Token Authentication not working on Appscript



Posted Jun 18, 2024

I'm currently working on a project that integrates Google Apps Script with the Zendesk Request API. Currently, I can create tickets from Apps Script using the Request API. Initially, I implemented an authentication token process, but a few days ago, I started receiving spam. Upon checking the documentation, I discovered that the API endpoint is open, meaning the authentication process wasn't being utilized, and tickets were being created without authentication.

When I enabled the "Require authentication for request and uploads APIs" option in the Admin center, the endpoint returned the following error:

API Response: {"error":"Couldn't authenticate you"}

Could anyone pinpoint where the error might be in the authentication process?

Here's the script I'm using:


function createZendeskRequest(

 name, email, topic, region, subregion, cc, subject, description, zendesk_email, zendesk_token,zendesk_api) {

 

// Zendesk API endpoint for creating requests

 var zendeskApiUrl = zendesk_api;

 

 // Zendesk email and API token

 var zendeskEmail = zendesk_email;

 var zendeskToken = zendesk_token;

 

 // Combine email and token and Base-64 encode

 var combinedCredentials = zendeskEmail + ":" + zendeskToken;

 var authorizationHeader = "Basic " + Utilities.base64Encode(combinedCredentials);

 

 // Request data

 var requestData = {

   "request": {

     "subject": subject,

     "comment": { "body": description,

     "priority": "normal",

     "custom_fields": [

       { "id": xxxxx, "value": topic },

       { "id": xxxxx, "value": region },

       { "id": xxxxx, "value": subregion },

       { "id": xxxxx, "value": cc }

 

     ],

     "requester": {

       "name": name,

       "email": email

     }

   }

 };

 

 // Options for the API request

 var options = {

   "method": "post",

   "headers": {

     "Authorization": authorizationHeader,

     "Content-Type": "application/json",

   },

   "payload": JSON.stringify(requestData),

   "muteHttpExceptions": true,

 };

 

 // Make the API request

 var response = UrlFetchApp.fetch(zendeskApiUrl, options);

 

Thanks in advance

 


0

4

4 comments

Sign in to leave a comment.

Didn't find what you're looking for?

New post