1
votes

i have to send a message to a device using pushwoosh api. Im sending it from vb.net and i have a premium account. The code works fine, but i getting a code 400 in return from the server. Any ideas?

My json request looks like this:

{   
    'request':
    {
'application':'xxxxx-xxxxx',                 
    'auth':'xxxxx',
        'notifications':[{
             'send_date':'now',     
             'ignore_user_timezone': true,     
             'content':'Hallo world'   
             }]
     }
}

VB.net code:

The call:

dim JsonSring = "{'request':{'application':'My app id','auth':'the api key','notifications':[ { 'send_date':'now', 'ignore_user_timezone': true, 'content':'Hallo world' } ]}}"

Dim myUri As New Uri("https://cp.pushwoosh.com/json/1.3/")

Dim data = Encoding.UTF8.GetBytes(jsonSring)

Dim result_post = MyFunctions.SendRequest(myUri, data, "application/json", "POST")

The function:

Public Shared Function SendRequest(uri As Uri, jsonDataBytes As Byte(), contentType As String, method As String) As String

    Dim req As WebRequest = WebRequest.Create(uri)

    req.ContentType = contentType

    req.Method = method

    req.ContentLength = jsonDataBytes.Length



    Dim stream = req.GetRequestStream()
    stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
    stream.Close()

    Dim response = req.GetResponse().GetResponseStream()

    Dim reader As New StreamReader(response)
    Dim res = reader.ReadToEnd()
    reader.Close()
    response.Close()

    Return res
End Function
1

1 Answers

1
votes

Your URL seems to be incomplete. Could it be the case?

Dim myUri As New Uri("https://cp.pushwoosh.com/json/1.3/")

It should be either https://cp.pushwoosh.com/json/1.3/createMessage, or https://cp.pushwoosh.com/json/1.3/registerDevice, etc.