SMS REST API python xojo cloud

  1. last year
    Edited last year

    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

    # 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())
  2. Beatrix W

    27 Feb 2019 Testers, Third Party Store Europe (Germany)

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

  3. Greg O

    27 Feb 2019 Xojo Inc scout.galaxy.barn

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

  4. Oliver O

    27 Feb 2019 Testers, Xojo Pro https://udemy.seminar.pro

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

    This works for me:

    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

    And the actual send 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

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

  5. Oliver O

    27 Feb 2019 Testers, Xojo Pro https://udemy.seminar.pro

    -image-

  6. Oliver O

    27 Feb 2019 Testers, Xojo Pro https://udemy.seminar.pro

    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

  7. Edited last year

    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!

  8. Oliver O

    27 Feb 2019 Testers, Xojo Pro https://udemy.seminar.pro

    @Michael B 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!

    You are aware that the example I gave is running with native Xojo code? No need for plugins or python ...

  9. Oliver O

    27 Feb 2019 Testers, Xojo Pro https://udemy.seminar.pro
    Edited last year

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

    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 :)

  10. scott b

    27 Feb 2019 Testers, Xojo Pro local coffee shop

    @Oliver O but it still suffers from some technical teething issues on Windows

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

  11. 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

  12. Oliver O

    27 Feb 2019 Testers, Xojo Pro https://udemy.seminar.pro

    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.

  13. Oliver O

    27 Feb 2019 Testers, Xojo Pro https://udemy.seminar.pro

    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

  14. Oliver O

    28 Feb 2019 Testers, Xojo Pro https://udemy.seminar.pro

    @Michael B : 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

  15. Greg O

    28 Feb 2019 Xojo Inc scout.galaxy.barn

    @Oliver O 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.

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

or Sign Up to reply!