0

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.

2
  • Please show hardcoded and not hardcoded version Commented Oct 17, 2022 at 17:59
  • I added the hardcoded value to the end. Commented Oct 17, 2022 at 18:38

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

18 Comments

No, I have the semicolon in my code. I just wrote that as an example.
place a larger scope of the code to get better help.
Just added pictures at the top of the question to better explain
I see you doing a console log just before the return of your JSONString. what does that console log give you? Also is there a reason you are doing all the concats instead of just loading the values?
Thank you so much. I used JSON.parse(JSONString) to do it but you were spot on. If you make a reply saying that I'll mark that as the answer. Seriously thanks that was so frustrating.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.