简体   繁体   中英

Ebay API C# Cancel Order without AddDispute

So from looking at the link below I see that you can cancel an order by opening a dispute with the API.

Cancel eBay order via API

But I'm not looking to open a dispute for every cancellation. What I would like to do is be able to programmatically cancel the order without opening a dispute. It would seem that this should be possible since it is available in the GUI. In the GUI if you look up your orders and click on the drop down of the orders screen you get a cancel button. Then on the next screen it asks the reason for cancelling and gives you two options. I can't seem to find documentation on this anywhere. Everything I can find for cancelling an order with the API leads to the method of opening a dispute. Does anyone know how to cancel an order with this method?

在此输入图像描述

在此输入图像描述

I was able to figure out this can be accomplished by using the Post-Order API.

https://developer.ebay.com/Devzone/post-order/index.html

Look at the links under the Cancellation section.

UPDATING ANSWER WITH CODE EXAMPLE FOR KEVINUK:

This is my working example. I use it as a bool to let me know whether or not the cancellation request was successful or not so that I can see where to go from there.

    /// <summary>
    /// 
    /// </summary>
    /// <param name="authToken"></param>
    /// <param name="ebayFullOrderId"></param>
    /// <param name="reason">Must be BUYER_ASKED_CANCEL or ADDRESS_ISSUES</param>
    private static bool Cancellation_SubmitCancelRequest(string authToken, string ebayFullOrderId, string reason)
    {
        var status = false;
        const string url = "https://api.ebay.com/post-order/v2/cancellation";

        var cancelOrderRequest = (HttpWebRequest)WebRequest.Create(url);

        cancelOrderRequest.Headers.Add("Authorization", "TOKEN " + authToken);
        cancelOrderRequest.ContentType = "application/json";
        cancelOrderRequest.Accept = "application/json";
        cancelOrderRequest.Headers.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY_US");
        cancelOrderRequest.Method = "POST";

        //cancelOrderRequest.Headers.Add("legacyOrderId", ebayFullOrderId);

        using (var streamWriter = new StreamWriter(cancelOrderRequest.GetRequestStream()))
        {
            string json = "{\"legacyOrderId\":\"" + ebayFullOrderId + "\",\"cancelReason\":\"" + reason + "\"}";

            streamWriter.Write(json);
            streamWriter.Flush();
            streamWriter.Close();
        }

        var response = (HttpWebResponse)cancelOrderRequest.GetResponse();

        string result;
        using (var streamReader = new StreamReader(response.GetResponseStream()))
        {
            result = streamReader.ReadToEnd();
        }
        var reader = new JsonTextReader(new StringReader(result));

        while (reader.Read())
        {
            if (reader.Value != null)
            {
                var pt = reader.Path;
                var val = reader.Value.ToString();

                var isNumeric = !string.IsNullOrEmpty(val) && val.All(Char.IsDigit);
                if (pt == "cancelId" & isNumeric == true)
                {
                    status = true;
                    break;
                }
            }
        }
        return status;
    }    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM