Skip to content

From Zero to Trunk: Creating a Trunk Group via API (curl) ​

Steps to go from nothing to a SIP trunk group with an access trunk. The example values are placeholders.

If you want to skip the step-by-step setup, click here to go directly to the full script

Setup ​

bash
# Ask for those requirements to our team
BASE="https://<backend-url>"
BASE_URL="$BASE/draas"
DRAAS="<draas_instance>"
GROUP="<group_uuid>"

0. Login (get a token) ​

https://fusion.docs.netaxis.solutions/provisioning/api/000_authentication.html#logging-in

bash
curl -X POST "$BASE/auth/login" \
  -H "Content-Type: application/json" \
  -d '{ "username": "admin@example.com", "password": "********" }'
# → { "access_token": "...", "refresh_token": "..." }   (or a 2fa_payload if 2FA is on)

TOKEN="<access_token>"
AUTH=(-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -H "Accept: application/json")

Remember that a token will expires, so follow the Refresh token procedure to get a new working token for the next requests.

1. Create a tenant ​

POST /{draas}/tenants.

https://fusion.docs.netaxis.solutions/provisioning/api/03_tenants.html#create-a-new-tenant

bash
curl -X POST "$BASE_URL/$DRAAS/tenants" "${AUTH[@]}" \
  -d '{
    "name": "Acme Corp",
    "billingId": "ACME-001",
    "markup": 0,
    "owner": { "type": "reseller", "uuid": "<reseller-uuid>" }
  }'
# → { "uuid": "<tenant-uuid>" }

TENANT="<tenant-uuid>"

owner is optional. It sets the parent entity (distributor or reseller).

2. Create a subscription in the tenant ​

POST /{draas}/tenants/{tenant}/subscriptions.

https://fusion.docs.netaxis.solutions/provisioning/api/04_subscriptions.html#create-a-new-subscription

bash
curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions" "${AUTH[@]}" \
  -d '{ "name": "Acme HQ", "billingId": "ACME-HQ-001" }'
# → { "id": "<subscription-id>" }

SUB="<subscription-id>"

3. Place an order (entitlements and SIP licenses) ​

First list the products available to the tenant to find the SKUs.

https://fusion.docs.netaxis.solutions/provisioning/api/11_products.html#get-the-list-of-products

bash
curl "$BASE_URL/$DRAAS/tenants/$TENANT/products" "${AUTH[@]}"

Then POST /{draas}/tenants/{tenant}/subscriptions/{sub}/orders.

https://fusion.docs.netaxis.solutions/provisioning/api/12_orders.html#submit-a-new-order-for-providing-resources

bash
curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/orders" "${AUTH[@]}" \
  -d '{
    "name": "Acme HQ",
    "products": [
      { "sku": "SIP-TRUNK-CHANNEL", "quantity": 10 },
      { "sku": "BE-GEO-NUMBER",     "quantity": 10 }
    ]
  }'

The SKUs above are examples, so use the ones returned by /products.

Optional check of what was granted:

https://fusion.docs.netaxis.solutions/provisioning/api/07_entitlements.html#list-all-number-entitlements-of-a-subscription

https://fusion.docs.netaxis.solutions/provisioning/api/06_licenses.html#get-the-licenses-of-a-subscription

bash
curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/entitlements" "${AUTH[@]}"
bash
curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/licenses" "${AUTH[@]}"

4. Assign numbers to the subscription ​

Find ranges that can be assigned ​

bash
curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/number_inventory/ranges?page_size=100&filters=%7B%22country_code%22:%22%2B32%22,%22number_type%22:%22geo%22%7D" "${AUTH[@]}"

where the query params are:

  • page_size
  • filters is a dictionary (eg. {"country_code":"+32","number_type":"geo"}) that holds
    • country_code in the format +32
    • number_type could be geo, mobile, tollFree (depending on what has been defined in NIMS)

Get number suggestions from NIMS ​

https://fusion.docs.netaxis.solutions/provisioning/api/97_public_data.html#get-a-number-suggestion-from-the-nims

