Help

JSON rest API script

Topic Labels: Automations
2387 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Andrea
5 - Automation Enthusiast
5 - Automation Enthusiast

I need a make an json request with my script,
i think the error is body: JSON.stringify because the JSON and other data is working in another script.

let response = await fetch(‘https://api.service.com/fb/sending/sendContent’, {
method: ‘POST’,
body: JSON.stringify(’
{
“subscriber_id”: 3039330322761660,
“data”: {

“version”: “v2”,
“content”: {
“messages”: [
{
“type”: “cards”,
“elements”: [
{
“title”: “Card title”,
“subtitle”: “card text”,
“image_url”: “”,
“action_url”: “https://google.com
}
],
“image_aspect_ratio”: “horizontal”
}
]
}

},
“otn_topic_name”: “Driver”
}

'),
headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer 1170be67ba0d10ac2158fb435fcd6d778'
},

});
console.log(await response.json());

3 Replies 3

I think the issue is passing the JSON object quoted.

i tried but report: There was an unexpected error while executing your script.

Andrea
5 - Automation Enthusiast
5 - Automation Enthusiast

i found the problem, had Input variables set but not used in script. Is a stupid error but i’m new here. Thank you Bill