skip to Main Content

Here is my script which uploads feed to ebay. The script working on local PC but when I upload to my live server, it does not work.

Here is my code.

public function createTask($feedType='FX_LISTING')
    {
        $link = "https://api.ebay.com/sell/feed/v1/task";
        //$appConfig = parse_ini_file("config.ini");
        
        //payload
        $payload = json_encode(array("schemaVersion"=>"1.0","feedType"=>"FX_LISTING"));


        //$appConfig['user_token'] = 'mehboob';
        $ch = curl_init($link);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Authorization:Bearer ' . $this->userToken,
            'Accept:application/json',
            'Content-Type:application/json',
            'X-EBAY-C-MARKETPLACE-ID: EBAY_US'
        ));
        curl_setopt($ch, CURLHEADER_SEPARATE, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        //scurl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        $response = curl_exec($ch);
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $headers = substr($response, 0, $header_size);
        $body = substr($response, $header_size);
        $info = curl_getinfo($ch);  

        echo($body);
        curl_close($ch);

        $headers = explode("rn", $headers); // The seperator used in the Response Header is CRLF (Aka. rn) 

        $headers = array_filter($headers);

        $loc = basename(implode(preg_grep("/^location.*/", $headers)));
      return $loc;


    }
 


    public function uploadFile($taskID, $fName)
    {
          $link = "https://api.ebay.com/sell/feed/v1/task/$taskID/upload_file";
         $curl = curl_init();
        curl_setopt($curl, CURLINFO_HEADER_OUT, true);
        // curl_setopt($curl, CURLOPT_PROXY, '127.0.0.1:8888');
        curl_setopt_array($curl, array(
        CURLOPT_URL => $link,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_SSL_VERIFYHOST=> 1,
        CURLOPT_SSL_VERIFYPEER=> 1,
        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($fName)),'type' => 'form-data'),
        CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer ' . $this->userToken,
        'Content-Type: multipart/form-data',
        'X-EBAY-C-MARKETPLACE-ID: EBAY_US'
        ),
        
        )); 
        
        $response = curl_exec($curl);
        var_dump($response);

        curl_close($curl);

    }

Using the code as under:

$feedPath = __DIR__ . "/" ."feed.csv";
$taskID= createTask();
$uF = uploadFile($taskID,$feedPath);

The above code works fine on my local PC, creating task id and uploading file to ebay. But when I am uploading code on my server, it gets failed.
I confirmed the path to the file on my server is OK.
Also I am using the same version of PHP on my server.

Please see the following response I receives from Server.

string(595) "HTTP/1.1 100 Continue HTTP/1.1 500 Internal Server Error rlogid: t6pitaf%60btuf1%3D9vjdpitaf%60btuf1*or3ah%28rbpv6775-1795f5551e5-0x2340 x-ebay-client-tls-version: TLSv1.2 content-type: application/json content-length: 228 date: Wed, 12 May 2021 06:48:18 GMT x-envoy-upstream-service-time: 125 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."}]}"

The error says about "eBay internal error" but I don’t think so. its due to some problem in the code.

The documentation to the above eBay service is as under:
eBay Feed File – uploadFile documentation

Your cooperation in this context will be highly appreciated.

2

