Node library for performing REST API calls to Salesforce Marketing Cloud (formerly ExactTarget).
npm install fuel-restFuel REST Client (for Node.js)  
=============
This repo used to be located at https://github.com/exacttarget/Fuel-Node-REST
This library allows users access to the Salesforce Marketing Cloud REST API at a low level.
npm install fuel-rest --save
yarn add fuel-rest
`
Initialization
new FuelRest(options) - Initialization
* options.auth
* Required: yes
* Type: Object or [FuelAuth Instance][1]
* properties need to match [FuelAuth][1]
* options.origin or options.restEndpoint
* Required: no
* Type: String
* Default: https://www.exacttargetapis.com
* options.headers
* Required: no
* Type: Object
* set headers that apply to all REST requests (not auth requests)
* options.globalReqOptions
* Required: no
* Type: Object
* set configuration options that apply to all requests (auth + REST)
API
* apiRequest(options, callback)
* options - [see request modules options][3]
* options.auth - will be passed into [getAccessToken][4] inside Fuel Auth
* options.uri - can either be a full url or a path that is appended to options.origin used at initialization ([url.resolve][2])
* options.retry - boolean value representing whether or not to retry request (and request new token) on 401 invalid token response. default: false
* callback - executed after task is completed.
* if no callback is passed, you'll need to use the promise interface
* get | post | put | patch | delete(options, callback)
* options - see apiRequest options
* options.retry - see above for description. default: true
* callback - see apiRequest options
* Request method will be overwritten by these methods. It will be set to same value as the name of the method used
Setting up the client
`js
const FuelRest = require('fuel-rest');
const options = {
auth: {
// options you want passed when Fuel Auth is initialized
clientId: 'clientId',
clientSecret: 'clientSecret'
},
origin: 'https://alternate.rest.endpoint.com' // default --> https://www.exacttargetapis.com
};
const RestClient = new FuelRest(options);
`
Examples
`js
const options = {
uri: '/platform/v1/endpoints',
headers: {}
// other request options
};
// CANNOT USE BOTH CALLBACKS AND PROMISES TOGETHER
RestClient.get(options, (err, response) => {
if (err) {
// error here
console.log(err);
}
// will be delivered with 200, 400, 401, 500, etc status codes
// response.body === payload from response
// response.res === full response from request client
console.log(response);
});
// or with promises
RestClient.get(options)
.then(response => {
// will be delivered with 200, 400, 401, 500, etc status codes
// response.body === payload from response
// response.res === full response from request client
console.log(response);
})
.catch(err => console.log(err));
``