UNPKG

@androozka/zendesk-api-js

Version:

A JS library for interacting with the Zendesk API.

81 lines (67 loc) 1.95 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/organization_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/organization_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/organization_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/organization_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/organization_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/organization_fields/reorder.json`, headers, data }; } }; };