openboxes@1.0.0
Functions
get
get(path, options) ⇒ Operation
Make a GET request
Param | Type | Description |
---|---|---|
path | string | Path to resource |
options | RequestOptions | Optional request options |
This operation writes the following keys to state:
State Key | Description |
---|---|
data | the parsed response body |
response | the response from the HTTP server, including headers, statusCode, body, etc |
references | an 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
Param | Type | Description |
---|---|---|
path | string | Path to resource |
body | object | Object which will be attached to the POST body |
options | RequestOptions | Optional request options |
This operation writes the following keys to state:
State Key | Description |
---|---|
data | the parsed response body |
response | the response from the HTTP server, including headers, statusCode, body, etc |
references | an 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
Param | Type | Description |
---|---|---|
method | string | HTTP method to use |
path | string | Path to resource |
options | RequestOptions | Optional request options |
This operation writes the following keys to state:
State Key | Description |
---|---|
data | the parsed response body |
response | the response from the HTTP server, including headers, statusCode, body, etc |
references | an 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
Name | Description |
---|---|
data | the parsed response body |
response | the response from the HTTP server, including headers, statusCode, body, etc |
references | an array of all previous data objects used in the Job |
RequestOptions
Options provided to the HTTP request
Properties
Name | Type | Description |
---|---|---|
body | object | string | body 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). |
errors | object | Map of errorCodes -> error messages, ie, { 404: 'Resource not found;' } . Pass false to suppress errors for this code. |
query | object | An object of query parameters to be encoded into the URL. |
headers | object | An object of headers to append to the request. |