Accessing Fillz API using PHP

Fillz PHP class

This is a PHP class that implements a very simple interface to the the Fillz API. To use this code, copy-and-paste the code below somewhere into your PHP project. Then, you can create a Fillz object and use it to do your interactions with the Fillz API. The constructor for the Fillz object needs three pieces of information:

  • your username
  • your API token

See below for a sample of creating and using this object.

<?
class FillZ
{
  private $user;
  private $token;
  
  const FILLZ_URL = 'https://app.fillz.com/legacy_api';
  const XML_HEAD = '<?xml version="1.0" encoding="UTF-8"?>';
  
  function __construct( $user, $token)
  {
    $this->user = $user;
    $this->token = $token;
  }

  function get_orders_list( $status) 
  {
    return $this->make_request( <<<EXML
<GetOrders status="$status">
  <AuthUser>$this->user</AuthUser>
  <AuthToken>$this->token</AuthToken>
</GetOrders>
EXML
);
  }

  function get_order( $id, $detail=0) 
  {
    return $this->make_request( <<<EXML
<GetOrder id="$id" detail="$detail">
  <AuthUser>$this->user</AuthUser>
  <AuthToken>$this->token</AuthToken>
</GetOrder>
EXML
);
  }
  
  function set_order_status( $id, $status, 
    $final_postage, 
    $transaction_date_time, 
    $postage_status, 
    $transaction_id,
    $tracking_num,
    $service ) 
  {
    return $this->make_request( <<<EXML
<SetOrderStatus id="$id" status="$status">
  <AuthUser>$this->user</AuthUser>
  <AuthToken>$this->token</AuthToken>
  <Package>
   <FinalPostage>$final_postage</FinalPostage>
   <TransactionDateTime>$transaction_date_time</TransactionDateTime>
   <Status>$postage_status</Status>
   <TransactionID>$transaction_id</TransactionID>
   <PIC>$tracking_num</PIC>
   <Service>$service</Service>
  </Package>
</SetOrderStatus>
EXML
);
  }

  function make_request( $xml)
  {
    $r = new HttpRequest( self::FILLZ_URL, HttpRequest::METH_POST);
    $r->setContentType( 'text/xml');
    $r->setRawPostData( self::XML_HEAD . "\n\n" . $xml);
    
    $msg = $r->send();
    
    if ( $msg->getResponseCode() != 200 )
      throw new Exception( "bad response code: " . $msg->getResponseCode());
    
    $xml = new SimpleXMLElement($msg->getBody());
    
    if ( $xml->getName() == 'Result' ) 
      if ( $xml->Code == 200 )
        return $xml;
      else
        throw new Exception( "request failed: " . $xml->Code . " '" . $xml->Message . "'");
      
    return $xml;
  }
}

?>

 

Using Fillz class

$f = new FillZ( 'your-user-name', 'your-api-token');

print_r( $f->get_orders_list('new'));

#>> SimpleXMLElement Object
#>> (
#>>     [Order] => SimpleXMLElement Object
#>>         (
#>>             [@attributes] => Array
#>>                 (
#>>                     [id] => 78261636
#>>                 )
#>>         )
#>> )

print_r( $f->get_order( 78261636,2));

#>> SimpleXMLElement Object
#>> (
#>>     [@attributes] => Array
#>>         (
#>>             [id] => 78261636
#>>         )
#>>     [Status] => new
#>>     [ShipMethod] => Standard
#>>     [Marketplace] => SimpleXMLElement Object
#>>         (
#>>             [@attributes] => Array
#>>                 (
#>>                     [id] => 5345345
#>>                     [name] => Store
#>>                 )
#>>         )
#>>     [ToName] => SimpleXMLElement Object ()
#>>     [ToAddress1] => SimpleXMLElement Object ()
#>>     [ToAddress2] => SimpleXMLElement Object ()
#>>     [ToCity] => SimpleXMLElement Object ()
#>>     [ToState] => SimpleXMLElement Object ()
#>>     [ToPostalCode] => SimpleXMLElement Object ()
#>>     [ToCountry] => SimpleXMLElement Object ()
#>>     [ToEmail] => SimpleXMLElement Object ()
#>>     [ToPhone] => SimpleXMLElement Object () 
#>>     [Date] => 2010-01-19 17:32:31
#>>     [CreateDate] => 2010-01-20 11:34:52
#>>     [LastModified] => 2010-01-20 11:34:52
#>>     [PaymentReceiveDate] => SimpleXMLElement Object ()#>> 
#>>     [Value] => 761.11
#>>     [Currency] => USD
#>>     [ShippingTotal] => 0
#>>     [BuyerNote] => SimpleXMLElement Object ()
#>>     [SellerNote] => SimpleXMLElement Object ()
#>>     [Items] => SimpleXMLElement Object
#>>         (
#>>             [Item] => Array
#>>                 (
#>>                     [0] => SimpleXMLElement Object
#>>                         (
#>>                             [SKU] => AAA$$$-$$$-Sep07-18-K-1012
#>>                             [Author] => Luis Otero
#>>                             [Title] => He Aqui LA Esclava Del Senor (Spanish Edition)
#>>                             [Media] => Hardcover
#>>                             [ProductId] => 8466603050
#>>                             [Location] => 12503
#>>                             [Quantity] => 1
#>>                             [Condition] => 1
#>>                             [Price] => 190.30
#>>                             [Shipping] => SimpleXMLElement Object ()
#>>                             [Note] => 1
#>>                             [Cost] => 2.50
#>>                             [OrderItemId] => SimpleXMLElement Object ()
#>>                             [Source] => SimpleXMLElement Object ()
#>>                         )
#>>                 )
#>>         )
#>>     [PaymentMethod] => Prepaid
#>> )

$r = $f->get_orders_list('new');
foreach ( $r as $order ) {
  print( $order['id'] . "\n");
}

#>> 78261636
#>> 78261637

$o = $f->get_order( 78261636,2);

foreach ( $o->Items->Item as $item ) {
  print $item->SKU . "\n";
}

#>> AAA$$$-$$$-Sep07-18-K-1012
#>> AAA$$$-$$$-Sep07-19-K-1006
#>> AAA$$$-$$$-Sep07-19-K-1030
#>> AAA$$$-$$$-Sep07-19-K-1034

Have more questions? Submit a request