Send sms POST

Post Reply
User avatar
MarcoBoschi
Posts: 1070
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Send sms POST

Post by MarcoBoschi »

Hi to all!
I have to send sms from my application in this way Using Rest Api of our provider.

Using this command from ubuntu (in my windows10) it works fine


curl --location 'https://app.xxxxxxx.it/API/v1.0/REST/sms' \
--header 'user_key: 9999999' \
--header 'Access_token: TOKENALFANUMERICO' \
--header 'Content-Type: application/json' \
--data '{
"recipient": [
"+393123456789"
],
"message": "Ths is a Test",
"sender": "MarcoBoschi",
"message_type": "n"
}'

How can I launch this command from a fivewin program?

Many Thanks to all
Marco
Marco Boschi
info@marcoboschi.it
User avatar
cmsoft
Posts: 1293
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Send sms POST

Post by cmsoft »

Hola Marco
Tal vez esto te pueda dar una luz
Yo lo uso para consumir una api

Code: Select all | Expand

#include "Fivewin.ch"
static oOle
FUNCTION Main()
LOCAL aData, cJson, cContentType, aResp, aAuthorization, aRecipient := {}

Try
    //oOle := CreateObject( 'MSXML2.XMLHTTP' )
    oOle := Createobject("MSXML2.ServerXMLHTTP")
Catch
    oOle := CreateObject( 'Microsoft.XMLHTTP' )
End
aData  := hash() 
AADD(aRecipient,'+393123456789')
aData["recipient"] = aRecipient
aData["message"] = "Ths is a Test"
aData["sender"] = "MarcoBoschi"
aData["message_type"] = "n"

aAuthorization := {{"user_key","9999999"},{"Access_token","TOKENALFANUMERICO"}}

cJson := hb_jsonEncode(aData,.f.)

cContentType:="application/json"
aResp := SendPostToUrl( "https://app.xxxxxxx.it/API/v1.0/REST/sms", cJson, cContentType, aAuthorization  )    
if valtype(aResp) == 'C'
   MsgInfo(aResp)
   Else    
   xbrowse(aResp) // Ver respuesta
endif   
Return NIL    

STATIC Function SendPostToUrl( cUrl, cParams,cContentType,aAuthorization )
    Local cRet:='',uRet, i, oError
    default cContentType:="application/json"
    default aAuthorization:={}
    
    oOle:Open( 'POST', cUrl, .f. )
       
    if !empty(aAuthorization)
       for i := 1 TO len(aAuthorization)
           oOle:SetRequestHeader( aAuthorization[i,1],aAuthorization[i,2])
       next i 
    endif    
    oOle:SetRequestHeader( "Content-Type",cContentType)
    try
        oOle:Send( cParams )

    Catch oError
        MsgInfo(oError:description)
        return "Error"
    end try    
   
    cRet:=""
    IF !oOle:ResponseBody = NIL 
       hb_jsonDecode(oOle:ResponseBody,@cRet)        
       ELSE
       cRet := oOle:ResponseText
    ENDIF
Return cRet
 
User avatar
MarcoBoschi
Posts: 1070
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Re: Send sms POST

Post by MarcoBoschi »

ON THE FIRST SHOT!

THANKYOUVERYMUCH

marco
Marco Boschi
info@marcoboschi.it
User avatar
cmsoft
Posts: 1293
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Send sms POST

Post by cmsoft »

Excelente Marco!
Me alegro haya sido de utilidad!
User avatar
MarcoBoschi
Posts: 1070
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Re: Send sms POST

Post by MarcoBoschi »

8)
Marco Boschi
info@marcoboschi.it
Post Reply