Home > Enterprise >  Variable in JSON API POST Request is not working
Variable in JSON API POST Request is not working

Time:10-18

The first image is the transformer I am building in Retool, all this is doing is building my JSON string for the API call

This image is where I am inputting the value of the JSON string into the API POST call. As you can see, the value of the transformer is the same as what I hardcode

I am making an API to Carbone (PDF generator site) to generate a PDF based on JSON data that I provide. This is all being done through Retool which uses JavaScript and is an app building application.

I have a JSON string saved as a variable:

jsonString = '{
"products": [{"name": "Fred"},
  {"name": "Abby"},
  {"name": "Jason"},
  {"name": "Josh"}]
              }'

This is a string variable.

When I hardcode this into the API call data parameter, the PDF returns just fine. However, when I input this variable into the call, the PDF does not generate at all.

Am I missing something? I have already tried deleting the first and last character of the string in case for some reason quotes were being added to the variable but it did not fix anything.

{
"products": [{"name": "Fred"},
  {"name": "Abby"},
  {"name": "Jason"},
  {"name": "Josh"}]
              }

^ This is the hardcoded value I can enter in the data parameter for the API call and it works.

CodePudding user response:

Make sure to JSON.stringify( jsonSting ) before or when loading the call. This is only if your json is returned as an object and not a string.

Carbone requires the data to be passed in as an object or array. The following should fix the issue.

If needing to send in an object and you have a string use JSON.parse( jsonString ) to make string and object before or when loading the call.

  • Related