Skip to content

Instantly share code, notes, and snippets.

@yuta-imai
Created May 14, 2020 12:26
Show Gist options
  • Save yuta-imai/50941a7539c51443f1b4f05a87c6a59b to your computer and use it in GitHub Desktop.
Save yuta-imai/50941a7539c51443f1b4f05a87c6a59b to your computer and use it in GitHub Desktop.
import json
import urllib3
api = 'https://api.soracom.io/v1'
auth_key_id = "keyId-xxxxxxx"
auth_key = "secret-xxxxxxxx"
target_imsi = '111111111111111'
http = urllib3.PoolManager()
auth_result = http.request(
'POST',
api + '/auth',
body = json.dumps({'authKeyId':auth_key_id, 'authKey':auth_key}),
headers={'Content-Type': 'application/json'}
)
credential =json.loads(auth_result.data.decode('utf-8'))
print(credential)
sms_send_result = http.request(
'POST',
api + '/subscribers/{}/send_sms'.format(target_imsi),
body = json.dumps({'encodingType':2, 'payload':'Hello World.'}),
headers={
'Content-Type': 'application/json',
'x-soracom-api-key': credential['apiKey'],
'x-soracom-token': credential['token']
}
)
print(json.loads(sms_send_result.data.decode('utf-8')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment