@taghub/api
v1.8.0
Published
This is a JavaScript module wrapping the [TagHub API](https://gitlab.taghub.net/documentation/devdocs/wikis/home).
Downloads
39
Maintainers
Keywords
Readme
TagHub API module
This is a JavaScript module wrapping the TagHub API.
It makes use of JavaScript modules and async/await and is designed to work both on the web and with NodeJS.
Requirements
Web: Tested with `create-react-app` (webpack).
NodeJS: 13.5+ and "type": "module" in package.json.
Install
npm install --save @taghub/api
Usage
import { login, getProjects } from '@taghub/api'
const credentials = await login('username', 'password')
const projects = await getProjects(credentials)
API
Common options
Most API calls take an options object as one of their parameters. Some of these options are common and are listed below.
param type descrption
--
init boolean If `true` the options will be stored in module state
consumerKey string Passed as the `TAGHUB_CONSUMER_KEY` header for API calls (required)
accessKey string Passed as the `TAGHUB_ACCESS_KEY` header for API calls (required)
endpoint string Used as base URL (optional) - overwrite any attempt at detecting the environemnt
.init(options)
Init will store options in the module state for future calls.
Useful so you only have to pass the consumerKey
once.
Example:
import { init } from '@taghub/api'
init({ consumerKey: '123' })
.login(username, password, options)
Logs the user into TagHub. Returns an object with an accessKey
parameter that can be used for access to other APIs.
Passing init: true
in options will also store accessKey
in module state.
Example:
import { login } from '@taghub/api'
await login('username', 'password', { consumerKey: '123', init: true })
.loginSSO(username, ssoKey, updateUserOptions, options)
Logs the user into TagHub from a SSO key which is linked to a Company.
Returns an object with an accessKey
parameter that can be used for access to other APIs.
Passing init: true
in options will also store accessKey
in module state.
updateUserOptions
contains options to update the user:
param type descrption
createIfNotExists
: boolean
If true
it will create a user if it does not exist.
firstName
: string
It will update the user's first name on every login.
lastName
: string
It will update the user's last name on every login.
roles
: array
It will update the project-role relationship on every login. Of shape: [{ project, role }]
.
Example:
import { login } from '@taghub/api'
await loginSSO('username', 'ssoKey', {}, { consumerKey: '123', init: true })
Updating user properties:
await loginSSO('username', 'ssoKey', {
createIfNotExists: true,
firstName: 'Bob',
lastName: 'Sponge',
roles: [
{ project: 'Norway', role: 'Spectator' },
{ project: 'USA', role: 'Administrator' }
]
}, { consumerKey: '123', init: true })
.getProjects(options)
Get a list of the projects the current user has access to.
Example:
import { login, getProjects } from '@taghub/api'
await login('username', 'password', { consumerKey: '123', init: true })
const projects = await getProjects()
.getItems(project_uuid, options)
Get a list of items for the passed project.
Options:
param type descrption
--
query object Object containing query params to pass to items call (optional)
Example:
import { login, getItems } from '@taghub/api'
await login('username', 'password', { consumerKey: '123', init: true })
const items = await getItems('project_uuid')
const equipment = await getItems('project_uuid', { query: { filter9: 1 }})
.getItem(project_uuid, epcString, options)
Get an item of a project.
Example:
import { login, getItem } from '@taghub/api'
await login('username', 'password', { consumerKey: '123', init: true })
const item = await getItem('project_uuid', 'epcString')
.getEvents(project_uuid, epcString, serviceId, options)
Get a list of events of a Service or all Services if serviceId
is not passed.
Options:
param type descrption
--
query object Object containing query params to pass to items call (optional)
query.startFrom number Index from where to start fetching events (latest events come first).
query.maxHits number Max number of events to fetch
Example:
import { login, getEvents } from '@taghub/api'
await login('username', 'password', { consumerKey: '123', init: true })
const items = await getEvents('project_uuid', 'epcString', 'serviceId')
const equipment = await getEvents('project_uuid', 'epcString', 'serviceId', { query: { startFrom: 0, maxHits: 5 }})
.getProjectMeta(project_uuid, options)
Get the metadata of a project. Information about enabled services etc.
Example:
import { login, getProjectMeta } from '@taghub/api'
await login('username', 'password', { consumerKey: '123', init: true })
const meta = await getProjectMeta('project_uuid')
.getProfiles(project_uuid, options)
Get a list of profiles of a project.
Options:
param type descrption
--
query object Object containing query params to pass to items call (optional)
Example:
import { login, getProfiles } from '@taghub/api'
await login('username', 'password', { consumerKey: '123', init: true })
const items = await getProfiles('project_uuid')
.getItemTypes(project_uuid, options)
Get a list of item types related to a project.
Example:
import { getItemTypes } from '@taghub/api'
const items = await getItemTypes('project_uuid')
enjoy.