โ10-12-2023 07:24 AM
Hi, I'm trying to send an HTTP request to an API endpoint using the Workato HTTP app "Send request via HTTP". The endpoint is expecting a field name of "First Name" (with a space) but it appears when creating the field name Workato does not allow spaces in the field names. I can only use snake case, such as "FirstName" or "First_Name". When the endpoint receives it in either format, I think it is interpreting it as "FirstName" or "First_Name" rather than the anticipated "First Name" and as a result does not accept the associated value as expected. And yes, the same thing happens with the Last Name. Other one-word field names are not having this issue.
Solved! Go to Solution.
โ10-12-2023 10:30 AM
If you're referring to the response schema, I can't find a way around this issue directly in the HTTP action. Usually, you can use a JSON sample to work around this blocker, but when using a JSON sample with "first name", Workato automatically changes it to "first_name".
However, there are a couple things that do work...
First, you can access the key directly with bracket notation. This is a little clunky, but it works.
This message imitates the API response:
And then you can access it like this:
Output:
Second, (definitely the better option) you can feed a sample JSON with spaces into the JSON parser, and it will parse it without issue.
It still replaces the spaces with underscores, but this action provides data pills that retain the expected value.
Output schema:
So if I do this:
I get this:
Hope this helps!
โ10-12-2023 10:30 AM
If you're referring to the response schema, I can't find a way around this issue directly in the HTTP action. Usually, you can use a JSON sample to work around this blocker, but when using a JSON sample with "first name", Workato automatically changes it to "first_name".
However, there are a couple things that do work...
First, you can access the key directly with bracket notation. This is a little clunky, but it works.
This message imitates the API response:
And then you can access it like this:
Output:
Second, (definitely the better option) you can feed a sample JSON with spaces into the JSON parser, and it will parse it without issue.
It still replaces the spaces with underscores, but this action provides data pills that retain the expected value.
Output schema:
So if I do this:
I get this:
Hope this helps!
โ10-13-2023 05:01 AM
Thank you gary1 and for the great documentation! I will try your "better option" and report back.
J
โ10-13-2023 02:02 PM
Gary1,
I wasn't able to get it to work but it's probably due to my lack of knowledge and understanding of what you are "saying". I tried the second option by first using the Parse JSON document action and then trying to use the result in a pill in the following HTTP post request schema but it still appeared in the receiving app as FirstName: Jay rather than First name: Jay. Am I way off course from what you were suggesting? Maybe you could dumb it down some more for me? Thank you J
โ10-13-2023 02:24 PM - edited โ10-13-2023 02:35 PM
It's a little confusing, but let's break it down. The core issue is the HTTP action won't parse the API response as-is, but the JSON Parser action will. This means you need to provide the JSON Parser with an example of the full response so it knows how to parse it, and in return it provides data pills to use in later recipe actions.
In both of our examples, we're only providing a snippet of the full response in the "sample document" field. Without seeing the actual full response from your HTTP action, I can't say exactly what you should put into the JSON Parser's "sample document" field, but what I recommend doing is copy/pasting the entire "body" JSON object from the HTTP action. (Sometimes this body is truncated which makes this trickier to do, but not impossible.)
Then, in the JSON Parser "document" input field, you should put the "body" data pill of the HTTP response.
Here's another example using the "Cat Facts" API (https://alexwohlbruck.github.io/cat-facts/docs/). For this example, let's pretend the API response is incompatible with the HTTP action, so we have to parse it in the JSON Parser.
HTTP action to call the API:
The HTTP action's output has a "body" value that is a "stringified" JSON:
Copy/paste that body into the "sample document" input field of the JSON parser. You can see that the JSON Parser is now providing all of data pills based on the provided sample:
Now, in the "document" field use the "body" data pill from the HTTP action. This is basically saying "I am providing you input data that is formatted exactly like the provided sample."
Finally, you can now use the output data pills from the JSON Parser (and they should have data):
... to get a result like this:
Good luck!