Ebay API C#取消没有AddDispute的订单

时间:2017-01-04 23:04:48

标签: c# ebay ebay-api

因此,通过查看下面的链接,我发现您可以通过打开与API的争议来取消订单。

Cancel eBay order via API

但我不打算为每次取消打开争议。我想做的是能够以编程方式取消订单而不会引发争议。似乎这应该是可能的,因为它在GUI中可用。在GUI中,如果您查找订单并单击订单屏幕下拉菜单,则会出现取消按钮。然后在下一个屏幕上询问取消的原因并给出两个选项。我似乎无法在任何地方找到相关文档。我可以通过API取消订单的所有内容都会导致打开争议的方法。有谁知道如何用这种方法取消订单?

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:3)

我能够发现这可以通过使用Post-Order API来实现。

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

查看“取消”部分下的链接。

使用KEVINUK的代码示例更新答案:

这是我的工作范例。我用它作为一个bool让我知道取消请求是否成功,以便我可以看到从那里去哪里。

    /// <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;
    }