I'm trying to call a Zendesk webhook to create a ticket with Google Apps Script (evenetually using a Google form to trigger the webhook). Zendesk's Webhook page has a few different types of auth methods and I'm using basic auth. I can't figure out how to properly authenticate the webhook. I've tried several different variations on this code but keep getting "error":"Couldn't authenticate you" as a response.
In the Zendesk console, I have an active webhook with post set at the request method, JSON as the request format, basic auth set as the authentication method, and https://myDevelopmentDomain.zendesk.com/api/v2/tickets.json set as the endpoint URL.
What am I doing wrong here?
var ENDPOINT_URL = "https://myDevelopmentDomain.zendesk.com/api/v2/tickets.json"
function testhook() {
var options = {
'method': "post",
'contentType': "application/json",
'headers': {
"authentication":{
"type":"basic_auth",
"data":{
"username":"zendeskWebhookUsername",
"password":"zendeskWebhookPassword"
},
"add_position":"header"
}
},
'payload': JSON.stringify({
"ticket": {
"id": 35436,
"priority": "high",
"status": "open",
"subject": "Help, my printer is on fire!",
"description": "The fire is very colorful.",
"tags": [
"enterprise",
"other_tag"
]
}
}),
'muteHttpExceptions': false,
}
UrlFetchApp.fetch(ENDPOINT_URL, options);
}
When I saw the official document, it seems that the following value is used for creating a Webhook. Ref
I thought that this might be the reason for your current issue of
"error":"Couldn't authenticate you". From the URL and the value ofpayload, I guessed that in your current situation, you have already created your Webhook and you might want to request the Webhook using Google Apps Script.If my understanding is correct, how about the following modification?
Modified script:
Note:
Reference: