Skip to content

Instantly share code, notes, and snippets.

@bafonins
Created August 30, 2019 10:09
Show Gist options
  • Select an option

  • Save bafonins/7a2e99acb5f2fa05ea014f9727393405 to your computer and use it in GitHub Desktop.

Select an option

Save bafonins/7a2e99acb5f2fa05ea014f9727393405 to your computer and use it in GitHub Desktop.
const assert = require('assert')
const TTN = require('ttn-lw').default
const is = process.env.TTN_LW_IDENTITY_SERVER_ADDRESS
const token = process.env.access_token
const ttnClient = new TTN(token, {
stackConfig: { is: `${is}/api/v3` },
connectionType: 'http',
proxy: false,
})
;(async function() {
try {
const adminId = 'admin'
const organizationId1 = 'org-1'
const organizationName1 = 'org-1-name'
const organizationId2 = 'org-2'
const organizationName2 = 'org-2-name'
await ttnClient.api.OrganizationRegistry.Create(
{ routeParams: { 'collaborator.user_ids.user_id': adminId } },
{
organization: {
ids: {
organization_id: organizationId1,
},
name: organizationName1,
},
},
)
console.log(`created organization:${organizationId1}`)
await ttnClient.api.OrganizationRegistry.Create(
{ routeParams: { 'collaborator.user_ids.user_id': adminId } },
{
organization: {
ids: {
organization_id: organizationId2,
},
name: organizationName2,
},
},
)
console.log(`created organization:${organizationId2}`)
const { organizations, totalCount } = await ttnClient.Organizations.getAll(
{
page: 1,
limit: 10,
},
['name'],
)
assert(totalCount === 2)
assert(organizations[0].ids.organization_id === organizationId1)
assert(organizations[0].name === organizationName1)
assert(organizations[1].ids.organization_id === organizationId2)
assert(organizations[1].name === organizationName2)
} catch (error) {
console.log(error)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment