Methods
This document details the methods of the JavaScript client library.
Initializing the client
Begin by initializing an instance of DeskproClient, from the @deskpro/deskpro-api-client-javascript package, with the URL to your Deskpro instance.
const DeskproClient = require('@deskpro/deskpro-api-client-javascript');
const client = new DeskproClient('http://deskpro.company.com');Axios is used to make HTTP requests. A default Axios client will be used by the library, but a custom instance may be provided.
const DeskproClient = require('@deskpro/deskpro-api-client-javascript');
const httpClient = axios.create({
timeout: 1000
});
const client = new DeskproClient('http://deskpro.company.com', httpClient);
// Or use the setter method.
// client.setHTTPClient(httpClient);Requests may be logged by passing a function as the third constructor argument.
const DeskproClient = require('@deskpro/deskpro-api-client-javascript');
const logger = console.log;
const client = new DeskproClient('http://deskpro.company.com', null, logger);
// Or use the setter method.
// client.setLogger(logger);Authenticating
Many API methods require authentication. Set the ID of the user to authenticate with and either the auth "key" or "token".
Get
Sends a GET request to the API.
DeskproClient::get(endpoint, params = {}) : Promise
Post
Sends a POST request to the API.
DeskproClient::post(endpoint, body = null, params = {}) : Promise
Put
Sends a PUT request to the API.
DeskproClient::put(endpoint, body = null, params = {}) : Promise
Delete
Sends a DELETE request to the API.
DeskproClient::del(endpoint, params = {}) : Promise
Batch
Sends a batch request to the API.
DeskproClient::batch(requests) : Promise
Request
Sends a request to the API.
DeskproClient::request(method, endpoint, body = null, params = {}, headers = {}) : Promise
Default Headers
Sets the headers sent with each request.
DeskproClient::setDefaultHeaders(defaultHeaders) : DeskproClient
Response
Each of the methods get, post, put, delete, batch, and request returns an object with the properties data, meta, and linked.
Browser Usage
The client library may be used in the browser as well as Node. The library may be installed using npm or embedded in a document using the unpkg.com CDN.
Last updated