Constructing a JSON in workflow using workflow variables

Hello,
I am configuring a workflow and I need to send an HTTP request with a body in this workflow.
the first element of the body is a static string that I define, but the second element of the body is a list that is a variable we got from a previous workflow operation.
I have tried to create a body similar to the body created in this post Chained Workflows

{
"application":"ApplicationA",
"result":"{{$.hTTPRequest.body}}"
}

but the output I see is not really a json list and the data cannot be used as intened.

I have tried to remove the quotes form the variable but then the workflow just returns an error.
Is there a workaround for this?
Regards.

It needs to be something like this:

{
"application":"ApplicationA",
"result": [
{{$.request.Body}}

]
}

I have tried this but it did not work for me

Can you share the contents of $.hTTPRequest.body

The content of the $.hTTPRequest.body is too big to share here, but it is the result of a search query made to IDN that returns a list of account activity

What type of data do you get in the body? Array […] or Json {…}?

The data in the response body are in Array […] format

Try this :

{
"application":"ApplicationA",
"result": 
{{$.request.body}}


}
1 Like

I mentioned in my original post that I tried to have the body without the double quotes as you suggest but I still have an error.

the error is the following
Unable to parse input as JSON, please ensure it is syntactically correct. (type: Error Parsing Input, retryable: false): invalid character 'm' looking for beginning of value

Not sure if this will work. But try this one

{
"application":"ApplicationA",
"result":[{{$.hTTPRequest.body[*]}}]
}

Unfortunately this did not work.

I also tested

{
"application":"ApplicationA",
"result":{{$.hTTPRequest.body[*]}}
}

but without any success

i know is not necessary but can you use the step Define Variable and use the variable instead?

Hello Ivan,

Your suggestion did not work for me

1 Like

Apparently {{}} does not work as a placeholder for arrays in templating. (They can be used for single variables only) Using any variation of {{$.hTTPRequest.body}} inserts a text string that is in the format map[...] where ... is the actual content of the array. Also, every nested child array inside will also be prefixed with map. This is why you are getting the below error

I guess you will have to look for another approach.

PS: Please share your findings as this is a very interesting use case

2 Likes

Hello Nithesh,

Thank you for your answer. I was trying to look into an alternative by only sending the array in the body using the “choose variable” option and sending the information "application":"ApplicationA" in the request header as it is a static value that I define.

While I believe this can work easily in most cases it does not work for me as the receiving end on the HTTP request, is an external trigger of another workflow in IDN. And from what I tested I do not have a way of retrieving the headers from this trigger.

I am open for testing ideas and other methods of implementation if anyone can think of a possible solution.

A bad solution would be to create a new workflow with external trigger for each application but this is something we don’t want to do as we would be wasting our workflow limit in the environment

Regards,