Recent searches
No recent searches
ZENDESK API Clients vs HTTP Requests/Responses
Posted Feb 01, 2022
I'm working on a new web application in Node JS that needs to access Zendesk to check if there are tickets created for a specific user/requester e-mail (not agent e-mail).
I came accross two scenarios where I could use to make this request. The first one is recommended by Zendesk, which is access Zendesk using one of two API Clients available for Node JS. They are node-zendesk by Farrin Reid and Zendesk NodeJS API written by Adam Gray. Check it out here
The problem is that I am getting the message "Couldn't authenticate you" from Zendesk when I do the fetch. Maybe someone already came accross this problem and could help me out clarifying where exactly is my mistake or what I'm missing in the code.
I would appreciate a light on that.
Here is my code:
async function getZendeskTickets(clientEmail) {
const zendeskAgent = 'agent@email.com'
const api_token = 'some token'
const query = `type:ticket requester:${clientEmail}`;
const url = `https://mydomain.zendesk.com/api/v2/search.json?query=${query}`
try {
const res = await fetch(url, {
method: 'GET',
mode: 'no-cors',
headers: {
'Content-Type': 'application/json',
Authorization: Buffer.from(`${zendeskAgent}/token:${api_token}`).toString('base64'),
}
})
let data = await res.json();
console.log('response', JSON.parse(JSON.stringify(data)))
} catch (error) {
console.log('zendesk response error', error)
}
return
}
0
2 comments
Deepesh Namdev
I am also getting the same Error: 401 Unauthorized, can anyone please help
0
Christopher Kennedy
Are you able to authenticate using the same credentials via cURL or a REST client? If so, can you double-check the username you're supplying to the Node JS API client you're using? Keep in mind that with API token authentication, the username is
{email_address}/token
. The client may or may not append/token
to the username before generating the request Authorization header depending on what details it expects to receive.0