Skip to content

Instantly share code, notes, and snippets.

@jongan69
Created May 11, 2025 19:08
Show Gist options
  • Save jongan69/c29e8bd4e60e95368e8f9c95c91fa4d5 to your computer and use it in GitHub Desktop.
Save jongan69/c29e8bd4e60e95368e8f9c95c91fa4d5 to your computer and use it in GitHub Desktop.
Using Surge API for sending text messages in python
import requests
import json
import os
import dotenv
dotenv.load_dotenv()
# Surge API endpoint
url = "https://api.surge.app/messages"
# API credentials and headers
def get_surge_headers():
return {
"Authorization": f"Bearer {os.getenv('SURGE_API_KEY')}",
"Surge-Account": os.getenv('SURGE_ACCOUNT'),
"Content-Type": "application/json"
}
def send_surge_message(body, phone_number):
"""
Sends a message using the Surge API.
Args:
body (str): The message body to send.
phone_number (str): The recipient's phone number.
Returns:
Response object from requests.post
"""
payload = {
"body": body,
"conversation": {
"contact": {
"phone_number": phone_number
}
}
}
headers = get_surge_headers()
response = requests.post(url, headers=headers, data=json.dumps(payload))
return response
if __name__ == "__main__":
# Example usage
body = "HELLO!"
phone_number = os.getenv('PHONE_NUMBER')
response = send_surge_message(body, phone_number)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment