0

Order Payment API - Yahoo Store

Hi,

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
Try
postStream = request.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
Finally
If Not postStream Is Nothing Then postStream.Close()
End Try

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

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

' Console application output
Console.WriteLine(reader.ReadToEnd())
' 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
Try
errorResponse = DirectCast(wex.Response, HttpWebResponse)
Console.WriteLine( _
"The server returned '{0}' with the status code {1} ({2:d}).", _
errorResponse.StatusDescription, errorResponse.StatusCode, _
errorResponse.StatusCode)
Finally
If Not errorResponse Is Nothing Then errorResponse.Close()
End Try
End If
Finally
If Not response Is Nothing Then response.Close()
End Try
End Sub

by
5 Replies
  • I responded to your earlier post.

    Cheers,
    Robyn
    0
  • Hi,

    There are no real answers out there for this problem and we are having a very tough time working through this very same issue. I'm sure it's something simple, but even the XML straight out of the documentation (using the correct token, store ID, etc) is returning 400 Bad Request. I have tried multiple ways of generating the request (HTML form, C#, Fiddler) and get the same error with each one. Can someone please post a simple, working example of a complete request?

    HELP!
    0
  • QUOTE (GlennP @ Nov 11 2010, 07:02 AM) <{POST_SNAPBACK}>
    Hi,

    There are no real answers out there for this problem and we are having a very tough time working through this very same issue. I'm sure it's something simple, but even the XML straight out of the documentation (using the correct token, store ID, etc) is returning 400 Bad Request. I have tried multiple ways of generating the request (HTML form, C#, Fiddler) and get the same error with each one. Can someone please post a simple, working example of a complete request?

    HELP!



    I have the same issue. Have you found a solution? I have talk to a yahoo rep with no luck.
    This is frustrating having the sample XML in the documantation but no clear way of properly
    packaging the REST request to their server. No one seems to have an answer.
    0
  • Can somebody point me in the right direction for this? I am having the same 400 issues.
    0
  • I found the solution to the C# (ERROR 400) bad message from Yahoo Order and Payment API.
    NOTE: Do not use the StringBuilder function as this is the root of the problem.
    I hope this helps, Good Luck!
    Bill R.

    The following code works.

    static void Main(string[] args)
    {

    String StoreID = "Your Store ID goes here";
    String Url = "https://" + StoreID + ".order.store.yahooapis.com/V1/order";
    String ContractToken = "Your Partner Access Token goes here";

    // Create the request message.
    HttpWebRequest request = WebRequest.Create(Url) as HttpWebRequest;
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    String Message = CreateStoreMessage(StoreID, ContractToken, OrderID);

    // Create a byte array of the data we want to send.
    byte[] byteData = UTF8Encoding.UTF8.GetBytes(Message);

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

    // Send the request message.
    using (Stream postStream = request.GetRequestStream())
    {
    postStream.Write(byteData, 0, byteData.Length);
    }

    // Get the message response.
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
    StreamReader reader = new StreamReader(response.GetResponseStream());

    // Console application output
    Console.WriteLine(reader.ReadToEnd());
    }

    // Pause the console so we can see the message.
    Console.ReadLine();
    }

    private static String CreateStoreMessage(String Store_ID, String Token, String Order_ID)
    {
    String MsgRequest = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
    MsgRequest += "<ystorewsRequest>";
    MsgRequest += " <StoreID>" + Store_ID + "</StoreID>";
    MsgRequest += " <SecurityHeader>";
    MsgRequest += " <PartnerStoreContractToken>" + Token + "</PartnerStoreContractToken>";
    MsgRequest += " </SecurityHeader>";
    MsgRequest += " <Version> 1.0 </Version>";
    MsgRequest += " <Verb> get </Verb>";
    MsgRequest += " <ResourceList>";
    MsgRequest += " <OrderListQuery>";
    MsgRequest += " <Filter>";
    MsgRequest += " <Include> all </Include>";
    MsgRequest += " </Filter>";
    MsgRequest += " <QueryParams>";
    MsgRequest += " <OrderID>" + Order_ID + "</OrderID>";
    MsgRequest += " </QueryParams>";
    MsgRequest += " </OrderListQuery>";
    MsgRequest += " </ResourceList>";
    MsgRequest += "</ystorewsRequest>";

    return MsgRequest;
    }
    }
    0

Recent Posts

in .NET Development