English Swedish
Auto Light Dark
Auto Light Dark
English Swedish
Breadcrumbs

The Service Account API

The Service Account API lets a server integrate with your whole Dstny organization without signing in as a user. Think of it as a robot user. Your system logs in as the service account, receives a token that lasts one hour, and uses it to read data or perform actions in your organization.

When to use it

Use a service account when an integration needs organization-wide access, for example to show live queue numbers on a wallboard, look up contacts from a CRM, read or set presence from another system, or read function numbers and queue information. The Core User API ties each ticket to one user, so it fits a single user's application better.

A service account is for systems, not for people, and it only works inside your own organization. It can do only what its scopes allow. Without the right scope, the API returns 403.

Price

Any customer can request a service account.

Customer

Price

Enterprise contract

Included

Other customers

995 SEK per month per service account, plus a one-time setup fee of 1,500 SEK per service account

Prices exclude VAT. You need someone who can build the integration, such as your IT team or a supplier.

Access

Ask Dstny to set up a service account for your organization and tell Dstny which scopes you need (see Scopes below). Dstny creates the account with a name and a secret, and gives you a client ID, a client secret, the token address and the API address.

  • The service account secret is shown only once. Store it in a password manager or secret vault straight away, not in code, email or chat. If you lose it, Dstny creates a new service account and deletes the old one.

  • Dstny sends the connection details to a named technical contact, and sends the secrets separately in a protected message.

  • A service account has an expiry date. When it passes, the integration stops with 401 errors. Ask Dstny for the date and plan the renewal.

Authenticate

Send one request to the token endpoint with these values:

Value

Content

client_id

The client ID from Dstny

client_secret

The client secret from Dstny

grant_type

password

username

The service account name

password

The service account secret

curl -X POST \
  "https://keycloak.eu-nordics-sto-production.dstny.d4sp.com/auth/realms/dstnyse-skondal-dstnyse/protocol/openid-connect/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "client_id={client_id}" \
  -d "client_secret={client_secret}" \
  -d "grant_type=password" \
  -d "username={sa-username}" \
  -d "password={sa-password}"

The response contains a JWT (a signed token, RFC 7519) in access_token. It is valid for 3600 seconds. Send it as a bearer token on each request, and reuse it until it expires. Do not request a new token for every call. When a call returns 401, request a new one.

The API address for the Sköndal environment is:

https://api.eu-nordics-sto-production.dstny.d4sp.com/api-admin/realm/dstnyse-skondal-dstnyse/fwd/api
GET {api-address}/queue/statistics/v1/list/{domain}
Authorization: Bearer {access_token}
Accept: application/json

{domain} is your organization's domain. All calls go to this one address, also calls that are administration calls in the Core documentation. The normal Core API documentation still applies. Only the address changes.

The full list of calls, parameters and responses is in the Service Account API specification.

To try the calls in Postman, import the Service Account API Postman collection with File, Import. Fill in the variables, then run Get access token first.

Scopes

Each scope opens one part of the API. Dstny enables only what you ask for. If you need more later, Dstny can add scopes to the same service account, and you then request a new token.

Standard set

These are enabled by default.

Scope

What it allows

Contact search

The global contacts defined in your organization

Queue statistics

Current statistics for queues

User info

Basic user information such as lines, devices and photo. Read and set presence (activity, availability, note) and manage presence shortcuts

ACD/attendant queues

View and log in to queues, for users who are agents or attendants

Function numbers

List the function numbers in your organization

Additional scopes

These are enabled only when you ask for them.

Scope

What it allows

Good to know

User provisioning

List users, read user details, create and delete user tickets

Lets the account create a ticket for any user in your organization, which opens user-only data such as call history

Organization provisioning

Organization settings, for example the presence activities

Wider organization access

Communication Log

Call history, group inbox messages and voicemails

Exposes individual users' communication history

Call recording

Create tickets that control call recording

Sensitive. You are responsible for recording consent and GDPR

Call control

Control calls and follow call state

Needs a Call Control API license for the user and "Enable Cloud CTI API" turned on for the user

Call setup

Start outbound calls from selected devices and control diversions

Lets the system act on calls

Event channel

Used for mobile chat


Line state

Lets external telephony systems report line state

Needs a Line State API license for the user

Personal contacts

Create and manage personal contacts

Private user data

Voicemail settings

Read, change and reset voicemail settings


Reports

Call detail record (CDR) reports

Gives access to call records

Give each integration its own service account and the fewest scopes it needs. Delete service accounts you no longer use.

