Post request to the tickets endpoint is returning 403 error
I am developing a node.js application that when certain info is received it will open a ticket on behalf of the customer. When trying to do a POST request to create the ticket, I've made sure that my API key has the correct permissions. Can someone take a look at my code and let me know what I'm doing wrong?
const fetch = require("node-fetch");
const encodedData = Buffer.from(
`${process.env.ZDUser}/token:${process.env.ZD_TOKEN}`
).toString("base64");
async function createTicket(id, zdId, title, description) {
let zdUrl = process.env.ZD_URL + `/api/v2/tickets`;
let yumiUrl = `https://app.yumi.io/player/${id}`;
let body = {
ticket: {
requester_id: `${zdId}`,
comment: {
body: `${description}
Related video: ${yumiUrl}`,
},
priority: "normal",
subject: `${title}`,
},
};
let reqOption = {
method: "POST",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${encodedData}`,
},
};
try {
fetch(zdUrl, reqOption)
.then((resp) => {
return resp.json();
})
.then((json) => console.log(json));
} catch (err) {
`error occurred: ${err}`;
}
}
0
Please sign in to leave a comment.
Comments
0 comments