@builton/node-sdk
Version:
Builton Node SDK.
109 lines (75 loc) • 3.17 kB
Markdown
[](https://david-dm.org/BuiltonDev/node-sdk)
[](https://github.com/BuiltonDev/node-sdk/releases)
[](LICENSE.md)
# Builton SDK
[Builton](https://www.builton.dev) offers a platform as a service that digitizes core business functions and optimizes resource allocation with baked-in machine learning capabilities. This SDK gives you a machine-to-machine access to our platform's building blocks and will help you implement its API in a Javascript environment. Get instant access to modules like Payments, Messaging Tools, User Management, Webhooks, Resource Allocation and more.
If you are looking for a client SDK, take a look at our [Javascript SDK](https://github.com/BuiltonDev/javascript-sdk)

## Requirement
- A Builton API Key
- A Builton Service Account Key
## Install
From [npm](https://npmjs.org)
```sh
npm install @builton/node-sdk
```
## Getting started
`new Builton({ apiKey, bearerToken })`
Initialises a new instance of `Builton` configured with your application `apiKey` and a `bearerToken`.
The `bearerToken` is the service account key.
- **apiKey {String}**: Your attributed Builton API Key.
- **bearerToken {String}**: Your service account key.
### Example: Fetching and updating orders
Using a callback:
```js
builton.orders.get({ size: 5 }, function(err, page) {
const firstOrder = page.current[0];
firstOrder.update({ delivery_status: 'DONE' });
});
```
Using promises:
```js
builton.orders.get({ size: 5 }).then((page) => {
const firstOrder = page.current[0];
firstOrder.update({ delivery_status: 'DONE' });
});
```
Using async/await:
```js
// This needs to be within in an `async` function
const page = await builton.orders.get({ size: 5 });
const firstOrder = page.current[0];
firstOrder.update({ delivery_status: 'DONE' });
```
### Example: Updating a product method by id
```js
builton.products.update(':productId:', {
name: 'New name'
});
```
### Example: Using the `set` methods:
The `set` method allows you to create an object without fetching it from the api. I can be useful when working with stored data for example.
```js
const product = builton.products.set(':productId:');
product.update({
name: 'New name'
});
```
With multiple payment methods:
```js
const paymentMethods = builton.paymentMethods.set([':paymentMethodId1:', ':paymentMethodId2:']);
paymentMethods[0].update({
token: ':StripeTokenId:'
});
```
With full props:
```js
const paymentMethod = builton.paymentMethods.set({<paymentMethodJsonObject>});
paymentMethod.update({
token: ':StripeTokenId:'
});
```
## Issue Reporting
If you have found a bug or if you have a feature request, please report them to this repository's issues section.
## License
This project is licensed under the MIT license. See the [LICENSE](LICENSE.md) file for more info.