question

itati-shop avatar image
0 Likes"
itati-shop asked

I need some help for the file upload feed API in PHP

Hello,

I need some help for the file upload feed API in PHP.

I just can't find an approach how to upload a file using the feed-API interface.

The aim is to upload a "csv" file that takes over the current stocks in eBay.

At the moment I am doing that with the FileExchange which will be discontinued on June 15th.

Maybe someone already has experience with it and can show me a PHP source code?

Many thanks for your help.


#### added: 15.Mai 2021 ####

The goal is to have a CSV file


For example, upload_file.csv:

----

Action (Siteid = Germany | Country = DE | Currency = EUR | Version = 835 | CC = UTF-8); Itemid; Quantity; Relationship; Relationship Details; Product: EAN; Customlabel

Revise; 31188022534; 15 ;;; 8335310347924; TM-37692

----


To upload to eBay via feed API.


First, the Create_Task is executed and returns a task number. (is working)


----

$ postdata = [

'feedtype' => 'lms_revise_fixed_price_item',

'Schemaversion' => '1149'

];

----


Then the file should be uploaded with


----

Curlopt_url => 'https://api.ebay.com/sell/feed/v1/task/task-1xx9/upload_file'

----


where the corresponding task number is used under Task-1xx9.


In the header, the same token has been used as the Create Task.


Result is:

Http / 1.1 100 Continue

HTTP / 1.1 500 Internal Server Error


and


{Errors ": [{" Errorid ": 160001," Domain ":" api_feed "," subdomain ":" Selling "," category ":" Application "," Message ":" There's a problem with an eBay internal System or Process. CONTACT eBay Developer Technical Support for Assistance. "}]}


And as an answer comes the following header:


----

Post / Sell / Feed / V1 / Task / Task-2-1444222119 / upload_file http / 1.1 Host: api.ebay.com ACCEPT-Encoding: Deflate, Gzip Authorization: Bearer V ^ 1.BlabLablaBlablaLA = X-eBay C-Marketplace -ID: eBay_en Accept: Application / JSON Content-Length: 55526 Content Type: Multipart / Form Data; Boundary = ------------------------ 7B48AB0D3D36F98D Expect: 100-Continue

----


Striking is that under Accept: Application / JSON stands.

The file length is correct.


Can it be that you can not load CSV files on German eBay, but only JSON files?


I am grateful for every tip ... :-)


##############################

# It works ! ---- 20.05.2021 ##########

##############################


Feed APIv1.3.1

CreateTask ist => FX_LISTING !!

PHP cURL => CURLFILE ist zwingend mit @-Zeichen, andernfalls wird eine leere Datei zu eBay übertragen.

Hier der funktionierende Code:


$file = $_SERVER["DOCUMENT_ROOT"]."/upload_file.csv";

$curl = curl_init();
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$finfo = finfo_file($finfo, $datei);

$postData = [ 'file' => new CURLFILE(@$file,$finfo,$datei), 'type' => 'form-data', 'name' => 'file',];

curl_setopt_array($curl, array(
CURLOPT_URL => https://api.ebay.com/sell/feed/v1/task/task-77777774/upload_file
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_SSL_VERIFYHOST=> 0,
CURLOPT_SSL_VERIFYPEER=> 0,
CURLOPT_TIMEOUT => 0,
CURLOPT_HEADER => 1,
CURLINFO_HEADER_OUT => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $postData,
CURLOPT_HTTPHEADER => array(
'Authorization:Bearer '.$token,'X-EBAY-C-MARKETPLACE-ID:EBAY_DE','Content-Type:multipart/form-data','Accept:application/json'
),));
$response = curl_exec($curl);

curl_close($curl);

Die Datei wird dann hochgeladen und steht im Verkäufer Cockpit Pro unter Berichte.

feed-apiuploadfilecurlfilephp upload sell-api
· 2
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I am happy for you!
What inizialize $datei? is empty?

0 Likes 0 ·
itati-shop avatar image itati-shop giuseppdivuol_0 ·

$x = pathinfo($file);

$datei = $x["basename"];

0 Likes 0 ·
ordi-paris avatar image
0 Likes"
ordi-paris answered

Works fine. First create task, then upload file and later check result.

<?php


$curl = curl_init();


curl_setopt_array($curl, array(

CURLOPT_URL => 'https://api.ebay.com/sell/feed/v1/task/task-40-xxx7/upload_file',

CURLOPT_RETURNTRANSFER => true,

CURLOPT_ENCODING => '',

CURLOPT_MAXREDIRS => 10,

CURLOPT_SSL_VERIFYHOST=> 0,

CURLOPT_SSL_VERIFYPEER=> 0,

CURLOPT_TIMEOUT => 0,

CURLOPT_HEADER => 1,

CURLOPT_FOLLOWLOCATION => true,

CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

CURLOPT_CUSTOMREQUEST => 'POST',

CURLOPT_POSTFIELDS => array('file'=> new CURLFILE(realpath("upload_file.csv")),'type' => 'form-data'),

CURLOPT_HTTPHEADER => array(

'Authorization: Bearer <your oauth token here>',

'X-EBAY-C-MARKETPLACE-ID: EBAY_US'

),

));


$response = curl_exec($curl);

var_dump($response);

curl_close($curl);

?>

· 7
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

You are awesome!

This works like a charm.

You saved my days.

Thanks

0 Likes 0 ·

The script works on Local PC, however, when I upload to live server, it does not work.

I have shared all the requests and responses in the forum, please check if there is any problem in the code?


