I am using zafClient to perform requests as per this article: https://developer.zendesk.com/apps/docs/core-api/client_api#client.requestoptions
So far I am successful with GET requests and can fetch the information needed. Example:
zafClient.request({
url: '/api/v2/macros.json',
httpCompleteResponse: true,
}).then(response => {
console.log(response.responseJSON);
}, error => {
console.log(error.responseText)
})
but, when I perform POST operation, I am getting nasty error that I cannot fight. here is post:
zafClient.request({
url: '/api/v2/macros.json',
method: 'POST',
data: {
"macro": {
'title': "Created Macro with API test",
'actions': [{ "field": "subject", "value": "Change subjectline with API" }]
}
}
}).then(res => console.log(res), error => console.log(error.responseText))
And here is the error.responseTest
{
"error": {
"title": "Invalid attribute",
"message": "You passed an invalid value for the actions attribute. Invalid parameter: actions must be an array from api/v2/rules/macros/create"
}
}
Am I missing something in the post operation? if I log just the object "macro" I can see that attribute "actions" is an array, so the object "macro" is an exact object that I am fetching from API
Any ideas would be welcome as to what am I doing wrong.
Now I know that I was supposed to JSON.Stringify passing data:)
zafClient.request({
url: '/api/v2/macros.json',
httpCompleteResponse: true,
contentType: 'application/json',
method: 'POST',
data: JSON.stringify({
macro: {
title: "Created Macro with API test",
actions: [{ "field": "subject", "value": "Change subjectline with API" }]
}
})
}).then(res => console.log(res), error => console.log(error.responseText))
First experience with HTTP requests
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.