bash
curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/number_inventory/suggestions?numberType=geo&countryCode=%2B32&startsWith=&rangeSize=1&numberOfResults=1&rangeId=36" "${AUTH[@]}"

where the query params are:

  • numberType could be geo, mobile, tollFree (depending on what has been defined in NIMS)
  • countryCode in the format +32 (needs url encoding)
  • startsWith if you need to specify a prefix
  • rangeSize is the amount of consecutive numbers
  • numberOfResults is the amount of different suggestions you wants
  • rangeId is the ID of the range retrieved above

Then POST /{draas}/tenants/{tenant}/subscriptions/{sub}/numbers.

https://fusion.docs.netaxis.solutions/provisioning/api/08.1_numbers.html#add-numbers-to-the-subscription

Option A: by range ([start, end] NSN pairs, inclusive):

bash
curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/numbers" "${AUTH[@]}" \
  -d '{ "countryCode": "+32", "ranges": [[22001000, 22001009]] }'

Option B: individual numbers.

bash
curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/numbers" "${AUTH[@]}" \
  -d '{ "countryCode": "+32", "numbers": [22001000, 22001001] }'

5. Create the SIP trunk (trunk group) ​

Optional: list the trunk types enabled for the subscription.

bash
curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups_types" "${AUTH[@]}"
# → { "trunkTypes": ["sip", ...] }

5a. Create the trunk group. POST .../trunkgroups.

https://fusion.docs.netaxis.solutions/provisioning/api/09_trunking.html#create-a-new-trunk-group

bash
curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups" "${AUTH[@]}" \
  -d '{
    "name": "acme-hq-trunk",
    "billingId": "ACME-TG-001",
    "calledFormat": "e164",
    "callingFormat": "e164",
    "maxCalls": 10,
    "maxIncomingCalls": 10,
    "maxOutgoingCalls": 10,
    "region": "<region>"
  }'
# → { "id": "<trunk-id>" }

TRUNK="<trunk-id>"
  • Format values: e164, national_with_0, international_with_00, international_without_00.
  • For a non-sip trunk type, add "type": "<trunkType>". You can leave type out for plain sip.

5b. Find free numbers in the subscription that can be assigned to the trunk.

https://fusion.docs.netaxis.solutions/provisioning/api/08.1_numbers.html#list-free-numbers-of-a-subscription

bash
curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/free_numbers?page_size=100" "${AUTH[@]}"

5c. Attach DIDs to the trunk. POST .../trunkgroups/{trunk}/numbers.

https://fusion.docs.netaxis.solutions/provisioning/api/09_trunking.html#add-numbers-to-a-trunk-group

bash
curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups/$TRUNK/numbers" "${AUTH[@]}" \
  -d '{ "numbers": ["+3222001000", "+3222001001"] }'

5d. Set the pilot number. Look up the DID's connectionId, then set it as pilot.

https://fusion.docs.netaxis.solutions/provisioning/api/09_trunking.html#get-numbers-from-a-trunk-group

https://fusion.docs.netaxis.solutions/provisioning/api/09_trunking.html#modify-an-existing-trunk-group

bash
curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups/$TRUNK/numbers?page_size=1000" "${AUTH[@]}"
# → { "numbers": [ { "fullNumber": "+3222001000", "connectionId": 4711, ... } ] }

curl -X PUT "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups/$TRUNK" "${AUTH[@]}" \
  -d '{ "pilot": 4711 }'

6. Create an access trunk in the trunk group ​

List the POPs available to the subscription to get their ids.

https://fusion.docs.netaxis.solutions/provisioning/api/97_public_data.html#get-trunking-pops

bash
curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunking_pops" "${AUTH[@]}"

POST .../trunkgroups/{trunk}/access_trunks.

https://fusion.docs.netaxis.solutions/provisioning/api/09_trunking.html#create-a-new-access-trunk

