08-15-2023 05:02 PM
Hello.
I am trying to upload a file of type LMS_REVISE_INVENTORY_STATUS via the Sell Feed API. I first created a task with feed type LMS_REVISE_INVENTORY_STATUS and received a URL location of:
https://api.sandbox.ebay.com/sell/feed/v1/task/<TASK ID>
If it matters, I created the task with schemaVersion 1235. I can't remember where I got that version. (I really don't know where the schemaVersion comes from, so I'd appreciate help with that as well.)
I am then attempting to post to the above URL using the following code (C#):
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
httpClient.DefaultRequestHeaders.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY_US");
var httpContent = new MultipartFormDataContent();
httpContent.Add(new ByteArrayContent(File.ReadAllBytes(filename)), "file");
httpContent.Add(new StringContent(Path.GetFileName(filename)), "fileName");
httpContent.Add(new StringContent("file"), "name");
httpContent.Add(new StringContent("form-data"), "type");
Task<HttpResponseMessage> task = httpClient.PostAsync(uploadURL, httpContent);
task.Wait();
HttpResponseMessage response = task.Result;
var responseString = response.Content.ReadAsStringAsync().Result;
}
Here is my file:
apis:eBLBaseComponents">
en_US
High
1********8
2
The error I am receiving is:
{
"errors": [
{
"errorId": 2004,
"domain": "ACCESS",
"category": "REQUEST",
"message": "Invalid request",
"longMessage": "The request has errors. For help, see the documentation for this API."
}
]
}
Can anyone please tell me what I am doing wrong?
Thanks!
Solved! Go to Best Answer
08-15-2023 08:01 PM
I managed to get it working. For anyone else who comes up against this, here is the code that works:
string filename = Path.GetFileName(filepath);
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
var httpContent = new MultipartFormDataContent();
httpContent.Add(new StringContent(File.ReadAllText(filepath)), "file", filename);
httpContent.Add(new StringContent(filename), "fileName");
httpContent.Add(new StringContent("file"), "name");
httpContent.Add(new StringContent("form-data"), "type");
Task<HttpResponseMessage> task = httpClient.PostAsync(uploadURL, httpContent);
task.Wait();
HttpResponseMessage response = task.Result;
bool succeeded = response.StatusCode == HttpStatusCode.OK;
}
08-15-2023 05:17 PM
The XML file did not format correctly in the above post. Here is the full XML:
<?xml version="1.0" encoding="UTF-8"?>
<BulkDataExchangeRequests>
<ReviseInventoryStatusRequest xmlns="urn
apis:eBLBaseComponents">
<ErrorLanguage>en_US</ErrorLanguage>
<WarningLevel>High</WarningLevel>
<InventoryStatus>
<ItemID>1XXXXXXXXX8</ItemID>
<Quantity>2</Quantity>
</InventoryStatus>
</ReviseInventoryStatusRequest>
</BulkDataExchangeRequests>
08-15-2023 08:01 PM
I managed to get it working. For anyone else who comes up against this, here is the code that works:
string filename = Path.GetFileName(filepath);
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
var httpContent = new MultipartFormDataContent();
httpContent.Add(new StringContent(File.ReadAllText(filepath)), "file", filename);
httpContent.Add(new StringContent(filename), "fileName");
httpContent.Add(new StringContent("file"), "name");
httpContent.Add(new StringContent("form-data"), "type");
Task<HttpResponseMessage> task = httpClient.PostAsync(uploadURL, httpContent);
task.Wait();
HttpResponseMessage response = task.Result;
bool succeeded = response.StatusCode == HttpStatusCode.OK;
}