Я пытался использовать PostMan для отправки запроса на eBay createShippingFulfillment , и это работает. Однако, когда я попытался опубликовать его в VS, я получил ошибку Bad Request.
StatusCode: 400, ReasonPhrase: 'Bad Request'
Ниже подробно описана ошибка
{[
{
"errorId": 32200,
"domain": "API_FULFILLMENT",
"category": "REQUEST",
"message": "Invalid line item id: ''"
}
]}
Когда я проверил значение lineItemId, это правильно и также я использую string
и long
для lineItemId
, но все еще та же ошибка.
{"lineItems":[{"lineItemId":"100224635xxxxx","quantity":1}],"shippedDate":"2020-01-24T01:25:15.604Z","shippingCarrierCode":"Couriers Please","trackingNumber":"6J7042xxxx"}
Коды ниже:
string endpoint = string.Format("sell/fulfillment/v1/order/{0}/shipping_fulfillment", orderFromOrd.StoreOrderId);
Fullfillment fulfillment = new Fullfillment();
fulfillment.trackingNumber = orderFromOrd.TrackingNo;
fulfillment.shippingCarrierCode = base.GetCarrierName(_carriers, orderFromOrd);
fulfillment.shippedDate = DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:ss.fffZ");
foreach (var ol in sentOrigOLOrd)
{
var checkIfsentinOrd = checkOLinStore.Where(x => x.lineItemId == ol.StoreOrderLineId).FirstOrDefault();
if (checkIfsentinOrd != null)//Only not fulfilled orderlines & sent orderlinestatus in Ordmation
{
FulfillmentLineItems line = new FulfillmentLineItems();
line.lineItemId = Convert.ToInt64(ol.StoreOrderLineId); // line-item-id from store Order
line.quantity = ol.Qty;
fulfillment.lineItems.Add(line);
}
}
HttpResponseMessage response = _requestHelper.PostHttpResponse(endpoint, fulfillment);
public HttpResponseMessage PostHttpResponse(string requestUri, object data)
{
// Serialize our concrete class into a JSON String
var stringPayload = JsonConvert.SerializeObject(data);
// Wrap our JSON inside a StringContent which then can be used by the HttpClient class
var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
using (var client = CreateHttpClient())
{
try
{
HttpResponseMessage response = client.PostAsJsonAsync(requestUri, httpContent).Result;
//response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
{
return response;
}
else
{
GetErrorsResponse(response);
throw new HttpRequestException(string.Format("There was an exception trying to post a request. response: {0}", response.ReasonPhrase));
}
}
catch (HttpRequestException ex)
{
throw ex;
//return null;
}
}
}
private HttpClient CreateHttpClient()
{
var client = new HttpClient();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
string baseAddress = WebApiBaseAddress;
if (string.IsNullOrEmpty(baseAddress))
{
throw new HttpRequestException("There is no base address specified in the configuration file.");
}
client.Timeout = new TimeSpan(0, 5, 59);
client.BaseAddress = new Uri(baseAddress);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Add("Authorization", string.Format("Bearer {0}", _cred.eBayToken));
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));//ACCEPT header
client.DefaultRequestHeaders.Add("LegacyUse", "true");
return client;
}