Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ebay Auth token

I'm using Sandbox Auth. Token here and it always sends me an error like this.

Error: Auth token is invalid. Validation of the authentication token in API request failed.

But if I use my Production Auth. Token it seems to workout and has no problem at all.

I've also checked the validity of my Sandbox Token and the expiration date is November 2016 which is far enough. Can someone please help me regarding my problem? Thanks in advance.

Here's the code:

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

$config = require __DIR__.'/../configuration.php';

use \DTS\eBaySDK\Constants;
use \DTS\eBaySDK\Trading\Services;
use \DTS\eBaySDK\Trading\Types;
use \DTS\eBaySDK\Trading\Enums;

$service = new Services\TradingService(array(
    'apiVersion' => $config['tradingApiVersion'],
    'siteId' => Constants\SiteIds::US
));

$request = new Types\GetMyeBaySellingRequestType();

$request->RequesterCredentials = new Types\CustomSecurityHeaderType();
$request->RequesterCredentials->eBayAuthToken = $config['sandbox']['userToken'];

$request->ActiveList = new Types\ItemListCustomizationType();
$request->ActiveList->Include = true;
$request->ActiveList->Pagination = new Types\PaginationType();
$request->ActiveList->Pagination->EntriesPerPage = 10;
$request->ActiveList->Sort = Enums\ItemSortTypeCodeType::C_CURRENT_PRICE_DESCENDING;

$pageNum = 1;

do {
    $request->ActiveList->Pagination->PageNumber = $pageNum;
    $response = $service->getMyeBaySelling($request);

echo "==================\nResults for page $pageNum\n==================\n";

if (isset($response->Errors)) {
    foreach ($response->Errors as $error) {
        printf("%s: %s\n%s\n\n",
            $error->SeverityCode === Enums\SeverityCodeType::C_ERROR ? 'Error' : 'Warning',
            $error->ShortMessage,
            $error->LongMessage
        );
    }
}

if ($response->Ack !== 'Failure' && isset($response->ActiveList)) {
    foreach ($response->ActiveList->ItemArray->Item as $item) {
        printf("(%s) %s: %s %.2f\n",
            $item->ItemID,
            $item->Title,
            $item->SellingStatus->CurrentPrice->currencyID,
            $item->SellingStatus->CurrentPrice->value
        );
    }
}

$pageNum += 1;

} while(isset($response->ActiveList) && $pageNum <= $response->ActiveList->PaginationResult->TotalNumberOfPages);

Credits to Sir David T. Sadler

like image 692
River Avatar asked Jun 28 '26 07:06

River


2 Answers

By default the SDK will connect to the production API. If you want to use the sandbox API just pass true to the sandbox configuration option when creating your TradingService object. A list of all the configuration options is available.

$service = new Services\TradingService(array(
    'apiVersion' => $config['tradingApiVersion'],
    'siteId' => Constants\SiteIds::US,
    'sandbox' => true
));

Base on what was given I can almost guarantee you are sending your request to

https://api.ebay.com/ws/api.dll (which is why production auth works)

instead of sending it to

https://api.sandbox.ebay.com/ws/api.dll (in which the sandox auth SHOULD work)

Additional notes

Make sure all three of the developer id's are sandbox compared to production because they do differ

Also it should be noted sandbox has a bunch more bugs than production, so personally I just use production to set up my calls and stuff.

like image 25
Ian Thompson Avatar answered Jun 30 '26 21:06

Ian Thompson