bash
curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups/$TRUNK/access_trunks" "${AUTH[@]}" \
  -d '{
    "name": "acme-hq-access-1",
    "billingId": "ACME-AT-001",
    "priority": 1,
    "weight": 100,
    "trunkLocale": "BE",
    "authRequired": false,
    "pops": [
      {
        "id": 1,
        "inboundCalls": true,
        "outboundCalls": true,
        "transport": "UDP",
        "sipOptions": true,
        "privateRealm": false
      }
    ],
    "primaryPeerIp": "203.0.113.10",
    "primaryPeerPort": 5060,
    "ipWhitelist": "203.0.113.0/28"
  }'
  • priority: 1 to 5. transport: UDP or TCP.
  • Include only the POPs you want enabled.

Script ​

We suggest to create a bash script to set variables, grab responses, extract values and so on during runs.

bash
#!/usr/bin/env bash

BASE="https://apio-dev.fusion.netaxis.cloud/api/v01"
BASE_URL="$BASE/draas"
DRAAS="node4_fusion_dev"
GROUP="adb26c5a-38bf-469c-87e2-20445fa1e64d"

response=$(curl -X POST "$BASE/auth/login" -H "Content-Type: application/json" -d '{ "username": "n4_dev_g", "password": "ChangeMe1!" }')

TOKEN=$(echo "$response" | jq -r '.access_token')

AUTH=(
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-H "Accept: application/json"
)

QUERY_PARAMS="?page_size=9999"

### Support Func ###
build_query_string() {
  # Pass positional arguments into jq via stdin
  printf '%s\n' "$@" | jq -sRr '
    split("\n")
    | map(
        select(length > 0)
        | @uri
      )
    | join("&")
  '
}
### /Support Func ###

echo "--- Creating a new tenant ---"
response=$(curl -X POST "$BASE_URL/$DRAAS/tenants" "${AUTH[@]}" \
  -d '{
    "name": "Acme Corp",
    "billingId": "ACME-001",
    "markup": 0,
    "owner": { "type": "reseller", "uuid": "<reseller-uuid>" }
  }')
TENANT=$(echo "$response" | jq -r '.uuid')
echo "Created tenant with UUID: $TENANT"


