You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library can also be used with Neto's OAuth program by providing the oauth_clientId and oauth_secret configuration options instead of key. Here is an example:
This library doesn't handle any authentication logic, it assumes that you already have obtained an API key or OAuth secret by some other means. More information on how to retrieve credentials can be found by visiting Neto's API documentation
Basic syntax
Once the library is initialised, you can use it like so:
mySite.type// See below for a list of supported types.method()// See below for a list of methods for each type (generally add, get or update).exec()// Returns a promise that resolves with the API response in JSON format.then(response)// Response object is returned via callback.catch(err);// Always handle your errors ;)
.add() and .update() methods can be chained together with themselves to improve readability - the request itself will only be sent when .exec() is called. Check it out below:
This allows you to some other cool stuff, such as building a bulk request to execute at some time in the future:
// Expose a copy of the request typevaraddItems=api.item;// Do some stuff...addItems=addItems.add({SKU: "smp_1"});// Do some other stuff...addItems=addItems.add({SKU: "smp_2"});// Keep building the request...addItems=addItems.add({SKU: "smp_3"});// Finally execute the request at a later timeaddItems.exec().then(response=>{console.log(response);}).catch(err=>console.log(err));
Chaining .get() methods will be supported soon, I promise.
async/await support
Because this library is built on promises, it supports the use of async and await operators. Here's an example:
asyncfunctionaddItem(){try{varresponse=mySite.item.add({SKU: "smp_1"}).exec();// Do some stuff...console.log(awaitresponse);}catch(err){console.log(err);}}addItem();