https://forums.developer.ebay.com/questions/41609/selling-feed-api-uploadfile-works-from-local-pc-bu.html


Thanks

0 Likes 0 ·

many thanks for the help !!

I think that was the key ... I'll try it right away.

many thanks

0 Likes 0 ·

It may be that CSV files can not be uploaded, but only JSON?

0 Likes 0 ·

But according to documentation, csv is valid type to upload. And also it is successfully uploading when sending request from Local PC. The file get uploaded and returns response with processing information as how many records accepted and rejected. So the file is valid and uploadable. The problem is only something is going wrong from live hosting server.

0 Likes 0 ·

After a very long research, I have the following knowledge:

Upload via feed API works with FX_Listing.


Curl on the console and with CSV file and custom task works flawlessly.


CURL with PHP on the same device in conjunction with CURLFILE does not work. The file is probably uploaded and also found, but eBay does not process it.


What could mean that? Wrong Mime? I tried it with "text/plain".


There must be a difference between CURL on the console (MacOS) and the PHP7 on the same device.

I'm completely at a loss ... :-(

please help me :-)

0 Likes 0 ·
Show more comments
afridigems avatar image
0 Likes"
afridigems answered

The code you have provided is working on local PC but not working on live server.

Can you please suggest any modification?


See the response from my server.

task-40-1312321194string(595) "HTTP/1.1 100 Continue HTTP/1.1 500 Internal Server Error rlogid: t6pitaf%60btuf1%3D9whhpitaf%60btuf1*t2dao%28rbpv6713-1795f176c30-0x2355 x-ebay-client-tls-version: TLSv1.2 content-type: application/json content-length: 228 date: Wed, 12 May 2021 05:40:42 GMT x-envoy-upstream-service-time: 134 server: ebay-proxy-server x-ebay-pop-id: UFES2-LVSAZ01-api {"errors":[{"errorId":160001,"domain":"API_FEED","subdomain":"Selling","category":"APPLICATION","message":"There was a problem with an eBay internal system or process. Contact eBay Developer Technical Support for assistance."}]}" 


· 3
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I have exactly the same answer.

After all, I first get an answer (HTTP / 1.1 100 Continue) and then immediately an answer (HTTP / 1.1 500 Internal Server Error).

I find no mistake. And in the documentation is no longer.

What else could it be ???

0 Likes 0 ·

Check if CSV file path is correct.

0 Likes 0 ·

Yes ... I also think it could lie on the path.

Local works everything, but via PHP on the same device does not work.


$ postdata = [

'filename' => New CurlFile (RealPath ('upload_file.csv'),

'Type' => 'Form Data',

'name' => 'file'

];


Somehow it stumbles somewhere and I just do not get it solved. As if the file is not found.

0 Likes 0 ·
melodyge-58 avatar image
0 Likes"
melodyge-58 answered

In this tutorial, we will show you how to work with RESTful API and For any file that is about to be uploaded, we need to have the case, unfortunately it's not of much help in case of file uploading. Simply plug your own RSS feeds and turn the Xcode template into a RSS reader or a Blog reader app.


mygiftcarsdsite mastercard

10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

giuseppdivuol_0 avatar image
0 Likes"
giuseppdivuol_0 answered

After many days it finally works!

If you use a php version <5.6 (but I think it is the same for the other versions) you have to add the mimetype "text / html" to the $cfile with your .csv!!!

$url_file = $_SERVER["DOCUMENT_ROOT"]. "/ebay/product_ebay.csv";
$cfile = "@".$url_file."; type=text/html;filename=product_ebay.csv";

$fields = array ("file" => $cfile, "type" => "form-data", "name" => "file");

If you have php version <5.6 use this:

curl_setopt ($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);

Thank you all for ispirations


· 1
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I tried your hack but did not work. Can you share your upload script, or rectify mines one given in the reply.


Thanks

0 Likes 0 ·
afridigems avatar image
0 Likes"
afridigems answered

Hello @giuseppdivuol_0 ,

I put the mimetype type as you suggested, but still not working. My php version is above 7

Please see my curl request if there is any problem.


 public function uploadFile($taskID, $fName)
    {
        $link = "https://api.ebay.com/sell/feed/v1/task/$taskID/upload_file";
 
        $curl = curl_init();
         
        $cfile = "@". realpath($fName).";type=text/html;filename=feed_copy.csv";

        curl_setopt_array($curl, array(
        
        CURLOPT_URL => 'https://api.ebay.com/sell/feed/v1/task/' . $taskID . '/upload_file',
        
        CURLOPT_RETURNTRANSFER => true,
        
        CURLOPT_ENCODING => '',
        
        CURLOPT_MAXREDIRS => 10,
        
        CURLOPT_SSL_VERIFYHOST=> 0,
        
        CURLOPT_SSL_VERIFYPEER=> 0,
        
        CURLOPT_TIMEOUT => 0,
        
        CURLOPT_HEADER => 1,
        
        CURLOPT_FOLLOWLOCATION => true,
        
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        
        CURLOPT_CUSTOMREQUEST => 'POST',
        
        CURLOPT_POSTFIELDS => array("file" => $cfile, "type" => "form-data", "name" => "file"),
        
        CURLOPT_HTTPHEADER => array(
        
        'Authorization: Bearer ' . $this->userToken,
        
        'X-EBAY-C-MARKETPLACE-ID: EBAY_US'
        
        ),
        
        )); 

        $response = curl_exec($curl);
       
        curl_close($curl);

    }

Please look into the matter if you can help.

Thanks

10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.