echo "--- Creating a new subscription inside tenant $TENANT ---"
response=$(curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions" "${AUTH[@]}" \
  -d '{ "name": "Acme HQ", "billingId": "ACME-HQ-001" }')
SUB=$(echo "$response" | jq -r '.id')
echo "Created subscription with ID: $SUB"


echo "--- Listing products ---"
response=$(curl "$BASE_URL/$DRAAS/groups/$GROUP/products$QUERY_PARAMS" "${AUTH[@]}")
products=$(echo "$response" | jq -r '.products')
echo "Available products: $products"


echo "--- Ordering products for tenant/subscription $TENANT/$SUB ---"
response=$(curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/orders" "${AUTH[@]}" \
  -d '{
    "name": "Acme HQ",
    "products": [
      { "sku": "SIP-TRUNK-CHANNEL", "quantity": 10 },
      { "sku": "BE-GEO-NUMBER",     "quantity": 10 }
    ]
  }')
echo "Created order: $response"


echo "--- Listing entitlements ---"
response=$(curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/entitlements$QUERY_PARAMS" "${AUTH[@]}")
entitlements=$(echo "$response" | jq -r '.entitlements')
echo "Available entitlements: $entitlements"

echo "--- Listing licenses ---"
response=$(curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/licenses$QUERY_PARAMS" "${AUTH[@]}")
licenses=$(echo "$response" | jq -r '.licenses')
echo "Available licenses: $licenses"


echo "--- Assigning numbers to tenant/subscription $TENANT/$SUB ---"

echo "--- Listing number ranges ---"
RANGES_QUERY_PARAMS=(
"page_size=100"
"{\"country_code\":\"+32\",\"number_type\":\"geo\"}"
)
RANGES_QUERY_PARAMS_ENC=$(build_query_string "${RANGES_QUERY_PARAMS[@]}")

response=$(curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/number_inventory/ranges$RANGES_QUERY_PARAMS_ENC" "${AUTH[@]}")
echo "Available ranges: $response"

echo "--- Get number suggestions ---"
SUGGESTION_QUERY_PARAMS=(
"numberType=geo"
"countryCode=+32"
"rangeSize=1"
"numberOfResults=1"
"rangeId=36"
)
SUGGESTION_QUERY_PARAMS_ENC=$(build_query_string "${SUGGESTION_QUERY_PARAMS[@]}")

response=$(curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/number_inventory/suggestions$SUGGESTION_QUERY_PARAMS_ENC" "${AUTH[@]}")
echo "Suggestions: $response"

echo "--- Assigning numbers ---"
response=$(curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/numbers" "${AUTH[@]}" \
  -d '{ "countryCode": "+32", "ranges": [[22001000, 22001009]] }')
echo "Created order: $response"


echo "--- Creating SIP trunk on tenant/subscription $TENANT/$SUB ---"

echo "--- Listing free numbers ---"
response=$(curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups_types$QUERY_PARAMS" "${AUTH[@]}")
trunkTypes=$(echo "$response" | jq -r '.trunkTypes')
echo "Available trunk types: $trunkTypes"

response=$(curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups" "${AUTH[@]}" \
  -d '{
    "name": "acme-hq-trunk",
    "billingId": "ACME-TG-001",
    "calledFormat": "e164",
    "callingFormat": "e164",
    "maxCalls": 10,
    "maxIncomingCalls": 10,
    "maxOutgoingCalls": 10,
    "region": "<region>"
  }')
TRUNK=$(echo "$response" | jq -r '.id')
echo "Created trunk group with ID: $TRUNK"


echo "--- Assign numbers to SIP trunk $TRUNK ---"

echo "--- Listing free numbers ---"
response=$(curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/free_numbers$QUERY_PARAMS" "${AUTH[@]}")
free_numbers=$(echo "$response" | jq -r '.free_numbers')
echo "Available free numbers: $free_numbers"


response=$(curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups/$TRUNK/numbers" "${AUTH[@]}" \
  -d '{ "numbers": ["+3222001000", "+3222001001"] }')
echo "Assigned numbers to trunk group $TRUNK: $response"


echo "--- Update pilot number of SIP trunk $TRUNK ---"

echo "--- Listing trunk numbers ---"
response=$(curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups/$TRUNK/numbers$QUERY_PARAMS" "${AUTH[@]}")
trunk_numbers=$(echo "$response" | jq -r '.numbers')
echo "Trunk numbers: $trunk_numbers"

response=$(curl -X PUT "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups/$TRUNK" "${AUTH[@]}" \
  -d '{ "pilot": 4711 }')
echo "Updated pilot number for trunk group $TRUNK: $response"


echo "--- Creating access trunks for SIP trunk $TRUNK ---"

echo "--- Listing Trunking PoPs ---"
response=$(curl "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunking_pops" "${AUTH[@]}")
trunk_pops=$(echo "$response" | jq -r '.pops')
echo "Trunking PoPs: $trunk_pops"

response=$(curl -X POST "$BASE_URL/$DRAAS/tenants/$TENANT/subscriptions/$SUB/trunkgroups/$TRUNK/access_trunks" "${AUTH[@]}" \
  -d '{
    "name": "acme-hq-access-1",
    "billingId": "ACME-AT-001",
    "priority": 1,
    "weight": 100,
    "trunkLocale": "BE",
    "authRequired": false,
    "pops": [
      {
        "id": 1,
        "inboundCalls": true,
        "outboundCalls": true,
        "transport": "UDP",
        "sipOptions": true,
        "privateRealm": false
      }
    ],
    "primaryPeerIp": "203.0.113.10",
    "primaryPeerPort": 5060,
    "ipWhitelist": "203.0.113.0/28"
  }')
echo "Created access trunks on trunk group $TRUNK: $response"