cancel
Showing results for 
Search instead for 
Did you mean: 

How to accommodate an HTTP request field name requiring a space

JayMappus
Deputy Chef III
Deputy Chef III

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. 

 
I tried to manually edit the schema but get the following error when I try:

"Oops! Something went wrong
Field name should start with a letter and should not contain spaces or any special characters except `_`
 
Any advice? Maybe I'm off on my analysis of the issue? Thank you for your time and expertise.
 
Settings:
The request content type = Multipart form, Response content type = Text, Encoding = UTF-8
1 ACCEPTED SOLUTION

gary1
Executive Chef II
Executive Chef II

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:

gary1_0-1697131247321.png

And then you can access it like this:

gary1_2-1697131331601.png

Output:

gary1_3-1697131349530.png

Second, (definitely the better option) you can feed a sample JSON with spaces into the JSON parser, and it will parse it without issue.

gary1_4-1697131536850.png

It still replaces the spaces with underscores, but this action provides data pills that retain the expected value.

Output schema:

gary1_5-1697131596541.png

So if I do this:

gary1_7-1697131706823.png

I get this:

gary1_8-1697131717862.png

 

Hope this helps!

View solution in original post

6 REPLIES 6

gary1
Executive Chef II
Executive Chef II

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:

gary1_0-1697131247321.png

And then you can access it like this:

gary1_2-1697131331601.png

Output:

gary1_3-1697131349530.png

Second, (definitely the better option) you can feed a sample JSON with spaces into the JSON parser, and it will parse it without issue.

gary1_4-1697131536850.png

It still replaces the spaces with underscores, but this action provides data pills that retain the expected value.

Output schema:

gary1_5-1697131596541.png

So if I do this:

gary1_7-1697131706823.png

I get this:

gary1_8-1697131717862.png

 

Hope this helps!

Thank you gary1 and for the great documentation! I will try your "better option" and report back.

J

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 JScreen Shot 2023-10-13 at 4.55.35 PM.pngScreen Shot 2023-10-13 at 4.57.13 PM.png

gary1
Executive Chef II
Executive Chef II

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:

gary1_0-1697231759531.png

The HTTP action's output has a "body" value that is a "stringified" JSON:

gary1_1-1697231826956.png

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:

gary1_2-1697231928259.png

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."

gary1_0-1697232940163.png

Finally, you can now use the output data pills from the JSON Parser (and they should have data):

gary1_3-1697232036227.png

... to get a result like this:

gary1_4-1697232060621.png

Good luck!