Skip to content

Instantly share code, notes, and snippets.

@coetry
Last active September 29, 2021 00:02
Show Gist options
  • Save coetry/3d4df0776b858cec0a60818a4e61d8f2 to your computer and use it in GitHub Desktop.
Save coetry/3d4df0776b858cec0a60818a4e61d8f2 to your computer and use it in GitHub Desktop.
Zendesk createTicket function
▲ (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'
}
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)
@coetry
Copy link
Author

coetry commented Nov 17, 2019

The error that I'm getting says that I'm missing the ticket parameter, but if you look at the code above in zd.js, you can see that the first key in the object that I'm sending to the api endpoint is ticket. I can't seem to figure out what's wrong based on the documentation regarding the tickets endpoint

@RobertoAlve
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment