Tradera.com logotype

Tradera Developer Program

Push API 

Tradera has a push API that can be used if required. It provides very limited information but can keep you notified of certain events in near realtime (< 30 seconds). It does not replace other API methods since the information sent through the push API is only an item Id or order Id and some timestamp information.

The Tradera push API uses Amazon Web Services Simple Queue Services (AWS SQS) an AWS account is needed for the push API. To enable a user for the SQS we suggest using AWS IAM to create a user and then on the permissions tab attaching the policy AmazonSQSFullAccess. The entry point used is Frankfurt(eu-central-1)

In order to get access to the push API you will first need to create an AWS user (see previous paragraph). To request access contact apiadmin@tradera.com and provide the following information:

  • AWS user account name.
  • AWS user account id.
  • Tradera application id.
  • What your application does and why it needs the push functionality.

API Push sends events from the Tradera system to Amazon SQS. Enabled applications will get access their own queue, to which messages for all authorized members are sent. Authorized members are Tradera users whose accounts have been used to login with the application at TokenLogin. There are two types of messages that can be sent through the queue: OrderCreated and ItemClosed.

OrderCreated

OrderCreated is sent when orders are created. For Auction/AuctionBin/FixedPrice that happens when the buyer confirms the purchase or the auction ends with a winning bid. For ShopItems that happens when the item is payed for.

Example message (JSON):

{"Type":"OrderCreated","OrderId":10187,"SellerMemberId":300124,"CreatedDate":"2015-11-11T14:36:33.9352466Z", "ItemIds": [11111]}

ItemClosed

ItemClosed is sent when an item is closed. That happens in four cases:

  • When Tradera shuts down a listing
  • When the seller shuts down the listing in my tradera
  • When a listing expires without a buyer
  • When a shop item's inventory reaches 0

Example message (JSON):

{"Type":"ItemClosed","ItemId":85592775,"SellerMemberId":300124, "Reason": "ItemClosedByTradera"}

Reason can be one of four values

ItemClosedByTradera
The listing has been shut down by Tradera
ItemClosedBySeller
The listing has been closed by the seller
ItemEndedWithoutBuyer
The item has expired without a buyer
ShopItemQuantityZero
The shop item's inventory has reaced 0

Code Example

The following is an example written in PHP. Notice that each message has to be removed like in the example or it will reappear in the queue after a short period of time.

  1:
  2:
  3:
  4:
  5:
  6:
  7:
  8:
  9:
 10:
 11:
 12:
 13:
 14:
 15:
 16:
 17:
 18:
 19:
 20:
 21:
 22:
 23:
 24:
 25:
 26:
 27:
 28:
 29:
 30:
 31:
 32:
 33:
 34:
 35:
 36:
 37:
 38:
 39:
 40:
 41:
 42:
 43:
 44:
 45:
 46:
 47:
 48:
 49:
 50:
 51:
 52:
 53:
 54:
 55:
 56:
 57:
 58:
 59:
 60:
 61:
// Composer autoloading
require 'vendor/autoload.php';

// Client used for connecting to AWS SQS
use Aws\Sqs\SqsClient;

// eu-central-1 is the Frankfurt entry point
// here the profile is configured in the ~/.aws/credentials
$client = SqsClient::factory(array(
    'profile' => 'default',
    'region'  => 'eu-central-1'
));


// The url is specific for your application id and Tradera user
$queueUrl = 'https://sqs.eu-central-1.amazonaws.com/1234567890/tradera_api_push_prod_4321';

// Typically replaced with: while(true)
// In production
for ($i=0; $i < 5; $i++) { 
    echo PHP_EOL . 'Long polling' . PHP_EOL;
    // The queue URL is supplied by Tradera on request if a queue is needed
    // If the queue is empty receiveMessage() blocks for a 
    $result = $client->receiveMessage(array(
        'QueueUrl' => $queueUrl,
        'MaxNumberOfMessages' => 10
    ));

    
    if(!is_array($result->get('Messages'))){
        echo 'Empty result' . PHP_EOL;
        continue;
    }

    foreach ($result->get('Messages') as $message) {
        // Do something with the message
        echo 'Body: ' . $message['Body'] . PHP_EOL;
        //echo 'MD5OfBody: ' . $message['MD5OfBody'] . PHP_EOL;
        //echo 'ReceiptHandle: ' . $message['ReceiptHandle'] . PHP_EOL;
        echo 'MessageId: ' . $message['MessageId'] . PHP_EOL;

        // For example
        $msgBody = json_decode($message['Body']);
        if($msgBody -> Type == 'OrderCreated'){
            echo 'Handle new order with OrderId: ' . $msgBody -> OrderId . PHP_EOL;
        }
        elseif($msgBody -> Type == 'ItemClosed'){
            echo 'Item with ItemId ' . $msgBody -> ItemId . ' was closed' . PHP_EOL;
        }
        else {
            echo 'Something went wrong. Message body:' . PHP_EOL;
            echo print_r($msgBody);
        }

        // Each message needs to be removed from the queue, otherwise it will only hidden for a little while 
        $result = $client->deleteMessage(array(
            'QueueUrl' => $queueUrl,
            'ReceiptHandle' => $message['ReceiptHandle'],
        ));
    }
}

XHTML CSS