Link to home
Start Free TrialLog in
Avatar of João serras-pereira
João serras-pereiraFlag for Portugal

asked on

character set on REST interface

Hi.
This Question is a follow-up of a previous question with the title "web browser for the REST interface" (previously we could issue follow-up questions, but now I can't find how to do it).

It was sorted and it works (almost) perfectly, using Jim's approach.
 
Now, my code is:

Public Function sendSMS(strApiKey As String, strApiSecret As String, strTarget As String, strText As String) As String

    
    strFrom = "myFib"

    Dim strPostURL As String
    Dim arrResponse
    Dim objRequest As New MSXML2.XMLHTTP
    Dim strAnswer As String
    
    strPostURL = "https://rest.nexmo.com/sms/json"
    strPostURL = strPostURL & "?api_key="
    strPostURL = strPostURL & strApiKey
    strPostURL = strPostURL & "&api_secret=" & strApiSecret
    strPostURL = strPostURL & "&from=" & "myFM"
    strPostURL = strPostURL & "&type=unicode"
    strPostURL = strPostURL & "&to=" & strTarget
    strPostURL = strPostURL & "&text=" & strText
    
    MsgBox strPostURL
    

    On Error GoTo Error_Handler

    ' Default to false in case anything goes wrong.
    sendSMS = ""
    
    ' We use xmlHTTP to submit the input values and record the response
    
    objRequest.Open "POST", strPostURL, False
    objRequest.Send
   
    arrResponse = objRequest.responseText
    sendSMS = arrResponse
    Exit Function

Exit_Handler:
    On Error Resume Next
    Set objRequest = Nothing
    Exit Function

Error_Handler:
      MsgBox Err.Description, _
        "ERROR " & Err.Number

    Resume Exit_Handler

End Function

Open in new window



The problem is that it does not accept accented characters (or Unicode)
.
As per NEXMO's support, I quote:
I've done a further check and I noticed the message seems garbled before reaching Nexmo. I'm wondering if this is something related to your system environment, as I've performed a test with our test numbers and it is working fine.

Could you try a simple debug by using a different tool(maybe POSTMAN or just simply a curl command) to re-send the SMS request again and observe the result?


Can anyone help me?
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

based on the documentation from Nexmo:

https://developer.nexmo.com/api/sms

the configuration in your codes look correct.

So, the next question is how you call that function: sendSMS which eventually trigger the request to the SMS gateway? You call that function in VBA environment?

have you also tried in Postman? Did you manage to pass through with unicode chars?
Avatar of João serras-pereira

ASKER

Yeap. It looks so

The final answer from Nexmo is, unfortunately, disappointing.

Quoting
Basically, just to build the API request in a HTTP format, and paste it in your internet browser and you should be able to archive the same as you do it in other application, and I believe the garbled message issue should be resolved.

Kindly let me know if you still having this issue, and I am happy to assist you further.
This means that they are convicted that the problema is exclusively on my side.

In order to invoke my function, the code is:


Private Sub btnEnviarSMS_Click()

    Dim strResult As String
    Dim strApiKey As String
    Dim strApiSecret As String
    Dim strTarget As String
    Dim strText As String


    strApiKey = "999999"
    strApiSecret = "9999999"
    strText = fldText
    strTarget = "+351910709936"
    
    strResult = sendSMS(strApiKey, strApiSecret, strTarget, strText)
    fldOutput = strResult

End Sub


Open in new window


(just replace the actual keys)

Now I am stuck

I have tested  the following command on Terminal (I am using OSX and Parallels) and it works fine:

curl -X "POST" "https://rest.nexmo.com/sms/json" \  
 -d "from=AcmeInc" \
 -d "text=A text message sent using the Nexmo SMS API" \
 -d "to=$TO_NUMBER" \
 -d "api_key=$NEXMO_API_KEY" \
 -d "api_secret=$NEXMO_API_SECRET"

So, in the limit, perhaps I could invoke that from within ms/access (although I do not know how) - but then how to get the output in my app?

Next, there is the option that Jim Dettman posted: use https://github.com/VBA-tools/VBA-Web 

So I have downloaded it, as it looks that Nexmo uses JSON. Actually, you may see it on the first curl line:
curl -X "POST" "https://rest.nexmo.com/sms/json" \  

But this looks rather complicated for me without a bit of coaching.

Can you help?

Hi -
I have progressed a bit and tested the cURL - the syntax is now Ok.
But I am experiencing the same character set problems.

If I type, on windows command:

curl -X POST  https://rest.nexmo.com/sms/json -d api_key=8e90e252 -d api_secret=XXXXXX -d to=351910709936 -d from="myFM" -d text="accented characters íãéó" -d type=unicode

the accented characters are destroyed.

If I invoke the webbrowser control using:

https://rest.nexmo.com/sms/json?api_key=8e90e252&api_secret=XXXXXX&from=myFM&to=351910709936&text=testing send accented characters: [áàãóõíìúñ]&type=unicode

will get the same

if I use Edge (directly) with the last sentence: it works OK


can anyone help?


use Powershell:

[console]::OutputEncoding = [text.encoding]::UTF8
$Uri = 'https://rest.nexmo.com/sms/json'
$contentType='application/x-www-form-urlencoded'
$body = @{
api_key = 'NEXMO_API_KEY'
api_secret = 'NEXMO_API_SECRET'
to = 'TO_NUMBER'
from = 'FROM_NUMBER'
type = 'unicode'
text = 'hello from vonage 😂😂'
}
Invoke-WebRequest -Method POST -uri $uri -body $body -ContentType $contentType

Open in new window


ASKER CERTIFIED SOLUTION
Avatar of João serras-pereira
João serras-pereira
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial