Skip to main content

I’ve been working with an that will POST data to a File Maker Pro endpoint when a new Cognito form is submitted. I’ve got pretty much everything working but from what I can tell the JSON being sent to the endpoint is not getting stringified correctly. I have 4 steps in the flow, 1. When Cognito form is submitted, 2. Send a POST request to get an bearer token for authentication, 3. Take the data from the Cognito for and stringify it using a Java script, 4. Send a post to the File Maker Endpoint for submission to the database to create a new entry. 

The file maker pro server is a third party and its very strict on what needs to be sent to them. Data field must look like this…
 

{"fieldData":
{
"Payload":"{\"id_RepresentationType\":\"2\",\"injured\":{\"email\":\"Testemail\",\"firstName\":\"TestFirstName\",\"lastName\":\"TestLastName\",\"homePhone\":\"123-456-7890\"}}"
},
"script":"LeadIntakeV2.1"
}

The java code to stringify looks like this…

 

// Extracting data from the inputData object

var id_RepresentationType = inputData.id_RepresentationType;

var id_source = inputData.id_source;

var firstName = inputData.firstName;

var lastName = inputData.lastName;

var homePhone = inputData.homePhone;

var mobilePhone = inputData.mobilePhone;

var workPhone = inputData.workPhone;

 

// Creating an injured object with the extracted data

var injured = {

  firstName: firstName,

  lastName: lastName,

  homePhone: homePhone,

  mobilePhone: mobilePhone,

  workPhone: workPhone,

};

 

// Creating a payload object with the extracted data and the injured object

var payload = {

  id_RepresentationType: id_RepresentationType,

  id_source: id_source,

  injured: injured,

};

 

// Converting the payload object to a JSON string

var payloadString = JSON.stringify(payload);

 

// Creating an output object with a fieldData property that contains the payload

var output = { payloadString };

The output looks like this…

 

 

However when I send this to the server I get an error code indicating to me that the data has not been properly stringified. Is there a way to ensure the data being posted will be stringified when its sent or does Zapier obfuscate that from the view of the Zapier user? Below is the error returned…

 

 

Please let me know if anyone has encountered anything like this? I’m wondering if Zapier might not be the best solution for this but I feel like I’m extremely close to figuring this out and hoping someone here has ran into this.

Hi @720SS,

I think you might find using quik.run in Zapier a breeze for the task you're working on. It's a neat tool that lets you test your code snippets with various scenarios, making life easier.

Below is a quick example of how you can pass data to a snippet and get the desired output. If you're interested, I can share the snippet which I made for your specific use-case, so you can plug it right into your Zap.

 

Just shoot me an email at nparashar150@gmail.com or naman@quik.run̉ for the snippet link, will be more than happy to resolve your issue. Cheers!

 

Below is response returned by QuikRun after running your code.  

 


I was able to figure this out and get it working by using a formatter zap to add in the \” as needed through the stringified JSON.