Associate a Phone Number with the SIP Trunk
# support
v
request { "provider": "byo-sip-trunk", "name": "Provider", "number": "sip:xxxxxxxxxxx@sip.vapi.ai", //"number": "yyyyyyyy", "numberE164CheckEnabled": false, "credentialId": "??????????????" } shell it be a "number" from https://dashboard.vapi.ai/phone-numbers where do I get it credentialId? response { "message": [ "property number should not exist", "property numberE164CheckEnabled should not exist", "property credentialId should not exist", "gateways should not be empty", "gateways must be an array" ], "error": "Bad Request", "statusCode": 400 }
v
Hi there! I see you're trying to associate a phone number with a SIP trunk in Vapi, but there seems to be some confusion in the API request you're making. Based on the error message, it looks like you're trying to create a SIP trunk credential rather than associate a phone number with an existing credential. Let me help clarify the process: ## Step 1: Create a SIP Trunk Credential First, you need to create a SIP trunk credential to get a `credentialId`:
Copy code
bash
curl -X POST https://api.vapi.ai/credential \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "provider": "byo-sip-trunk",
  "name": "My SIP Trunk",
  "gateways": [
    {
      "ip": "your.sip.provider.ip", 
      "port": 5060,
      "inboundEnabled": true,
      "outboundEnabled": true
    }
  ],
  "outboundAuthenticationPlan": {
    "authUsername": "your_outbound_username",
    "authPassword": "your_outbound_password",
    "sipRegisterPlan": {
      "realm": "your.sip.provider.domain",
      "username": "your_register_username",
      "domain": "your.sip.provider.domain",
      "publicIpInContactEnabled": false
    }
  }
}'
The response will contain your
credential_id
that you'll need for the next step. ## Step 2: Associate a Phone Number with the SIP Trunk Once you have your
credentialId
, you can associate a phone number with it:
Copy code
bash
curl -X POST https://api.vapi.ai/phone-number \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "provider": "byo-phone-number",
  "number": "+1234567890",
  "numberE164CheckEnabled": false,
  "credentialId": "credential_id_from_step_1"
}'
For the
number
property, you should use the E.164 format (e.g., "+1234567890") rather than a SIP URI format. I hope this helps! Let me know if you have any other questions. 😊 Sources: - [Discord Source](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341469652366266408)
v
Kindly check. request { "provider": "byo-phone-number", "name": "+xxxxxxxxxxx", "numberE164CheckEnabled": false, "credentialId": "xxxxxxxxx-5a76-4308-9443-xxxxxxxxx" }
response { "message": "Couldn't Create Phone Number.", "error": "Bad Request", "statusCode": 400 }
v
Message marked as helpful by @Vladimir! 🎉
v
Kindly check. request { "provider": "byo-phone-number", "name": "+xxxxxxxxxxx", "numberE164CheckEnabled": false, "credentialId": "xxxxxxxxx-5a76-4308-9443-xxxxxxxxx" } response { "message": "Couldn't Create Phone Number.", "error": "Bad Request", "statusCode": 400 }
I have used my credential_id
follow up please help me!
s
Here's the correct way to create a BYO phone number and associate it with your SIP trunk: \`\`\`json { "provider": "byo-phone-number", "number": "+xxxxxxxxxxx", // Replace with your actual number in E.164 format "numberE164CheckEnabled": false, // Set to false if using non-standard formats "credentialId": "xxxxxxxxx-5a76-4308-9443-xxxxxxxxx" // Your existing SIP trunk credential ID } \`\`\` Make the request to:
POST https://api.vapi.ai/phone-number
The key points to remember: 1\. Use
provider: "byo-phone-number"
when adding a phone number (not "byo-sip-trunk") 2\. Include the
number
field with your phone number (this is required) 3\. The
credentialId
must be an existing SIP trunk credential ID 4\. Set
numberE164CheckEnabled: false
if you're using a non-E.164 format number (like "123" or "abc") If you need to create a SIP trunk credential first, use a request like this: \`\`\`json { "provider": "byo-sip-trunk", "name": "My SIP Trunk", "gateways": \[ { "ip": "your.sip.provider.ip", "port": 5060, "inboundEnabled": true, "outboundEnabled": true } \] } \`\`\` Make this request to:
POST https://api.vapi.ai/credential
The response will give you a credential ID that you can then use in the phone number creation request. Would you like me to help with any other part of this process?
s
so do you need the "trunkId" or "id" as credentialId there is no CredentialId field in the api output
s
@Specialist when you create a BYO SIP trunk credential in Vapi, the system: 1. Generates a UUID (
credentialId
) to identify your credential in Vapi's database 2. Creates an account, API key, application, and trunk in the SIP backend 3. Stores the external reference IDs in a configuration object called sbcAccountConfiguration When associating a phone number with a SIP trunk, you need to use the id from the SIP trunk credential as the credentialId in your request - not the trunkId from inside the sbcAccountConfiguration. Here's the correct way to create a BYO phone number:
Copy code
json

{

  "provider": "byo-phone-number",

  "number": "+xxxxxxxxxxx",  // Your phone number in E.164 format

  "numberE164CheckEnabled": false,  // Set to false if non-standard format

  "credentialId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"  // The UUID of your SIP trunk credential

}
The credentialId should be the Vapi credential id value, which is the UUID you receive when creating a SIP trunk credential. This is NOT the same as the trunkId inside the sbcAccountConfiguration. When you create a SIP trunk credential through the API, the response will include an id field - this is the value you need to use as the credentialId when creating a phone number.
@Vladimir @Specialist Let me know if you require further help.
s
I'll give it a try, so far I am using sip direct uri calling and it works fine, so not sure why I would need a trunk, probably for outgoing calls?
3 Views