0
votes

I am trying to get sessionid by using ebay Trading API . I am able to get session id successfully by using Curl but as soon as i try to fetch session id via Guzzle Http client, get below error in response from ebay

FailureUnsupported API call.The API call "GeteBayOfficialTime" is invalid or not supported in this release.2ErrorRequestError18131002

I suppose there's some issues with the way i am using GuzzleHttp client . I am currently using GuzzleHttp v6 and new to this . Below is the code i am using to get session id by calling actionTest function

public function actionTest(){

$requestBody1 = '<?xml version="1.0" encoding="utf-8" ?>';
$requestBody1 .= '<GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestBody1 .= '<Version>989</Version>';
$requestBody1 .= '<RuName>test_user-TestAs-Geforc-ldlnmtua</RuName>';    
$requestBody1 .= '</GetSessionIDRequest>';


 $headers = $this->getHeader();


      $client = new Client();

    $request = new Request('POST','https://api.sandbox.ebay.com/ws/api.dll',$headers,$requestBody1);
    $response = $client->send($request);

    /*$response = $client->post('https://api.sandbox.ebay.com/ws/api.dll', [
        'headers' => $headers,
        'body' => $requestBody1
    ]);*/

    echo $response->getBody();die;

}

public function getHeader()
{
    $header = array(
        'Content-Type: text/xml',
        'X-EBAY-API-COMPATIBILITY-LEVEL: 989',
        'X-EBAY-API-DEV-NAME: a4d749e7-9b22-441e-8406-d3b65d95d41a',
        'X-EBAY-API-APP-NAME: TestUs-GeforceI-SBX-345ed4578-10122cfa',
        'X-EBAY-API-CERT-NAME: PRD-120145f62955-96aa-4d748-b1df-6bf4',
        'X-EBAY-API-CALL-NAME: GetSessionID',
        'X-EBAY-API-SITEID: 203',
    );
    return $header;
}

Plz suggest the possible shortcoming in the way i am making request . I already tried/modified the guzzle request call by referring various reference site and guzzle official doc but error remained same .

1

1 Answers

2
votes

You need to pass an associative array of headers as explained in the documentation.

public function getHeader()
{
    return [
        'Content-Type'                   => 'text/xml',
        'X-EBAY-API-COMPATIBILITY-LEVEL' => '989',
        'X-EBAY-API-DEV-NAME'            => '...',
        'X-EBAY-API-APP-NAME'            => '...',
        'X-EBAY-API-CERT-NAME'           => '...',
        'X-EBAY-API-CALL-NAME'           => '...',
        'X-EBAY-API-SITEID'              => '203',
    ];
}

In case you are interested there is an SDK available that simplifies the code. An example of how to call GetSessionID is shown below.

<?php
require __DIR__.'/vendor/autoload.php';

use \DTS\eBaySDK\Trading\Services\TradingService;
use \DTS\eBaySDK\Trading\Types\GetSessionIDRequestType;

$service = new TradingService([
    'credentials' => [
        'appId'  => 'your-sandbox-app-id',
        'certId' => 'your-sandbox-cert-id',
        'devId'  => 'your-sandbox-dev-id'
    ],
    'siteId'      => '203',
    'apiVersion'  => '989',
    'sandbox'     => true
]);

$request = new GetSessionIDRequestType();
$request->RuName = '...';

$response = $service->getSessionID($request);

echo $response->SessionID;