Skip to main content

openboxes@1.0.0

get(path, options)
post(path, body, options)
request(method, path, options)

Functions

get

get(path, options) ⇒ Operation

Make a GET request

ParamTypeDescription
pathstringPath to resource
optionsRequestOptionsOptional request options

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example: Get products

get("products", { query: { max: 10 }});

post

post(path, body, options) ⇒ Operation

Make a POST request

ParamTypeDescription
pathstringPath to resource
bodyobjectObject which will be attached to the POST body
optionsRequestOptionsOptional request options

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example

post("products", 
{
"id": "ff80818163e2de8d0163eba1b1e90002",
"productCode": null,
"name": "New product",
"category": {
"id": "ff80818163e2de8d0163eb93c5a00001",
"name": "New category"
},
"description": null,
"dateCreated": "2018-06-10T21:37:12Z",
"lastUpdated": "2018-06-10T21:37:12Z"
});

request

request(method, path, options) ⇒ Operation

Make a general HTTP request

ParamTypeDescription
methodstringHTTP method to use
pathstringPath to resource
optionsRequestOptionsOptional request options

This operation writes the following keys to state:

State KeyDescription
datathe parsed response body
responsethe response from the HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

Example: Update stock movement

request("POST", "/stockMovements/ff808181642fc9c101642fcccc420004", 
{
body: {
"name": "new stock movement",
"description": "new stock movement",
"origin.id": "1",
"destination.id": "2",
"requestedBy.id": "1",
"dateRequested": "06/23/2018"
}
});

Example: Update a product

request('POST', '/products/ff808181812576850182aee36930040b', { body: { name: 'Coffee', description: 'Arabica coffee from the highlands of Ethiopia' } });

Interfaces

HttpState

State object

Properties

NameDescription
datathe parsed response body
responsethe response from the HTTP server, including headers, statusCode, body, etc
referencesan array of all previous data objects used in the Job

RequestOptions

Options provided to the HTTP request

Properties

NameTypeDescription
bodyobject | stringbody data to append to the request. JSON will be converted to a string (but a content-type header will not be attached to the request).
errorsobjectMap of errorCodes -> error messages, ie, { 404: 'Resource not found;' }. Pass false to suppress errors for this code.
queryobjectAn object of query parameters to be encoded into the URL.
headersobjectAn object of headers to append to the request.