superoffice.webapi.tsclient v1.0.11
#Introduction: SuperOffice WebAPI TypeScript client
Axios based client for the SuperOffice WebAPI. Exposes the SuperOffice agents and data carrier objects as a TypeScript api.
The API is async / promise based, so that results must be await
ed or then
ed.
let contact: ContactEntity = { Name: "Bjørge AS", Department: "" };
let config: AxiosRequestConfig = { auth: { username: 'my username', password: 'my password' } };
let agent = new ContactAgent('https://crm.example.com/', config);
contact = await agent.SaveContactEntity(contact);
// or
agent.SaveContactEntity(contact).then(res:ContactEntity => {
// res.Name = "Bjørge AS"
// res.ContactId now set
return res.ContactId;
});
Agents and individual requests can be configured with language and culture settings:
let opts : WebApiOptions = {
baseUrl: 'https://crm.example.com/',
languageCode: 'sv',
cultureCode: 'en' };
let agent = new WebhookAgent(opts);
let newHook = await agent.CreateDefaultWebhook();
// all methods take an optional WebApiRequestOptions parameter to customize the request
let requestOptions : WebApiRequestOptions = {
languageCode: 'no',
cultureCode: 'no' };
let anotherHook = await agent.CreateDefaultWebhook(requestOptions);
The root WebApi
object allows you to configure the system globally, so you do not have to specify the base URL for every request.
let config : AxiosRequestConfig = { auth: { username: 'my name', password: 'my password' } };
WebApi.configure(host, config);
let agent = new WebhookAgent();
let response = await agent.CreateDefaultWebhook();
assert.equal(response.WebhookId, 0);
assert.equal(response.Name, null);
assert.equal(response.State, WebhookState.Active );
assert.equal(response.Type, "webhook" );
Installation
npm install SuperOffice.WebApi.TSClient --save
yarn add SuperOffice.WebApi.TSClient
Getting Started
Import the WebAPI module, and go from there
Javascript
var WebApi = require('superoffice.webapi.tsclient');
var api = new WebApi.AgentsApi('https://crm.example.com/');
api.authenticateWithPassword('foo', 'bar');
var agent = api.getContactAgent();
var contact = await agent.GetContact(123);
console.log(cont.Name);
// or
agent.GetContact(123).then(
cont => { console.log(cont.Name); }
);
TypeScript
import { AgentsApi } from 'superoffice.webapi.tsclient';
var api = new AgentsApi('https://crm.example.com/');
api.authenticateWithPassword('foo', 'bar');
var agent = api.getContactAgent();
var contact = await agent.GetContact(123);
console.log(cont.Name);
Build and Test
npm install
Installs dependencies. This installs the JEST testing framework and the TypeScript compiler.
npm run build
This compiles the typescript to Javascript files, and places them in the DIST folder
npm test
Runs the tests located in the __TESTS__
folder. The tests use Nock to mock the HTTP requests, so that the tests do not require a server to be running.
Contribute
This project does not take contributions - it is generated code.
We will take suggestions for changes to the generated code though.
License
Copyright (c) 2018, SuperOffice AS
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.