403 error when creating request via API
Answered
Posted Jan 27, 2021
Hi,
I'm creating a custom form for our end-users within Zendesk itself. When I try to call the https://subdomain.zendesk.com/api/v2/requests API to create the request, it returns with a 403 error. I'm using an api token for auth. The API call works in postman and I was able to create a request but when I try to call it in my custom form in zendesk, it gives me a 403 error.
We are on Proffesional.
{
"error": {
"title": "Forbidden",
"message": "Invalid authenticity token"
}
}
Not sure what I'm doing wrong since the call works on postman.
var myHeaders = new Headers();
myHeaders.append("Authorization", "Basic btoa(email/token:API_TOKEN)");
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Cookie", "__cfduid=d3d63f8118c012940ee1e08701ec6140d1610414533; _zendesk_session=BAh7CEkiD3Nlc3Npb25faWQGOgZFVEkiJTBiMGNlNTVlOGVhNjQ4NTcyMDkxNGJjMzZjOWQxNTdhBjsAVEkiDGFjY291bnQGOwBGaQMvZ5JJIgpyb3V0ZQY7AEZpA7nELw%3D%3D--2608b56780c88cadb0776d6913aace910de8a12b; __cfruid=da3497d68006538ec0acea547c226758ea2a06fc-1611699971");
var raw = JSON.stringify({"request":{"subject":"TESTING API!","comment":{"body":"My printer is on fire!"}}});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://subdomain.zendesk.com/api/v2/requests", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
0
23
23 comments
Bonaliza Garcia
Hey,
So I did that. It matches what I used. email/token:api_token.
Are you using this code in Zendesk or an external app?
Is it possible that the authentication is somehow clashing with the current logged in user?
0
Bonaliza Garcia
I also tried your code but it gave me the same error.
0
Bonaliza Garcia
Thomas Verschoren
Yea it's giving me the correct value. I also tried encrypting the whole thing and just pasting it but it's still giving me the error message.
Could you think of anything else? I'm just lost since it's working on Postman
0
Sign in to leave a comment.