So from looking at the link below I see that you can cancel an order by opening a dispute with the 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;
}