Ignition Edge and Twilio

I'm using Ignition edge, has anyone successfully sent text messages using "system.net.httpPost"

Crickets??

The silence could mean that nobody has tried to manually interact with Twilio via system.net.http* methods.

I haven't interacted with Twilio using system.net.http* methods but I do use Twilio in one of my projects.

FWIW it should definitely work. Twilio offers an API specifically for this.

I know this is not Jython, but asking the AI assistant on the Twilio website yields the following result in python:

import requests
from requests.auth import HTTPBasicAuth

# Your Account SID and Auth Token
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# The URL for the Twilio API endpoint
url = 'https://api.twilio.com/2010-04-01/Accounts/{}/Messages.json'.format(account_sid)

# The data payload for the request
data = {
    'From': '+15017250604',  # Twilio phone number
    'To': '+15558675309',    # Destination phone number
    'Body': 'Hello, this is a test message!'
}

# Make the POST request
response = requests.post(url, data=data, auth=HTTPBasicAuth(account_sid, auth_token))

# Check the response
print(response.status_code)
print(response.json())

You'd just have to replace the requests.post part with system.net.httpPost (although @PGriffith might recommend using system.net.httpClient then use the post method from what I've read recently) and format your payload accordingly (probably the HTTPBasicAuth part too, you'll have to experiment).

Some more related documentation here:

2 Likes

system.net.httpClient is a near drop in replacement for requests; the API was pretty directly inspired by it:

# Your Account SID and Auth Token
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# The URL for the Twilio API endpoint
url = 'https://api.twilio.com/2010-04-01/Accounts/{}/Messages.json'.format(account_sid)

# The data payload for the request
data = {
    'From': '+15017250604',  # Twilio phone number
    'To': '+15558675309',    # Destination phone number
    'Body': 'Hello, this is a test message!'
}

# Make the POST request
client = system.net.httpClient()
response = client.post(url, data=data, username=account_sid, password=auth_token)

# Check the response
print response.statusCode
print response.json
2 Likes

I think my issue may be related to government regulations. I found somewhere that 1 Jan 2024 a 'requirement' to have the sending number verified as toll free. I am pretty sure that includes the one issued by Twilio. (correct me if I'm wrong) I've tried that httpClient() method six ways to Sunday and keep getting the same "https://www.twilio.com/docs/errors/21604". I realize this says the "To" number is missing but all evidence to the contrary. Printing the 'data' shows correctly formatted "To" number. So my struggle continues.

The responses are much appreciated. I'll post if and when I find my problem.

Have you been able to successfully get your account verified since their new verification? I am having a nightmare time getting any support to even get an account verified to even try sending a test message.