Skip to main content

Twexit

| cURL | Python | Node | Ruby |


The Twexit API allows users to send messages and receive message notifications with minimal changes to existing Twilio messaging code. This makes it easier than ever to leave Twilio and begin utilizing Telnyx to send and receive text messages.

Mission control portal setup

To use the Twexit API, please ensure the following:

  1. You have active numbers on the portal.
  2. You have created a Messaging Profile to send and receive messages.

Once you have your profile created, select Twexit API under API Version in the Messaging Profile settings.

You should now receive inbound messages and webhooks in Twilio's format.

Finding the organization id

To find your organization id, run the following curl command:

curl --request GET \
--url https://api.telnyx.com/v2/whoami \
--header 'Authorization: Bearer ${auth_v2_api_key}'

Note: After pasting the above content, Kindly check and remove any new line added

This endpoint will respond with

{
"data": {
"organization_id": "ORGANIZATION_ID",
"user_id": "USER_ID"
}
}

Note: After pasting the above content, Kindly check and remove any new line added

cURL

Sending a message

Fill in the organization id and the auth v2 api key below:

curl -u "\${organization_id}":"\${auth_v2_api_key}" \\
--data-urlencode 'From=+13125550000' \\
--data-urlencode 'To=+13125550001' \\
--data-urlencode 'Body=Hello, World!' \\
https://api.telnyx.com/2010-04-01/Accounts/{organization_id}/Messages.json

Note: After pasting the above content, Kindly check and remove any new line added

The response will contain:

{
"sid": "40317159-f30d-4940-b751-9a6e81727249",
"date_created": "Wed, 08 Apr 2020 13:20:33 +0000",
"date_updated": "Wed, 08 Apr 2020 13:20:33 +0000",
"date_sent": null,
"account_sid": "${account_id}",
"to": "+13125550000",
"from": "+13125550001",
"messaging_service_sid": "40017155-44c7-4d18-8fa5-332c1a776db5",
"body": "Hello, World!",
"status": "queued",
"num_segments": "1",
"num_media": "0",
"direction": "outbound-api",
"api_version": "2010-04-01",
"price": null,
"price_unit": "USD",
"error_code": null,
"error_message": null,
"uri": "/2010-04-01/Accounts/{organization_id}/Messages/40317159-f30d-4940-b751-9a6e81727249.json",
"subresource_uris": {
"media": "/2010-04-01/Accounts/{organization_id}/Messages/40317159-f30d-4940-b751-9a6e81727249/Media.json"
}
}

Note: After pasting the above content, Kindly check and remove any new line added

Python

Sending a message

Fill in the organization id and the auth v2 api key below:

import requests
from requests.auth import HTTPBasicAUth
url = f"https://api.telnyx.com/2010-04-01/Accounts/{organization_id}/Messages.json"
auth = HTTPBasicAuth(organization_id, auth_v2_api_key)
data = {
"From": "+13125550000", # Your Telnyx number
"To": "+13125550001",
"Body": "Hello, World!"
}
response = requests.request('POST', url, auth=auth, data=data)
print(response.text)

Note: After pasting the above content, Kindly check and remove any new line added

The response will contain:

{
"sid": "40317159-f30d-4940-b751-9a6e81727249",
"date_created": "Wed, 08 Apr 2020 13:20:33 +0000",
"date_updated": "Wed, 08 Apr 2020 13:20:33 +0000",
"date_sent": null,
"account_sid": "${account_id}",
"to": "+13125550000",
"from": "+13125550001",
"messaging_service_sid": "40017155-44c7-4d18-8fa5-332c1a776db5",
"body": "Hello, World!",
"status": "queued",
"num_segments": "1",
"num_media": "0",
"direction": "outbound-api",
"api_version": "2010-04-01",
"price": null,
"price_unit": "USD",
"error_code": null,
"error_message": null,
"uri": "/2010-04-01/Accounts/{organization_id}/Messages/40317159-f30d-4940-b751-9a6e81727249.json",
"subresource_uris": {
"media": "/2010-04-01/Accounts/{organization_id}/Messages/40317159-f30d-4940-b751-9a6e81727249/Media.json"
}
}

Note: After pasting the above content, Kindly check and remove any new line added

Node

Sending a message

Fill in the organization id and the auth v2 api key below:

// https://github.com/visionmedia/superagent#install
const superagent = require('superagent');
superagent
.auth(organization_id, auth_v2_api_key)
.post(`https://api.telnyx.com/2010-04-01/Accounts/${organization_id}/Messages.json`)
.send({
From: '+13125550000', // Your Telnyx number
To: '+13125550001',
Body: "Hello, World!"
})
.then((response) => {
console.log(response.body);
});

Note: After pasting the above content, Kindly check and remove any new line added

The response will contain:

{
"sid": "40317159-f30d-4940-b751-9a6e81727249",
"date_created": "Wed, 08 Apr 2020 13:20:33 +0000",
"date_updated": "Wed, 08 Apr 2020 13:20:33 +0000",
"date_sent": null,
"account_sid": "${account_id}",
"to": "+13125550000",
"from": "+13125550001",
"messaging_service_sid": "40017155-44c7-4d18-8fa5-332c1a776db5",
"body": "Hello, World!",
"status": "queued",
"num_segments": "1",
"num_media": "0",
"direction": "outbound-api",
"api_version": "2010-04-01",
"price": null,
"price_unit": "USD",
"error_code": null,
"error_message": null,
"uri": "/2010-04-01/Accounts/{organization_id}/Messages/40317159-f30d-4940-b751-9a6e81727249.json",
"subresource_uris": {
"media": "/2010-04-01/Accounts/{organization_id}/Messages/40317159-f30d-4940-b751-9a6e81727249/Media.json"
}
}

Note: After pasting the above content, Kindly check and remove any new line added

Ruby

Sending a message

Fill in the organization id and the auth v2 api key below:

require "net/http"
require "uri"
uri = URI("https://api.telnyx.com/2010-04-01/Accounts/#{organization_id}/Messages.json")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request.basic_auth organization_id, auth_v2_api_key
body = {
From: "+13125550000", # Your Telnyx number
To: "+13125550001",
Body: "Hello, World!"
}
request.body = body.to_json
response = http.request(request)
puts response.read_body

Note: After pasting the above content, Kindly check and remove any new line added

The response will contain:

{
"sid": "40317159-f30d-4940-b751-9a6e81727249",
"date_created": "Wed, 08 Apr 2020 13:20:33 +0000",
"date_updated": "Wed, 08 Apr 2020 13:20:33 +0000",
"date_sent": null,
"account_sid": "${account_id}",
"to": "+13125550000",
"from": "+13125550001",
"messaging_service_sid": "40017155-44c7-4d18-8fa5-332c1a776db5",
"body": "Hello, World!",
"status": "queued",
"num_segments": "1",
"num_media": "0",
"direction": "outbound-api",
"api_version": "2010-04-01",
"price": null,
"price_unit": "USD",
"error_code": null,
"error_message": null,
"uri": "/2010-04-01/Accounts/{organization_id}/Messages/40317159-f30d-4940-b751-9a6e81727249.json",
"subresource_uris": {
"media": "/2010-04-01/Accounts/{organization_id}/Messages/40317159-f30d-4940-b751-9a6e81727249/Media.json"
}
}

Note: After pasting the above content, Kindly check and remove any new line added

On this page