Recent searches
No recent searches
Making POST API requests from a Zendesk app
Posted Sep 27, 2024
Hi,
I'm sending a POST request in Node.js using client.request
as shown below:
However, the response status alternates between 406 if i use .json at the end and 200 if i dont use.json, but the data isn't being inserted. It works fine when using Postman.
client.request({
url: `api/v2/users/${user.id}/identities`,
type: "POST",
contentType: 'application/json',
data: JSON.stringify(data)
});
0
1
1 comment
Mohamed Katib
Hi,
I was having similar issues and realised that the the issue was with the JSON.stringify of the data when including as part of the request. Therefore I did this, as an example,
payload = JSON.stringify({
{
"ticket": {
"custom_fields": [
{"id": [your_Field_Id], "value": "yourValue"}
]
}
}
});
let endPoint = `yourEndPoint`
let settings = {
url: '/api/v2/' + endPoint,
type: “POST”,
cors: false,
dataType: 'json',
data: payload
};
client.request(settings)
Others may have an explanation, but this works for me.
Hopefully this helps
0