Exemple API SMS Python


# -*- coding: utf-8 -*-
from urllib import request
import json

token = 'Your token' #Your first token must be generated on our plateform at https://app.smsup.ch/developers/api-tokens
content = 'Test API python' 
numbers = ['33601020304', '41781234567']
recipients = [];
for number in numbers:
  recipients.append({'value': number})

data = {
  'sms': {
    'message': {
      'text': content
    },
    'recipients': {
      'gsm': recipients
    }
  }
}

data = json.dumps(data).encode('utf-8')

req = request.Request('https://api.smsup.ch/send', data)
req.add_header('Accept', 'application/json')
req.add_header('Authorization', "Bearer %s" % token)

with request.urlopen(req, data) as f:
  print(f.read().decode('utf-8'))