Order Payment API - Yahoo Store


I am trying to call Yahoo Order Payment API - GetOrder function and am getting "Bad Request - 400" error on:
response = DirectCast(request.GetResponse(), HttpWebResponse)

I couldn't find any sample code for VB.NET that would let me see if I am calling this correctly or not. Here is my code:
Public Sub ReadYahooOrders()
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
Dim address As Uri
Dim appId As String
Dim context As String
Dim query As String
Dim data As StringBuilder
Dim byteData() As Byte
Dim postStream As Stream = Nothing

address = New Uri("https://mystore.order.store.yahooapis.com/V1/order")
Dim mypostData As String = "<?xml version=""1.0"" encoding=""utf-8""?>"
mypostData &= "<ystorewsRequest><StoreID> myStoreID </StoreID>"
mypostData &= "<SecurityHeader><PartnerStoreContractToken> myToken </PartnerStoreContractToken>"
mypostData &= "</SecurityHeader>"
mypostData &= "<Version> 1.0 </Version>"
mypostData &= "<ResourceList><OrderListQuery>"
mypostData &= "<Filter><Include> buyeremail </Include></Filter>"
mypostData &= "<QueryParams><IntervalRange><Start> 20931 </Start><End> 20950 </End></IntervalRange></QueryParams>"
mypostData &= "</OrderListQuery></ResourceList></ystorewsRequest>"

context = mypostData

' Create the web request
request = DirectCast(WebRequest.Create(address), HttpWebRequest)

' Set type to POST
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"

'' Create the data we want to send
'appId = "cell-accessories"
'context = "Italian sculptors and painters of the renaissance" _
' & "favored the Virgin Mary for inspiration"
'query = "madonna"

data = New StringBuilder()
' data.Append("appid=" + HttpUtility.UrlEncode(appId))
data.Append("context=" + HttpUtility.UrlEncode(context))
' data.Append("&query=" + HttpUtility.UrlEncode(query))

' Create a byte array of the data we want to send
byteData = UTF8Encoding.UTF8.GetBytes(data.ToString())

' Set the content length in the request headers
request.ContentLength = byteData.Length

' Write data
postStream = request.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
If Not postStream Is Nothing Then postStream.Close()
End Try

' Get response
response = DirectCast(request.GetResponse(), HttpWebResponse)

' Get the response stream into a reader
reader = New StreamReader(response.GetResponseStream())

' Console application output
' This exception will be raised if the server didn't return 200 - OK
' Try to retrieve more information about the network error
Catch wex As WebException
If Not wex.Response Is Nothing Then
Dim errorResponse As HttpWebResponse = Nothing
errorResponse = DirectCast(wex.Response, HttpWebResponse)
Console.WriteLine( _
"The server returned '{0}' with the status code {1} ({2:d}).", _
errorResponse.StatusDescription, errorResponse.StatusCode, _
If Not errorResponse Is Nothing Then errorResponse.Close()
End Try
End If
If Not response Is Nothing Then response.Close()
End Try
End Sub

  • R
  • Aug 19, 2010
1 Reply

Recent Posts

in General Discussion at YDN