locked
Sending SMS via Nexmo RRS feed

  • Question

  • Hello all
    I am sending sms from vfp using nexmo and getting error 'Bad Credentials' 

    code is :
    uname='my nexmo username which is email id'
    pwd='my nexmo key'
    From='mycompany' 
    to = '91+mymobilenumber' 
    lcsmstext='This is test message'
    sendsms = Textmerge("http://rest.nexmo.com/sms/xml?username=<< m.uname >>|password=<< m.pwd >>|from=<< m.from >>|to=<< m.to >>|text=<< m.lcsmstext >>")
    sendsms = Chrtran(sendsms, '|', Chr(38))

    Local loXmlHttp As "Microsoft.XMLHTTP"
    loXmlHttp = Newobject( "Microsoft.XMLHTTP" )

    loXmlHttp.Open( "POST" , m.sendsms, .F. )

    loXmlHttp.Send( )

    If loXmlHttp.Status = 200
    lcXML = StrExtract(loXmlHttp.responsetext,'<messages','</messages>',1,1+4)
    XMLToCursor(m.lcXML,'smsresult')
    Else
    MessageBox( Textmerge( "An error occurred. Status <<loXmlHttp.STATUS>> (<<loXmlHttp.statustext>>)." ) )
    Endif


    With Regards.
    Tariq Iftikhar 


    Thursday, March 12, 2015 5:22 PM

Answers

  • POST binary:

    loXmlHttp.Open( "POST" , CREATEBINARY(m.sendsms), .F. )

    On top of that your encoding might need to be UTF-8, not ANSI, so you would need to first convert the whole string via STRCONV. Refer to documentation, what encoding is needed.

    PS: Here, I read the manual to you:

    https://docs.nexmo.com/index.php/sms-api/send-message

    "All requests are submitted through the HTTP POST or GET method using UTF-8 encoding and URL encoded values"

    And if you POST, there are some more things said there:

    Expected "Content-Type" for POST is "application/x-www-form-urlencoded"

    You didn't specify a Centent-Type header.

    In general, to make a post request, parameters mustn't be embedded within the URL, they must be put into a POST body and you don't do that. Rather use GET, as the API also allows that.

    Bye, Olaf.


    Olaf Doschke - TMN Systemberatung GmbH

    http://www.tmn-systemberatung.de

    Friday, March 13, 2015 6:53 AM
  • Thanks. Olaf

    changing uname = 'my nexmo key'

    pwd = 'my nexmo secret'

    solved and working.

    Regards.

    Tariq Iftikhar

    Saturday, March 14, 2015 5:59 AM

All replies

  • POST binary:

    loXmlHttp.Open( "POST" , CREATEBINARY(m.sendsms), .F. )

    On top of that your encoding might need to be UTF-8, not ANSI, so you would need to first convert the whole string via STRCONV. Refer to documentation, what encoding is needed.

    PS: Here, I read the manual to you:

    https://docs.nexmo.com/index.php/sms-api/send-message

    "All requests are submitted through the HTTP POST or GET method using UTF-8 encoding and URL encoded values"

    And if you POST, there are some more things said there:

    Expected "Content-Type" for POST is "application/x-www-form-urlencoded"

    You didn't specify a Centent-Type header.

    In general, to make a post request, parameters mustn't be embedded within the URL, they must be put into a POST body and you don't do that. Rather use GET, as the API also allows that.

    Bye, Olaf.


    Olaf Doschke - TMN Systemberatung GmbH

    http://www.tmn-systemberatung.de

    Friday, March 13, 2015 6:53 AM
  • Thanks. Olaf

    changing uname = 'my nexmo key'

    pwd = 'my nexmo secret'

    solved and working.

    Regards.

    Tariq Iftikhar

    Saturday, March 14, 2015 5:59 AM
  • Dear Tariq,

    I am from India and have never used API messaging.

    I want to know :

    * from how long time you are using sending SMS via Nexmo ?
    * can the messages be send to DND No. also ?
    * How can I manage using this with my clients ?
    * what does the company provide - API or only UserName/Password ?

    Thanks.

    Saturday, March 14, 2015 6:38 AM
  • That's obvious you need to add your user/password.

    You also will need to address the encoding. The subset of latin letters, numbers and several punctuation matches with UTF-8, but already using some accents and ligatures you'll get quirky SMS messages appearing at your clients devices. Send a test message containing äößáéúíàèìòù for example.

    Bye, Olaf.


    Olaf Doschke - TMN Systemberatung GmbH http://www.tmn-systemberatung.de

    Saturday, March 14, 2015 7:45 AM
  • Hello Ankit,

    Certainly there are limitations using Nexmo. I can send sms from 9am to 9pm only. Message can not be send to DND numbers. If there is any alternate method, kindly suggest me.

    Regards.

    Tariq Iftikhar

    Monday, March 16, 2015 5:57 PM