Lenguaje "Python"
Enviar mensajes – REST API – JSON
[python]
import requests, base64
usrPass = "myusername:mypassword"
b64Val = base64.b64encode(usrPass)
url = "https://api.labsmobile.com/json/send"
payload = "{\"message\":\"Text of the SMS message\", \"tpoa\":\"Sender\",\"recipient\":[{\"msisdn\":\"12015550123\"},{\"msisdn\":\"447400123456\"},{\"msisdn\":\"5212221234567\"}]}"
headers = {
'Content-Type': "application/json",
'Authorization': "Basic %s" % b64Val,
'Cache-Control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
[/python]Consulta de créditos – REST API – JSON
[python]
import requests, base64
usrPass = "myusername:mypassword"
b64Val = base64.b64encode(usrPass)
url = "https://api.labsmobile.com/json/balance"
headers = {
'Authorization': "Basic %s" % b64Val,
'Cache-Control': "no-cache"
}
response = requests.request("GET", url, headers=headers)
print(response.text)
[/python]Enviar mensajes – HTTP/GET
[python]
Python 2.x:
import urllib2
print urllib2.urlopen("http://api.labsmobile.com/get/send.php?username=[X]&password=[X]&msisdn=34609036253&sender=SENDER&message=This+is+the+message").read()
---------
Python 3.x:
import urllib.request
print urllib.request.urlopen("http://api.labsmobile.com/get/send.php?username=[X]&password=[X]&msisdn=34609036253&sender=SENDER&message=This+is+the+message").read()
---------
import requests
r = requests.get("http://api.labsmobile.com/get/send.php?username=[X]&password=[X]&msisdn=34609036253&sender=SENDER&message=This+is+the+message")
[/python]Consulta de créditos – HTTP/GET
[python]
Python 2.x:
import urllib2
print urllib2.urlopen("http://api.labsmobile.com/get/balance.php?username=[X]&password=[X]").read()
---------
Python 3.x:
import urllib.request
print urllib.request.urlopen("http://api.labsmobile.com/get/balance.php?username=[X]&password=[X]").read()
---------
import requests
r = requests.get("http://api.labsmobile.com/get/balance.php?username=[X]&password=[X]")
[/python]