Public
Script
December 22, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import axios from "npm:axios";
export const refreshAccessToken = async (
clientId: string,
clientSecret: string,
refreshToken: string,
): Promise<string> => {
const responseDesk = await axios.post(
`https://accounts.zoho.com/oauth/v2/token`,
{}, // data is empty
{
params: {
client_id: clientId,
client_secret: clientSecret,
refresh_token: refreshToken,
grant_type: "refresh_token",
},
},
);
return responseDesk.data.access_token;
};
type Ticket = any;
export const notAssignedTickets = async (
accessToken: string,
orgId: string,
departmentId: string,
): Promise<{ data: Ticket[] }> => {
const responseDesk = await axios.get(
`https://desk.zoho.com/api/v1/tickets`,
{
params: {
limit: "100",
departmentIds: departmentId,
assignee: "Unassigned",
status: "${ONHOLD},${OPEN}",
},
headers: {
"Authorization": `Zoho-oauthtoken ${accessToken}`,
"orgId": orgId,
},
},
);
if (responseDesk.status === 422) {
// no data, return empty array
return {
data: [],
};
}
return responseDesk.data;
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
December 22, 2023