Question

Webhook passing JSON as string

  • 22 November 2023
  • 8 replies
  • 287 views

SImply put, I am trying to generate proper JSON and pass to a webhook.

 

I have a Code by Zap block:
 

const imageUrls = inputData.imageUrls.split(','); // Splitting the URLs
const imagesArray = imageUrls.map(url => {
return { "url": url.trim() }; // Mapping each URL into an object
});

const outputData = {
"title": inputData.title,
"text": inputData.text,
"images": imagesArray
};

output = { "jsonContent": JSON.stringify(outputData) };

this is working fine, output is correct:

jsonContent
{"title":"Antibes","text":"On
...

 

i have a Webhook by Zap, All things correctly formatted & verified

 

In the Data section, one key is content, which is the output from the Code block above

{{_GEN_1700674589490__jsonContent}}

 

However when I look at the received data on the Webhook, it has escaped quotes:

{
"content": "{\"title\":\"Antibes\",\"text\":\"On
...

 

I have tried every combination I can think of to make this work, any help from this point would be lovely :)


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

8 replies

Userlevel 7
Badge +14

Hi @Augie 

Good question.

To help us have true context, post screenshots with how your Zap webhook step is configured.

ok thanks!

Userlevel 7
Badge +14

@Augie 

Try using this Zap action: Webhook - Custom Request

That will let you put the JSON in the Body Data.

 

still showing escape codes, am i doing this right?

 

 

here’s what was picked up on the server side:

 

i know i’m close…

 

here’s what was in the JSon content block:

 

last up - here’s the script that generats the json:

const imageUrls = inputData.imageUrls.split(','); // Splitting the URLs
const imagesArray = imageUrls.map(url => {
return { "url": url.trim() }; // Mapping each URL into an object
});

const outputData = {
"title": inputData.title,
"text": inputData.text,
"images": imagesArray
};

output = { "jsonContent": JSON.stringify(outputData) };

 

thanks!!

Userlevel 7
Badge +14

@Augie 

Looks like you are missing the opening and closing { }

 

thanks - i’m sorry, i don’t follow - where specifically am i missing them?

just for clarity, heres the current steps:
...
javascript:
 

 

method one - custom request:

 

this fails with a JSON error (so I know something’s wrong)

 

method 2: post webhook:

this fails server-side

 

 

so i know i’m… “close” :)

Userlevel 7
Badge +14

@Augie 

Can you post the API endpoint docs you are referencing to configure this Zap step?