SMS REST API python xojo cloud

I have found a pretty cheap sms services but i have problem as it does not provide a xojo code.
The company is there and the relevant code in rubby/php/python etc…
https://gatewayapi.com/

Is anybody can spend some time to write the little code for calling the api in xojo code?
I use xojo cloud and don’t know if it supports running python scripts and how…
I put there the corresponding python code for convenience

[code]# Install deps with: pip install requests_oauthlib

If you are not running python 3:

from future import print_function
from requests_oauthlib import OAuth1Session
key = ‘OCBPsIM96YxMYbtF5NExSEje’
secret = ‘kbeicziA(UM6HLbJIcbfPpdQF3pEHm)Pr%eKVmmN’
gwapi = OAuth1Session(key, client_secret=secret)
req = {
‘sender’: ‘ExampleSMS’,
‘message’: ‘Hello World’,
‘recipients’: [{‘msisdn’: 4512345678}],
}
res = gwapi.post(‘https://gatewayapi.com/rest/mtsms’, json=req)
res.raise_for_status()
print(res.json())[/code]

You will need to do some Oauth authentication via Chilkat or MBS Curl plugin. Both plugins have examples to get you started.

Have you tried running the python script using a Shell object?

Check out the post example for urlconnection (Xojo : Examples->Communication->Internet->URLConnection)

This works for me:

[code]Public Function GenerateContent() as String
Dim json As String

// Create JSON Objects
Dim content As New JSONItem
Dim recipients As New JSONItem
Dim rcp As New JSONItem

content.Value(“message”) = “Hello World!”
content.Value(“sender”) = “MyName” // max 11 chars

rcp.Value(“msisdn”) = “41761105000”
recipients.Append rcp

rcp = New JSONItem
rcp.Value(“msisdn”) = “41761104000”
recipients.Append rcp

// continue to add recipients
’ rcp = New JSONItem
’ rcp.Value(“msisdn”) = “41762103000”
’ recipients.Append rcp

// Assign recipients list to contents JSON object
content.Value(“recipients”) = recipients

// Convert Dictionary to JSON Text
json = content.ToString

Return json
End Function
[/code]

And the actual send code:

[code]Sub Action() Handles Action
// Set content type
WebConnection.RequestHeader(“Content-Type”) = “application/json; charset=utf-8”

// Set content
WebConnection.SetRequestContent(Self.GenerateContent,“application/json”)

// Get your token from gatewayapi.com
Dim myToken As String = “To1bmQOzSCiXaWv8SkzeVySYonImJKQg7gK0IkX3ll-xxxxxxxxxxxxxx”

Dim URL As String = "https://gatewayapi.com/rest/mtsms?" _

  • “token=” + myToken

// Send Asynchronous Request
WebConnection.Send(“POST”,url)
End Sub
[/code]

Download sample project here:
https://nws-informatik.ch/download/gatewayapi.xojo_binary_project.zip

I updated the sample project, there was some left over obsolete code which raised errors…
https://nws-informatik.ch/download/gatewayapi.xojo_binary_project.zip

Thanks you all, I have chilkat library and I will try the solutions either by running a python script using the "Shell"command and Oliver’s code.

Oliver, is your code working without modifications in xojo webapp or what can I change?

Greg I use Xojo Cloud. Can you please I give me an example, can’t find any relevant to the documentation… In which directory have to put the script or can I assign all the code to a variable using line.append?

Appreciate for the quick response!

[quote=426410:@Michael Batakis]Thanks you all, I have chilkat library and I will try the solutions either by running a python script using the "Shell"command and Oliver’s code.

Oliver, is your code working without modifications in xojo webapp or what can I change?

Greg I use Xojo Cloud. Can you please I give me an example, can’t find any relevant to the documentation… In which directory have to put the script or can I assign all the code to a variable using line.append?

Appreciate for the quick response![/quote]
You are aware that the example I gave is running with native Xojo code? No need for plugins or python …

[quote=426410:@Michael Batakis]…
Oliver, is your code working without modifications in xojo webapp or what can I change?
…[/quote]

I have not used the new URLConnection class from a webapp yet, but I’d say: YES, works without modification.
https://docs.xojo.com/URLConnection

URLconnection is much simpler to use and to implement than Xojo.net.HTTPSocket, but it still suffers from some technical teething issues on Windows. I think this will disappear soon.

EDIT: I just tested my code with a webproject on Windows and it sends out successfully some sms to the iPhone of my Lady … she ‘loves’ it :slight_smile:

that is an understatement. I am hoping for good things in 2019R1 (and no I am not broadcasting hints from the betas… I promise!)

I use Xojo 2018.3. Does it work? When try to run I got the error but can’t find such an object/declaration

"Window1.WebConnection.ContentReceived Declaration
WebConnection on Window1 implements the event “ContentReceived,” but its superclass URLConnection has already

URLConnection is new in Xojo 2018r4. If I see this right, the REST API of gatewayapi.com requires HTTP 1.1, so you would have to rewrite my example and use Xojo.Net.HTTPSocket instead of URLConnection… or update to the latest Xojo version.

You can do the same thing with Xojo.Net.HTTPSocket - but it belongs to the ‘new’ framework which soon will be deprecated. URLConnection is what will be used from now on.

But if you need a solution now, which works with your version of Xojo, you will have to do some reading on how to use the Xojo.Net.HTTPSocket class.

Some links here:
https://forum.xojo.com/51780-api-balance-of-eth-accounts/p1#p419332

@Michael Batakis : I quickly put together two example projects with Xojo 2018r3 and using Xojo.Net.HTTPSocket, instead of URLConnection.

One desktop project and one Webproject. Let me know if you encounter any problems. Download from here:
http://nws-informatik.ch/download/sms_xojo_2018.zip

Deprecated <> Removed. Please feel free to use Xojo.Net.HTTPSocket in your projects if you want.