Common calls

Goal

Scope

Call

Queue statistics for all queues

Queue statistics

GET /queue/statistics/v1/list/{domain}

Statistics for one queue

Queue statistics

GET /queue/statistics/v1/{domain}/{queueId}

Search contacts

Contact search

GET /contacts/list/{domain}/{user}?query=

Look up a contact by number

Contact search

GET /contacts/lookup/v1/{domain}/{user}/{number}

Read a user's presence

User info

GET /user/info/{domain}/{user}/presence

Set a user's activity

User info

PUT /user/info/{domain}/{user}/activity/{activityId}

List a user's ACD and attendant groups

ACD/attendant queues

GET /user/acd-attendant-group/v1/{domain}/{user}

List function numbers

Function numbers

GET /admin/fnr/{domain}

List users

User provisioning

GET /admin/useradmin/list/v1/{domain}?query=

Other things the service account can do, with the matching scope, include call control and call state, diversion rules, webhooks for call state, presence and user configuration changes across the organization, and fetching call detail records as CSV. Use JSON for requests and responses. XML is deprecated.

Endpoints that need a user ticket

Some endpoints, such as the communication log, do not accept a service account token directly. The call returns 403 "no profile match", even when the scope is enabled. The workaround is supported:

  1. Ask for the User provisioning scope.

  2. Use the service account token to create a short-lived ticket for one user, without the user's password or 2FA: POST /tickets/v1/{domain}/{userId} with a body such as {"expires":3600,"ticketName":"example","allowedApis":["COMMUNICATION_LOG","DISTRIBUTION_GROUP"]}. expires is in seconds.

  3. Call the user-only endpoint at the baseUrl from the response, with the ticket as bearer token and /api added after the address, for example GET {baseUrl}/api/communicationlog/{domain}/{userId}?limit=50. Without /api the call returns 403.

  4. Delete the ticket with DELETE /tickets/v1/{domain}/{userId}/{ticketName} when you are done.

A ticket reads only its own user's data, and a ticket can last at most one year. Keep the life short, from hours to days, and create a new ticket when a call returns 401 or 403. The communication log shows the user's own view of calls: remote number, start time (UTC), duration in seconds (0 for missed calls) and direction. To see who answered a group call, use a ticket with the DISTRIBUTION_GROUP scope and GET {baseUrl}/api/user/distgroup/{domain}/{userId}/calllog. It covers only groups where the ticket's user is an agent or attendant.

The calls you can make with the ticket are in the Core User API specification.

Good to know

  • Presence: you can only set activities that exist in your organization. An administrator adds them. The list comes from GET /admin/organization/v1/presence/activity/{domain}?language=sv and needs the Organization provisioning scope.

  • Queue statistics update with a delay, so a call made a minute ago may not show yet.

  • A service account cannot send SMS. SMS is a user function in the Core User API.

  • Normal outbound HTTPS (port 443) to Dstny addresses is enough. If your firewall rules use IP addresses instead of names, ask Dstny for the current addresses.

  • Older deprecated endpoints are removed in Core 6.0.0. New integrations should use /admin/useradmin/list/v1/, /admin/useradmin/v1/ and /tickets/v1/. Core 6.0.0 also lets an administrator limit a service account's user administration access with an admin profile.

Troubleshooting

What you see

Likely cause

What to do

The token request fails with 401, invalid_client or invalid_grant

Wrong client ID or secret, wrong service account name or secret, or the service account has expired

Check each value for typos and spaces, then ask Dstny to check the expiry date

An API call returns 401

The token is older than one hour

Request a new token

An API call returns 403

The scope is not enabled, or the endpoint is user-only

Ask Dstny to check the scopes, then request a new token. For user-only endpoints, use the ticket workaround

Call control or call state fails although the scope is enabled

The user has no Call Control API license, or "Enable Cloud CTI API" is off

Check the license and the setting on the user

Line state reporting fails although the scope is enabled

The user has no Line State API license

Check the license on the user

A user-only call with a ticket returns 403

/api is missing after the ticket's baseUrl, or the ticket belongs to another user

Add /api and use the ticket for the right user

An API call returns 400

A validation error. The response lists the field and an error code

Read the field list. If the response has a header such as Warning: 703 "Error occurred, see {token}", give that token to Dstny support

Contact search returns nothing

Usually a scope or permission problem, not missing data

Check that Contact search is enabled

Calls fail suddenly after working for months

The service account reached its expiry date

Ask Dstny for a new service account

Last updated: