Send sms POST

Send sms POST

Postby MarcoBoschi » Thu Apr 06, 2023 2:40 pm

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
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Send sms POST

Postby cmsoft » Thu Apr 06, 2023 3:33 pm

Hola Marco
Tal vez esto te pueda dar una luz
Yo lo uso para consumir una api
Code: Select all  Expand view

#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
cmsoft
 
Posts: 1289
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Send sms POST

Postby MarcoBoschi » Thu Apr 06, 2023 3:47 pm

ON THE FIRST SHOT!

THANKYOUVERYMUCH

marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Send sms POST

Postby cmsoft » Thu Apr 06, 2023 6:40 pm

Excelente Marco!
Me alegro haya sido de utilidad!
User avatar
cmsoft
 
Posts: 1289
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Send sms POST

Postby MarcoBoschi » Fri Apr 07, 2023 12:44 pm

8)
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 61 guests