sbtech-api-sdk
v1.0.1
Published
JavaScript SDK for SBTech API
Downloads
2
Readme
SBTech TypeScript / JavaScript SDK
Make API calls to SBTech API with our easy-to-use SDK.
Installation
To use as module in a Node.js / TypeScript project
We always recommend you bundle your dependencies with your application. You can do this using such tools as Webpack, Browserify and etc.
- Install it using npm:
npm install --save sbtech-api-sdk
- Require/import it into the project:
import { SBTechAPI } from 'sbtech-api-sdk'
var SBTechAPI = require('sbtech-api-sdk').SBTechAPI;
To self host for use in the browser
- Copy index.js file from dist folder of the repo ApiSDK.
- Include it in the browser:
<script type="text/javascript" src="index.js"></script>
- Use the global object
SBTechLib.SBTechAPI
:
console.log(SBTechLib.SBTechAPI);
Usage
- Create global object
SBTech
with propertyCurrentConfiguration
to setup configuration.
var SBTech = {
CurrentConfiguration : {
loginApiRootUrl: 'http://ngapi.sbtech.com/login/api',
captchaApiRootUrl: 'http://ngapi.sbtech.com/captcha/api'
}
};
- Initialize the SBTech API using your JWT token which contains
SessionId
andSiteId
in payload.
var sbtechAPI = new SBTechAPI(token);
- Call one of the API methods
sbtechAPI.LoginAPI.signin({name: 'example_name', password: 'example_password'})
.then(function(response){
console.log(response);
})
.catch(function(error){
console.log(error);
});
API
Overview
Each API call returns a promise. Any response with a status of < 200 or >= 300 will reject the promise. All the rest statuses is considered a success and will resolve the promise.
Error object of rejected promise contains:
{Number} statusCode
: HTTP status code{String} message
: Error message{Object} errorObject
: Error object with detailed information
Methods
Login
SignIn
LoginAPI.signin(request: AuthenticationRequest):Promise<AuthenticationResponse>;
SignIn by token
LoginAPI.signInByToken(request: AuthenticationByTokenRequest):Promise<AuthenticationResponse>;
SignOut
LoginAPI.signout():Promise<AuthenticationResponse>;
Captcha
Get captcha image - returns image in base64
CaptchaAPI.getCaptchaImage():Promise<CaptchaResponse>;