Android Question How Send SMS verification using telesign API

DonManfred

Expert
Licensed User
Longtime User
I want to do it as in this
They do provide a REST Api. Just use it.

 
Upvote 0

alfaiz678

Active Member
Licensed User
Where is the project upload showing the problem?
WHAT does not work? WHAT is the error you get?

B4X:
    curl -X POST https://rest-api.telesign.com/v1/messaging \
    -d phone_number=XXXXXXXX \
    -d message="Your code is {insert code}." \
    -d message_type="OTP" \
    -u "CUSTOMER_ID":"API_KEY"

B4X:
Dim h_Spot_Token As HttpJob
    h_Spot_Token.Initialize("",Me)
    h_Spot_Token.PostString("https://rest-api.telesign.com/v1/messaging","phone_number="& phone_number _
     &"&message=11&message_type=OTP&" & CUSTOMER_ID & ":" & API_KEY  )
    h_Spot_Token.GetRequest.SetHeader("Content-Type", "application/json")

    Wait For (h_Spot_Token) JobDone(h_Spot_Token As HttpJob)
    If h_Spot_Token.Success = True Then
        Log(h_Spot_Token.GetString)
    Else
        Log(h_Spot_Token.ErrorMessage)
    End If

B4X:
ResponseError. Reason: Unauthorized, Response: {"reference_id": null, "external_id": null, "status": {"updated_on": "2020-10-11T11:38:18.521984Z", "code": 10009, "description": "Missing required 'Authorization' header"}}
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
1. Poststring is wrong. You probably need to use PostMultipart.
2. You are not setting a User
B4X:
h_Spot_Token.Username = $"CUSTOMER_ID:API_KEY"$
3. Setting the ContentType Header is wrong;
B4X:
h_Spot_Token.GetRequest.SetContentType("application/json")


Try it with
B4X:
    Dim m As Map = CreateMap("phone_number": 1, "message": 11,"message_type":"OTP")
    Dim h_Spot_Token As HttpJob
    h_Spot_Token.Initialize("",Me)
    h_Spot_Token.Username = $"CUSTOMER_ID:API_KEY"$
    h_Spot_Token.PostMultipart("https://rest-api.telesign.com/v1/messaging",m,Null)
    h_Spot_Token.GetRequest.SetContentType("application/json")

    Wait For (h_Spot_Token) JobDone(h_Spot_Token As HttpJob)
    If h_Spot_Token.Success = True Then
        Log(h_Spot_Token.GetString)
    Else
        Log(h_Spot_Token.ErrorMessage)
    End If
   h_Spot_Token.Release

Good luck; Expect this my last anser.
 
Upvote 0
Top