@androozka/zendesk-api-js
Version:
A JS library for interacting with the Zendesk API.
80 lines (66 loc) • 1.91 kB
JavaScript
const validate = require('./validate');
module.exports = ({ instance, headers }) => {
const url = `https://${instance}.zendesk.com`;
return {
list: (options = {}) => {
const { error } = validate.list(options);
if (error) throw new Error(error.details[0].message);
const { user_id } = options;
return {
method: 'GET',
url: `${url}/api/v2${user_id ? `/users/${user_id}` : ''}/groups.json`,
headers
};
},
show_assignable: (options = null) => {
if (options) throw new Error('no options are allowed');
return {
method: 'GET',
url: `${url}/api/v2/groups/assignable.json`,
headers
};
},
show: (options = {}) => {
const { error } = validate.show(options);
if (error) throw new Error(error.details[0].message);
const { id } = options;
return {
method: 'GET',
url: `${url}/api/v2/groups/${id}.json`,
headers
};
},
create: (options = {}) => {
const { error } = validate.create(options);
if (error) throw new Error(error.details[0].message);
const { data } = options;
return {
method: 'POST',
url: `${url}/api/v2/groups.json`,
headers,
data
};
},
update: (options = {}) => {
const { error } = validate.update(options);
if (error) throw new Error(error.details[0].message);
const { id, data } = options;
return {
method: 'PUT',
url: `${url}/api/v2/groups/${id}.json`,
headers,
data
};
},
delete: (options = {}) => {
const { error } = validate.delete(options);
if (error) throw new Error(error.details[0].message);
const { id } = options;
return {
method: 'DELETE',
url: `${url}/api/v2/groups/${id}.json`,
headers
};
}
};
};