@hartmannindustries/trackvia-sdk
v1.2.1
Published
A Typescript SDK for Trackvia
Downloads
2
Readme
TrackVia SDK
SDK for working with data from TrackVia
Getting Started
Installation
npm install @hartmannindustries/trackvia-sdk --save
or
yarn add @hartmannindustries/trackvia-sdk
Initialization
- Login to your Trackvia account and navigate to My Account -> API Access.
- Copy down the API key and generate a new Auth token for your user.
- Create a new object called
config
to pass to the TrackViaSDK constructor
import { TrackViaSDK } from '@hartmannindustries/trackvia-sdk';
// create configuration object
const config = {
apiKey: 'your api key',
authToken: 'your auth token',
host: '' // optional - if TrackVia provides you with a
// different url than https://go.trackvia.com, you can specify it here,
// otherwise don't specify a host
};
// initialize constructor
const sdk = new TrackViaSDK(config);
API methods
- Get all users in your TrackVia account,
paging
optional
/**
* @param - {object} - paging? - { start: number, max: number }
* @returns - {array} - users
** /
const users = await sdk.getUsers({ start: 0, max: 2 });
- Add new user
/**
* @param {object} - user - { email, firstName, lastName, timeZone? }
* @return {array} - new user
** /
const user = {
email: '[email protected]',
firstName: 'First Name',
lastName: 'Last Name',
timeZone: 'timezone'
};
const createUser = await sdk.addUser(user);
- Get all apps in your account
const apps = await sdk.getApps();
- Get app by name
/**
* @param {string} - name - app name
* @return {array} - app
** /
const app = await sdk.getAppByName('Project Tracking');
- Get all views
const views = await sdk.getViews();
- Get View
/**
* @param {number} - viewId
* @param {object} - Paging { start: Number, max: Number }
* @param {string} - q - query string
* @return {object} - view
** /
const view = sdk.getView(3, { start: 0, max: 5 }, q: 'query')
- Get view by name
/**
* @param {string} - name - view name
* @return {array} - view
** /
const view = await sdk.getViewByName('All Tasks');
- Get Record
/**
* @param {number} - viewId
* @param {number} - recordId
* @return {array} - view
** /
const record = await sdk.getRecord(3, 6);
- Add Record
/**
* @param {number} - viewId
* @param {object} - new record
** /
const record = await sdk.addRecord(3, {
name: 'Name',
address: 'Address'
});
- Update Record
/**
* @param {number} - viewId
* @param {number} - recordId
* @param {object} - record
** /
const record = await sdk.addRecord(3, 6, {
name: 'Name',
address: 'Address Updated'
});
- Delete all records in view
/**
* @param {number} - viewId
** /
const deleteRecords = await sdk.deleteAllRecordsInView(3);
- Delete a record in view
/**
* @description Delete a record in view
* @param {number} - viewId
* @param {number} - recordId
** /
const deleteRecord = await sdk.deleteRecord(3, 9);
- Get File
/**
* @description Get a file
* @param {number} - viewId
* @param {number} - recordId
* @param {string} - fieldName
* @param {object?} - { width?, maxDimension? }
**/
const getFile = await sdk.getFile(3, 6, 'Image', { width: 200, maxDimension: 200 });
- Attach File
/**
* @description Attach a file
* @param {number} - viewId
* @param {number} - recordId
* @param {string} - fieldName
* @param {string} - filePath
**/
const attachFile = await sdk.attachFile(3, 6, 'Image', 'path/to/image/file.jpg');
- Delete File
/**
* @description Delete a file
* @param {number} - viewId
* @param {number} - recordId
* @param {string} - fieldName
**/
const deleteFile = await sdk.deleteFile(3, 6, 'Image');