Last active
September 29, 2021 00:02
-
-
Save coetry/3d4df0776b858cec0a60818a4e61d8f2 to your computer and use it in GitHub Desktop.
Zendesk createTicket function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
▲ (trapbook) zd node index.js | |
creating ticket ... | |
{ | |
jsonString: '{"ticket":{"subject":"ZD API Test","comment":{"body":"This ticket was create by coetry via a node script and the ZD API. Please do not touch it or update its status. I will be interacting with it programmatically."}}}' | |
} | |
{ | |
error: 'ParameterMissing', | |
description: 'Parameter ticket is required' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function createTicket({ subject, body }) { | |
let jsonString = JSON.stringify({ | |
ticket: { | |
subject, | |
comment: { | |
body | |
} | |
} | |
}) | |
console.log({ jsonString }) | |
try { | |
let res = await fetch(`${BASE_URL}/tickets.json`, { | |
method: 'POST', | |
headers: { | |
Authorization: BASIC_AUTH_STRING, | |
'Content-Type': 'application/json', | |
Accept: 'application/json', | |
body: jsonString | |
} | |
}) | |
let json = await res.json() | |
return json | |
} catch (e) { | |
throw new Error(e.message) | |
} | |
} | |
console.log('creating ticket ...') | |
createTicket({ | |
subject: "ZD API Test", | |
body: "This ticket was create by coetry via a node script and the ZD API. Please do not touch it or update its status. I will be interacting with it programmatically." | |
}) | |
.then(console.log) | |
.catch(console.error) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello how are you? I don't know if you're still interested or if you've already fixed the error, but if you edit the fetch , removing the body you put inside the headers and putting it outside, like after the method, the ticket creation should work.