UNPKG

@androozka/zendesk-api-js

Version:

A JS library for interacting with the Zendesk API.

130 lines (108 loc) 3.27 kB
const validate = require('./validate'); module.exports = ({ instance, headers }) => { const url = `https://${instance}.zendesk.com`; return { list: (options = null) => { if (options) throw new Error('no options are allowed'); return { method: 'GET', url: `${url}/api/v2/user_fields.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/user_fields/${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/user_fields.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/user_fields/${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/user_fields/${id}.json`, headers }; }, reorder: (options = {}) => { const { error } = validate.reorder(options); if (error) throw new Error(error.details[0].message); const { data } = options; return { method: 'PUT', url: `${url}/api/v2/user_fields/reorder.json`, headers, data }; }, listOptions: (options = {}) => { const { error } = validate.listOptions(options); if (error) throw new Error(error.details[0].message); const { field_id } = options; return { method: 'GET', url: `${url}/api/v2/user_fields/${field_id}/options.json`, headers }; }, showOption: (options = {}) => { const { error } = validate.showOption(options); if (error) throw new Error(error.details[0].message); const { field_id, id } = options; return { method: 'GET', url: `${url}/api/v2/ticket_fields/${field_id}/options/${id}.json`, headers }; }, createOrUpdateOption: (options = {}) => { const { error } = validate.createOrUpdateOption(options); if (error) throw new Error(error.details[0].message); const { field_id, data } = options; return { method: 'POST', url: `${url}/api/v2/user_fields/${field_id}/options.json`, headers, data }; }, deleteOption: (options = {}) => { const { error } = validate.deleteOption(options); if (error) throw new Error(error.details[0].message); const { field_id, id } = options; return { method: 'DELETE', url: `${url}/api/v2/user_fields/${field_id}/options/${id}.json`, headers }; } }; };