# Phase 2 — API integration This phase keeps your system and Voicebot in step. A customer appears on your side, an account appears here, and the two stay matched for as long as both exist. Your engineers write that loop once. Optional in scale, not in substance Every integration needs the resources below. Automating them is what this phase adds. With nothing to synchronise, one administrator creates the same resources once — in the Account Panel or with a handful of calls — and this page becomes a checklist rather than a build. ## Step 1 — Authenticate The key from [phase 1](https://docs.aiva.apifonica.com/integration/phase-1-onboarding/#step-4--set-up-the-tenant) is a bearer credential. Send it on every request: ``` Authorization: Bearer ``` There is no exchange step and no token to refresh: the key is what authenticates. Treat it as you would any other production secret. It belongs in your secret store, never in source control, and it reaches your service the way the rest of your credentials do. | Key | Opens | | --------------------------- | -------------------------------------------------------------------- | | A tenant-level user’s key | the Tenant API, and the Account API for every account in your tenant | | An account-level user’s key | the Account API for the one account that user belongs to | A key lives until its `expires_at` passes; [POST/v1/t/user/{sid}/api-key](https://docs.aiva.apifonica.com/api/tenant/operations/issuetenantuserapikey/) states the full lifetime. [Identity and access](https://docs.aiva.apifonica.com/concepts/identity/) covers which key opens what. An exposed key is withdrawn with [DELETE/v1/t/user/{sid}/api-key/{key\_sid}](https://docs.aiva.apifonica.com/api/tenant/operations/revoketenantuserapikey/), and [GET/v1/t/user/-/api-key](https://docs.aiva.apifonica.com/api/tenant/operations/listtenantapikeys/) shows the keys your tenant holds. To replace a key without an outage, issue the new one first, switch your service to it, then revoke the old one. **Done when** [GET/v1/t/account](https://docs.aiva.apifonica.com/api/tenant/operations/listaccounts/) answers under that key. ## Step 2 — Mirror your resources Four resources cross the boundary. All four work the same way: something happens in your system, you call the matching operation here, and the two records stay joined by an identifier **you** choose. You keep your own identifiers Set `external_id` to your own primary key when you create a resource. It is unique on our side, so a repeated create is rejected rather than quietly forking into two records, and you can read and delete by it without storing our sid anywhere. ### Accounts One per organisational unit on your side: a department, a brand, a region, or a customer of yours. [POST/v1/t/account](https://docs.aiva.apifonica.com/api/tenant/operations/createaccount/)\ [PATCH/v1/t/account/{sid}](https://docs.aiva.apifonica.com/api/tenant/operations/patchaccount/)\ [DELETE/v1/t/account/{sid}](https://docs.aiva.apifonica.com/api/tenant/operations/deleteaccount/)\ [GET/v1/t/account](https://docs.aiva.apifonica.com/api/tenant/operations/listaccounts/) ### Users The people who sign in to that account. An account needs at least one. You give each user roles by name. [Roles and permissions](https://docs.aiva.apifonica.com/concepts/roles-and-permissions/) lists the fixed roles of your tenant and what each permission lets a user do. [POST/v1/a/user](https://docs.aiva.apifonica.com/api/account/operations/createuser/)\ [PATCH/v1/a/user/{sid}](https://docs.aiva.apifonica.com/api/account/operations/patchuser/)\ [DELETE/v1/a/user/{sid}](https://docs.aiva.apifonica.com/api/account/operations/deleteuser/)\ [GET/v1/a/user](https://docs.aiva.apifonica.com/api/account/operations/listusers/) ### Numbers An identifier the account places and answers calls on. It is an alphanumeric value carried in a SIP URI, not necessarily a dialable telephone number. [POST/v1/a/number](https://docs.aiva.apifonica.com/api/account/operations/createnumber/)\ [PATCH/v1/a/number/{id}](https://docs.aiva.apifonica.com/api/account/operations/patchnumber/)\ [DELETE/v1/a/number/{id}](https://docs.aiva.apifonica.com/api/account/operations/deletenumber/)\ [GET/v1/a/number](https://docs.aiva.apifonica.com/api/account/operations/listnumbers/) ### Number pools Only if you group numbers. A pool widens the inbound side: an agent bound to one answers on every active number in it. Membership lives on the number rather than on the pool — you attach and detach by patching the number’s `pool_sid`, not by calling the pool. [POST/v1/a/number-pool](https://docs.aiva.apifonica.com/api/account/operations/createnumberpool/)\ [PATCH/v1/a/number-pool/{id}](https://docs.aiva.apifonica.com/api/account/operations/patchnumberpool/)\ [DELETE/v1/a/number-pool/{id}](https://docs.aiva.apifonica.com/api/account/operations/deletenumberpool/)\ [GET/v1/a/number-pool](https://docs.aiva.apifonica.com/api/account/operations/listnumberpools/) ### SMS providers Only if the account sends SMS. It sits outside the loop the four resources above form. A provider is an account’s configuration of an SMS gateway: the one call that hands a message over, and the sender identities registered with that gateway. Your tenant-level key creates one for a named account, the same way it creates that account’s other resources. When you omit `access_type`, you administer the provider: the account reads it and sends through it, and a change or delete from inside the account is refused. So the gateway you contracted keeps pointing where you set it, whoever is administering that account. To let the account administer it, send `access_type: account`. The refusal governs writing, not reading: an administrator of that account can still read the configuration you stored, credentials included. Treat what you put in a provider as visible to the account it serves. An account running an SMS contract of its own configures its own provider instead. Both kinds appear together when that account lists them. [POST/v1/a/integrations/sms/provider](https://docs.aiva.apifonica.com/api/account/operations/createsmsprovider/)\ [PATCH/v1/a/integrations/sms/provider/{id}](https://docs.aiva.apifonica.com/api/account/operations/patchsmsprovider/)\ [DELETE/v1/a/integrations/sms/provider/{id}](https://docs.aiva.apifonica.com/api/account/operations/deletesmsprovider/)\ [GET/v1/a/integrations/sms/provider](https://docs.aiva.apifonica.com/api/account/operations/listsmsproviders/) This one carries no identifier of yours You address a provider by our sid. Store it when you create one — the identifier you set on the four resources above has no counterpart here. **Done when** every resource on your side has a counterpart here, a change on your side reaches it, and a deletion on your side removes it. ## Step 3 — Sign your users in Neither shape below gives your people a second password to remember. Pick one and apply it uniformly. You issue a one-time link for a user and hand it to them: your system redirects them straight into the panel, or delivers the link however it already reaches that person. [POST/v1/a/user/{sid}/magic-link/request](https://docs.aiva.apifonica.com/api/account/operations/issueusermagiclink/)\ [POST/v1/a/auth/magic-link/consume](https://docs.aiva.apifonica.com/api/account/operations/authmagicconsume/) The link is a credential while it is in transit. How it travels matters as much as the fact that it expires. You create the user and drive a password reset; the person then signs in with an email address and a password. [POST/v1/a/user/{sid}/password-reset/request](https://docs.aiva.apifonica.com/api/account/operations/issueuserpasswordreset/)\ [POST/v1/a/auth/regular](https://docs.aiva.apifonica.com/api/account/operations/authregularlogin/) Use this where a redirect is not possible. Either a tenant-level user’s key or that account’s own user’s key can issue the link. [Identity and access](https://docs.aiva.apifonica.com/concepts/identity/) covers the rest. **Done when** one of your people has signed in for real and `last_login_at` comes back set from [GET/v1/a/user](https://docs.aiva.apifonica.com/api/account/operations/listusers/). ## Step 4 — Validate Work through both against a real account rather than a scratch one. Everything your system created here, and the changes it makes afterwards. | # | Check | How | | - | ---------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | 1 | every account on your side has a counterpart here | [GET/v1/t/account](https://docs.aiva.apifonica.com/api/tenant/operations/listaccounts/) | | 2 | numbers registered | [GET/v1/a/number](https://docs.aiva.apifonica.com/api/account/operations/listnumbers/) | | 3 | numbers grouped into pools | [GET/v1/a/number-pool](https://docs.aiva.apifonica.com/api/account/operations/listnumberpools/) | | 4 | a change on your side reaches here | [PATCH/v1/a/number/{id}](https://docs.aiva.apifonica.com/api/account/operations/patchnumber/) | | 5 | a deletion on your side removes the counterpart here | [DELETE/v1/a/number/{id}](https://docs.aiva.apifonica.com/api/account/operations/deletenumber/) | The pass that matters: a user you created signs in and reads their own profile. | # | Check | How | | - | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | | 1 | that user can be issued a one-time link | [POST/v1/a/user/{sid}/magic-link/request](https://docs.aiva.apifonica.com/api/account/operations/issueusermagiclink/) | | 2 | consuming it returns a session | [POST/v1/a/auth/magic-link/consume](https://docs.aiva.apifonica.com/api/account/operations/authmagicconsume/) | | 3 | the session reads its own profile | [GET/v1/a/profile](https://docs.aiva.apifonica.com/api/account/operations/getprofile/) | The profile answers with that user, the account they belong to, and the features enabled for it, so a successful call confirms the whole chain in one request. Passing both is what opens [phase 3](https://docs.aiva.apifonica.com/integration/phase-3-configuration/), however the resources were created.