type Zendesk = {
username: string;
password: string;
subdomain: string;
};
/**
* Search Organizations by External ID
* If you set the `external_id` value of an organization to associate it to an external record, you can use the external id to search for the organization.
#### Allowed For:
* Admins
* Agents assigned to a custom role with permissions to add or modify organizations (Enterprise only)
See [Creating custom agent roles](https://support.zendesk.com/hc/en-us/articles/203662026#topic_cxn_hig_bd) in the Support Help Center.
*/
export async function main(auth: Zendesk, external_id: string | undefined) {
const url = new URL(
`https://${auth.subdomain}.zendesk.com/api/v2/organizations/search`
);
for (const [k, v] of [["external_id", external_id]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 377 days ago
type Zendesk = {
username: string;
password: string;
subdomain: string;
};
/**
* Search Organizations by External ID
* If you set the `external_id` value of an organization to associate it to an external record, you can use the external id to search for the organization.
#### Allowed For:
* Admins
* Agents assigned to a custom role with permissions to add or modify organizations (Enterprise only)
See [Creating custom agent roles](https://support.zendesk.com/hc/en-us/articles/203662026#topic_cxn_hig_bd) in the Support Help Center.
*/
export async function main(auth: Zendesk, external_id: string | undefined) {
const url = new URL(
`https://${auth.subdomain}.zendesk.com/api/v2/organizations/search`
);
for (const [k, v] of [["external_id", external_id]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 923 days ago