Skip to main content

Create and manage companies

Companies are organisation units (entityType: 'ou'). They can be nested: a holding has subsidiaries, a subsidiary has departments.

import sdk from '@scenid/cloud-sdk'

const { OU } = sdk.asAdmin().Customers()

Create a company​

const { status, result: company } = await OU.create(
{
data: {
ouType: 'ou',
name: 'Nordlicht Holding GmbH',
legalForm: 'gmbh'
}
},
{ return: true }
)

console.log(company.humanId) // "SC-ZW2VEG"
FieldRequiredNotes
nameyesAt least 3 characters
ouTypeyesDefaults to the catalog value for "organisation unit". Free values are allowed
legalFormnoCatalog key: gmbh, ag, kg, ug, gmbh_co_kg, eg, ev, ggmbh, ohg, gbr, partg, einzelunternehmen, se, …
Create validates the full schema by default

Create validates data against the same full schema update uses, so address, contacts, website and every other field below can be set right at creation time. This guide still sets them with a follow-up update to show that flow, but a single OU.create() call with the full data works too. Pass { schema: 'minimal' } as a third option to OU.create() to go back to validating just ouType, name and legalForm.

Add address, contacts and details​

update merges into the existing data by default. Pass overwrite: true to replace everything instead.

await OU.update('SC-ZW2VEG', {
data: {
hasAddress: true,
street: 'Hafenstraße',
houseNo: '12',
zipCode: '20457',
city: 'Hamburg',
countryCode: 'DE',
website: 'https://nordlicht-holding.example',
openingHours: 'Mo-Fr 08:00-17:00',
contacts: [
{ contactType: 'email', value: { email: 'info@nordlicht-holding.example' }, isFavorite: true },
{
contactType: 'phone',
value: { phone: { countryCode: 'DE', dialingCode: '+49', number: '405550100' } },
isFavorite: false
}
]
}
})

Rules worth knowing:

  • hasAddress: true is required to set address fields. With hasAddress: false they are rejected.
  • countryCode is an ISO code from the catalog (DE, AT, CH, …).
  • location (coordinates) is computed from the address. You do not send it.
  • website must be a valid URL.
  • contacts[].contactType is email, phone, mobile or fax. Email values are { email }, phone values { phone: { countryCode, dialingCode, number } }.

Create a hierarchy​

Pass parent (a humanId) on create, or move an existing company later:

const { result: sub } = await OU.create(
{ data: { ouType: 'ou', name: 'Nordlicht Software GmbH', legalForm: 'gmbh' }, parent: company.humanId },
{ return: true }
)

// Move under another parent, or to the top level
await OU.move(sub.humanId, 'SC-OTHER1')
await OU.move(sub.humanId)

Create with employees and groups in one call​

await OU.create({
data: { ouType: 'ou', name: 'Bergmann & Söhne KG', legalForm: 'kg' },
employees: [{ humanId: 'SC-PERSON', roles: [{ role: 'ceo', status: 'active' }] }],
groups: ['Key accounts']
})

groups take group names. The SDK resolves them to IDs (cached for five minutes). An unknown name throws customers/group-not-found.

Read​

// Everything
const { result } = await sdk.asAdmin().Customers().Entity.get('SC-ZW2VEG')

// Selected fields only
const { result: slim } = await sdk.asAdmin().Customers().Entity.get('SC-ZW2VEG', ['data.name', 'data.city'])

Deactivate and delete​

await OU.update('SC-ZW2VEG', { data: { active: false } })
await OU.delete('SC-ZW2VEG') // { result: 'deleted', humanId: 'SC-ZW2VEG' }

Inactive companies are hidden by hideInactive: true in searches.

Update semantics at a glance​

CallEffect
update(id, { data })Merges the given fields into the existing data
update(id, { overwrite: true, data })Replaces data completely. Missing fields are removed
employees, groups in the bodyReplaces the full list. Anything not listed is removed

Use upsertEmployee and removeEmployee to change a single employment, see Employments.