Answers


  1.     This code is in C# - RestClient
        
        createTask
        ==========
        var client = new RestClient("https://api.ebay.com/sell/feed/v1/task");
        client.Timeout = -1;
        var request = new RestRequest(Method.POST);
        request.AddHeader("Authorization", "Bearer v^1.1#i^1****** YOUR USER ACCESS TOKEN *********Ql3QYER3BQAAA==");
        request.AddHeader("Accept", "application/json");
        request.AddHeader("Content-Type", "application/json");
        request.AddHeader("X-EBAY-C-MARKETPLACE-ID", "EBAY_GB");
        var body = @"{
        " + "n" +
        @"  ""schemaVersion"": ""1149"",
        " + "n" +
        @"  ""feedType"": ""LMS_REVISE_INVENTORY_STATUS""
        " + "n" +
        @"}";
        request.AddParameter("application/json", body,  ParameterType.RequestBody);
        IRestResponse response = client.Execute(request);
        Console.WriteLine(response.Content);
        
        Response:
        location:https://api.ebay.com/sell/feed/v1/task/task-12-1127376027
    

    task-12-1127376027 is your TaskID

        uploadFile
        ==========
    test.xml file
    --------------
    
    <?xml version="1.0" encoding="utf-8"?>
    <ReviseInventoryStatusRequest xmlns="urn:ebay:apis:eBLBaseComponents">
      <RequesterCredentials>
        <eBayAuthToken></eBayAuthToken>
      </RequesterCredentials>
        <ErrorLanguage>en_US</ErrorLanguage>
        <WarningLevel>High</WarningLevel>
      <InventoryStatus>
        <SKU>test-1111</SKU>
        <Quantity>10</Quantity>
      </InventoryStatus>
      <InventoryStatus>
        <SKU>test-2222</SKU>
        <Quantity>20</Quantity>
      </InventoryStatus>
    </ReviseInventoryStatusRequest>
    
    
    
    upload code
    -----------
        var client = new RestClient("https://api.ebay.com/sell/feed/v1/task/task-12-1127376027/upload_file");
        client.Timeout = -1;
        var request = new RestRequest(Method.POST);
        request.AddHeader("Authorization", "Bearer v^1.1#i^1****** YOUR USER ACCESS TOKEN *********Ql3QYER3BQAAA==");
        request.AddHeader("X-EBAY-C-MARKETPLACE-ID", "EBAY_GB");
        request.AddHeader("Accept", "application/json");
        request.AddHeader("Content-Type", "multipart/form-data");
        request.AddParameter("fileName", "test.xml");
        request.AddFile("file", "F:/test.xml");
        request.AddParameter("type", "form-data");
        IRestResponse response = client.Execute(request);
        Console.WriteLine(response.Content);
        
        Response: "StatusCode: OK, Content-Type: , Content-Length: 0)"
        
        getTask
        ========
        var client = new RestClient("https://api.ebay.com/sell/feed/v1/task/task-12-1235290549");
        client.Timeout = -1;
        var request = new RestRequest(Method.GET);
        request.AddHeader("Authorization", "Bearer v^1.1#i^1****** YOUR USER ACCESS TOKEN *********Ql3QYER3BQAAA==");
        request.AddHeader("Accept", "application/json");
        request.AddHeader("Content-Type", "application/json");
        IRestResponse response = client.Execute(request);
        Console.WriteLine(response.Content);
        
        Response:
        {
            "taskId": "task-12-1127376027",
            "status": "FAILED",
            "feedType": "LMS_REVISE_INVENTORY_STATUS",
            "creationDate": "2022-02-09T11:39:50.000Z",
            "completionDate": "2022-02-09T11:50:34.000Z",
            "uploadSummary": {
                "successCount": 0,
                "failureCount": 0
            }
        }
    
    Login or Signup to reply.
  2. CREATE TASK
    ============
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://api.ebay.com/sell/feed/v1/task',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_POSTFIELDS =>'{
      "schemaVersion": "1149",
      "feedType": "LMS_REVISE_INVENTORY_STATUS"
    }',
      CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer v^1.1#i^1#p^3#I^*****YOUR USER ACCESS TOKEN HERE****py9v3J3ALc5rcFAAA',
        'Accept: application/json',
        'Content-Type: application/json',
        'X-EBAY-C-MARKETPLACE-ID: EBAY_GB'
      ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo $response;
    
    UPLOAD FILE
    ===========
    
    test.xml file
    -------------
    <?xml version="1.0" encoding="utf-8"?>
    <ReviseInventoryStatusRequest xmlns="urn:ebay:apis:eBLBaseComponents">
      <RequesterCredentials>
        <eBayAuthToken></eBayAuthToken>
      </RequesterCredentials>
        <ErrorLanguage>en_US</ErrorLanguage>
        <WarningLevel>High</WarningLevel>
      <InventoryStatus>
        <SKU>test-1111</SKU>
        <Quantity>10</Quantity>
      </InventoryStatus>
      <InventoryStatus>
        <SKU>test-2222</SKU>
        <Quantity>20</Quantity>
      </InventoryStatus>
    </ReviseInventoryStatusRequest>
    
    
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://api.ebay.com/sell/feed/v1/task/task-12-1127376027/upload_file',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_POSTFIELDS => array('fileName' => 'test.xml','file'=> new CURLFILE('/F:/test.xml'),'type' => 'form-data'),
      CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer v^1.1#i^1#p^3#I^*****YOUR USER ACCESS TOKEN HERE****py9v3J3ALc5rcFAAA',
        'X-EBAY-C-MARKETPLACE-ID: EBAY_GB',
        'Accept: application/json',
        'Content-Type: multipart/form-data'
      ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo $response;
    
    
    GETTASK
    =======
    <?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://api.ebay.com/sell/feed/v1/task/task-12-1127376027',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
      CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer v^1.1#i^1#p^3#I^*****YOUR USER ACCESS TOKEN HERE****py9v3J3ALc5rcFAAA',
        'Accept: application/json',
        'Content-Type: application/json'
      ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo $response;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search