Sample code for 30+ languages & platforms
Xbase++

WaTrend Send WhatsApp Text

See more WaTrend Examples

Send a WhatsApp text.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL oReq
LOCAL oSbUrl
LOCAL cResponseBodyStr
LOCAL oResp
LOCAL oSbResponseBody
LOCAL nRespStatusCode
LOCAL oJResp
LOCAL cStatus

nSuccess := 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oHttp := CreateObject("Chilkat.Http")

//  Use your actual access token instead of 555555555555555555555555555555
oReq := CreateObject("Chilkat.HttpRequest")
oReq:AddParam("number", "84933313xxx")
oReq:AddParam("type", "text")
oReq:AddParam("message", "This is a test message")
oReq:AddParam("instance_id", "609ACF283XXXX")
oReq:AddParam("access_token", "555555555555555555555555555555")

//  Note: The WaTrend online documentation indicate a POST should be used.
//  However, it seems you might actually need to send a GET request.
//  It is unclear.  
//  If a GET is neeed, you would just send to the URL w/ query params like this:
oSbUrl := CreateObject("Chilkat.StringBuilder")
oSbUrl:Append("https://app.watrend.com/api/send.php?")
oSbUrl:Append(oReq:GetUrlEncodedParams())
cResponseBodyStr := oHttp:QuickGetStr(oSbUrl:GetAsString())
//  The responseBodyStr contains the JSON response from the server..

oReq:HttpVerb := "POST"
oReq:ContentType := "application/x-www-form-urlencoded"

oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpReq("https://app.watrend.com/api/send.php", oReq, oResp)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    oReq:destroy()
    oSbUrl:destroy()
    oResp:destroy()
    RETURN
ENDIF

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)

nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
    ? "Response Header:"
    ? oResp:Header
    ? "Failed."
    oHttp:destroy()
    oReq:destroy()
    oSbUrl:destroy()
    oResp:destroy()
    oSbResponseBody:destroy()
    RETURN
ENDIF

? oResp:BodyStr

//  Both success and failed responses use 200 status code.

//  A success response contains this JSON in the response body:
//  {"status":"success", ... }

//  A failed response will contain something like this:
//  {"status":"error","message":"License Invalidated"}

oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)

cStatus := oJResp:StringOf("status")
? "status: " + cStatus

oHttp:destroy()
oReq:destroy()
oSbUrl:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()