I’m working on a Zapier integration that requires manual authentication with Zendesk. The platform only supports plain Node.js and the fetch method. I’ve checked Zendesk’s API docs, but they provide examples using curl commands. I’m not sure how to translate this into Zapier-compatible code.
Here’s a sample of what I’m trying to achieve:
async function authenticateZendesk() {
const email = '[email protected]';
const apiToken = 'abc123XYZ';
const subdomain = 'mycompany';
const response = await fetch(`https://${subdomain}.zendesk.com/api/v2/users.json`, {
headers: {
'Authorization': 'Basic ' + Buffer.from(`${email}/token:${apiToken}`).toString('base64')
}
});
if (response.ok) {
console.log('Authentication successful');
} else {
console.error('Authentication failed');
}
}
Can someone help me adapt this code for Zapier? I’m especially unsure about handling the Basic Auth header.
I’ve tackled Zendesk API integration with Zapier before, and it can be a bit tricky. One thing to keep in mind is that Zapier’s environment is more restricted than standard Node.js. Here’s what worked for me:
Instead of using fetch directly, I found it better to use Zapier’s built-in z.request() method. It handles a lot of the low-level stuff for you. Also, for the authentication header, the btoa() function is your friend for base64 encoding.
Here’s a snippet that might help:
const authTest = async (z, bundle) => {
const response = await z.request({
url: `https://${bundle.authData.subdomain}.zendesk.com/api/v2/users/me.json`,
method: 'GET',
headers: {
'Authorization': 'Basic ' + btoa(`${bundle.authData.email}/token:${bundle.authData.api_token}`)
}
});
if (response.status !== 200) {
throw new Error('Unable to authenticate with Zendesk');
}
return response.json;
};
This approach has been reliable for me. Remember to test thoroughly and handle rate limits appropriately. Good luck with your integration!
hey climbin lion, i’ve done smth similar b4. try using btoa() instead of Buffer.from() for base64 encoding. it’s supported in zapier. like this:
‘Authorization’: 'Basic ’ + btoa(${email}/token:${apiToken}
)
hope that helps! lmk if u need more info
I’ve implemented Zendesk authentication in Zapier before, and there are a few key points to consider. First, Zapier’s Node.js environment is more limited than a standard Node.js setup. As CreatingStone mentioned, using btoa()
for base64 encoding is a good approach. Additionally, you’ll want to use the fetch
polyfill provided by Zapier instead of the native fetch
.
Here’s a modified version of your code that should work in Zapier:
async function authenticateZendesk(z, bundle) {
const email = bundle.authData.email;
const apiToken = bundle.authData.api_token;
const subdomain = bundle.authData.subdomain;
const response = await z.request({
url: `https://${subdomain}.zendesk.com/api/v2/users.json`,
method: 'GET',
headers: {
'Authorization': 'Basic ' + btoa(`${email}/token:${apiToken}`)
}
});
if (response.status !== 200) {
throw new Error('Authentication failed');
}
return 'Authentication successful';
}
This approach uses Zapier’s z.request()
method and handles authentication errors properly.