c# - Ebay Restful API createshippingfulfillment Bad Request 400 错误
问题描述
我尝试使用PostMan向 eBay 的 createShippingFulfillment 发送请求,这很有效。但是,当我尝试在 VS 中发布它时,我收到了错误的请求错误。
StatusCode: 400, ReasonPhrase: 'Bad Request'
下面是详细的错误
{[
{
"errorId": 32200,
"domain": "API_FULFILLMENT",
"category": "REQUEST",
"message": "Invalid line item id: ''"
}
]}
当我检查 lineItemId 的值时,它是正确的,而且我使用了string
and long
forlineItemId
但仍然是同样的错误。
{"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;
}
解决方案
推荐阅读
- react-native - 任何人都知道我为什么会出现此错误:未定义不是对象(正在评估'messages.filter')
- javascript - 为什么 after() 函数不能与 clone() 函数一起使用?
- python - 从“gejson”变量中获取坐标(Python)
- reactjs - 如何在循环组件内只执行一次useEffect
- typescript - 如何在 VS Code 上获取 typescript 的 Go To Definition?
- python - 如何相对于请求django返回
- python - Python equivalent of Wolfram Table[]
- android - java.lang.ClassCastException:com.eng.bt_eng_mobility.viewmodel.HomeViewModelFactory 不能转换为 androidx.lifecycle.ViewModel
- php - Laravel 8 多对多关系不起作用(没有抛出错误)
- sqlalchemy - Nested session.query using sqlalchemy