João serras-pereira
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:
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?
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
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?
ASKER
Yeap. It looks so
The final answer from Nexmo is, unfortunately, disappointing.
Quoting
In order to invoke my function, the code is:
(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?
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.This means that they are convicted that the problema is exclusively on my side.
Kindly let me know if you still having this issue, and I am happy to assist you further.
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
(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?
ASKER
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:
the accented characters are destroyed.
If I invoke the webbrowser control using:
will get the same
if I use Edge (directly) with the last sentence: it works OK
can anyone help?
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?
ASKER
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
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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?