thatwayeasy33
thatwayeasy33

Reputation: 41

How to Send a URL Link within the Text Body with the Twilio API using Python

I am trying to send a text message that contains both text and a hypeprlink but am encountering the following message from the Twilio API: "Error - 12300 Invalid Content-Type: Attempt to retrieve MediaUrl returned an unsupported Content-Type."

Here is the code I am attempting to leverage:

import os
from twilio.rest import Client


# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']

client = Client(account_sid, auth_token)
message = client.messages \
        .create(
            body='Article: https://4r7s.short.gy/GPaoh7',
            from_='123-345-5667',
            to='123-345-5668',
        )

When I send a message without a hyperlink it works fine (e.g. body = 'Here is the article for you to read') but when it contains a link I receive the aforementioned error. I've also tried using a shortened url of the above but that causes the same issue.

Upvotes: 1

Views: 547

Answers (1)

philnash
philnash

Reputation: 73055

I was just able to send messages containing that exact link using my own Twilio account.

There might be an issue in that you are using phone numbers in local format, when they should be provided in e.164 format.

It's possible that your message is being blocked. Certain carriers don't like when you use link shorteners to obscure a link.

The error you are getting definitely seems weird, since you are not sending media. If you continue to have issues with this, I would contact Twilio support.

Upvotes: 2

Related Questions