PHP Examples

This code and these examples were written using PHP verison 5.2.13. PHP was configured with the --with-curl option and JSON enabled. See PHP JSON and PHP cURL for the details of the PHP functions.

As of October 2014, SSL v3 is no longer supported for secure_token requests. You can ensure this is enabled by calling "curl_setopt($connection, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);" - note that you may also need to add "CURLOPT_SSL_CIPHER_LIST => 'TLSv1'" to your PPHttpConfig.php - as described in this StackOverflow answer.

PHP Example for fetchToken

The fetchToken API call does not have ANY inputs. This call is a secure API request and requires the dev name and cert name headers. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print the token. Print the full response.

$dev_name = "xxx";
$cert_name = "yyy";
$url = "https://api.bonanza.com/api_requests/secure_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$args = array();
$post_fields = "fetchTokenRequest";
echo "Request: $post_fields \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
$token = $response['fetchTokenResponse']['authToken'];
echo "Token: $token \n";
echo "Response: \n";
print_r($response);
Request: fetchTokenRequest
Token: GTL0jWeQat
Response:
Array
(
  [fetchTokenResponse] => Array
      (
          [hardExpirationTime] => 2011-12-16T06:20:58.000Z
          [authenticationURL] => https://www.bonanza.com/login?apitoken=GTL0jWeQat
          [authToken] => GTL0jWeQat
      )
  [timestamp] => 2010-12-16T06:20:58.000Z
  [version] => 1.0beta
  [ack] => Success
)

PHP Example for addFixedPriceItem

Add an item to Bonanza by providing the title, price, quantity, description, picture, category and shipping. You will also need to provide an authorization token in the $args. Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a secure API request and requires dev name and cert name headers. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print out the item ID. Print the full response.

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "https://api.bonanza.com/api_requests/secure_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$item['title'] = "My Item";
$item['price'] = 30.57;
$item['quantity'] = 1;
$item['description'] = "This item is great.  Any html here.";
$item['pictureDetails']['pictureURL'] = "http://www.google.com/images/logos/ps_logo2.png";
$item['primaryCategory']['categoryId'] = 377;
$item['itemSpecifics']['specifics'] = array();
$item['itemSpecifics']['specifics'][] = array('Condition', 'New');
$item['itemSpecifics']['specifics'][] = array('Genre', 'Romance');
$item['shippingDetails']['shippingServiceOptions']['freeShipping'] = true;
$args = array("item" => $item);
$args['requesterCredentials']['bonanzleAuthToken'] = $token;
$post_fields = "addFixedPriceItem=" .  urlencode(json_encode($args));
echo "Request: $post_fields \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
$itemId= $response['addFixedPriceItemResponse']['itemId'];
echo "itemId: $itemId \n";
echo "Response: \n";
print_r($response);
Request: addFixedPriceItem={"item":{"title":"My Item","price":30.57,"quantity":1,"description":"This item is great.  Any html here.","pictureDetails":{"pictureURL":"http:\/\/www.google.com\/images\/logos\/ps_logo2.png"},"primaryCategory":{"categoryId":377},"shippingDetails":{"shippingServiceOptions":{"freeShipping":true}}},"requesterCredentials":{"bonanzleAuthToken":"zzz"}}
itemId: 24018227
Response:
Array
(
  [timestamp] => 2010-12-16T06:40:01.000Z
  [addFixedPriceItemResponse] => Array
      (
          [sellingState] => Ready for sale
          [categoryId] => 377
          [itemId] => 24018227
      )
  [version] => 1.0beta
  [ack] => Success
)

PHP Example for addMultipleFixedPriceItems

Adding multiple fixed price items is like adding a single item with the addition of adding each item to an outer items array.

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "https://api.bonanza.com/api_requests/secure_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);

$items = array();
$item0['title'] = "My Item 0";
$item0['price'] = 30.57;
$item0['quantity'] = 1;
$item0['description'] = "This item is great.  Any html here.";
$item0['primaryCategory']['categoryId'] = 397;
$items[] = array("item" => $item0);  # important step is to identify each item with an "item" key

$item1['title'] = "My Item 1";
$item1['price'] = 30.57;
$item1['quantity'] = 1;
$item1['primaryCategory']['categoryId'] = 397;
$item1['description'] = "This item is great.  Any html here.";
$items[] = array("item" => $item1);  # important step is to identify each item with an "item" key

$args = array("items" => $items);
$args['requesterCredentials']['bonanzleAuthToken'] = $token;
$post_fields = "addMultipleFixedPriceItems=" .  urlencode(json_encode($args));

echo "Request: $post_fields \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);

$json_response = curl_exec($connection);

if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}

curl_close($connection);

$response = json_decode($json_response,true);
$itemId= $response['addFixedPriceItemResponse']['itemId'];
echo "itemId: $itemId \n";
echo "Response: \n";
print_r($response);

PHP Example for reviseFixedPriceItem

Revise item 24018227 to update the title, price and quantity. You will also need to provide an authorization token in the $args. Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a secure API request and requires dev name and cert name headers. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print the full response.

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "https://api.bonanza.com/api_requests/secure_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$itemId = 24018227;
$item = array();
$item['title'] = "My Item - revised";
$item['price'] = 30.99;
$item['quantity'] = 2;
$args = array("item" => $item, "itemId" => $itemId);
$args['requesterCredentials']['bonanzleAuthToken'] = $token;
$post_fields = "reviseFixedPriceItem=" .  urlencode(json_encode($args));
echo "Request: $post_fields \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "Response: \n";
print_r($response);
Request: reviseFixedPriceItem={"item":{"title":"My Item - revised","price":30.99,"quantity":2},"itemId":24018227,"requesterCredentials":{"bonanzleAuthToken":"zzz"}}
Response:
Array
(
  [timestamp] => 2010-12-16T09:29:01.000Z
  [reviseFixedPriceItemResponse] => Array
      (
          [sellingState] => Ready for sale
          [categoryId] => 377
          [itemId] => 24018227
      )
  [version] => 1.0beta
  [ack] => Success
)

PHP Example for getUnlistedItem

Get the details of the unlisted item with the item ID of 24018222. You will also need to provide an authorization token in the $args. Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a secure API request and requires dev name and cert name headers. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print the full response.

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "https://api.bonanza.com/api_requests/secure_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$itemId = 24018222;
$args = array("itemId" => $itemId);
$args['requesterCredentials']['bonanzleAuthToken'] = $token;
$post_fields = "getUnlistedItem=" .  json_encode($args);
echo "Request: $post_fields \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "Response: \n";
print_r($response);
Request: getUnlistedItem={"itemId":24018222,"requesterCredentials":{"bonanzleAuthToken":"zzz"}}
Response:
Array
(
  [timestamp] => 2010-12-16T09:54:40.000Z
  [getUnlistedItemResponse] => Array
      (
          [item] => Array
              (
                  [primaryCategory] => Array
                      (
                          [categoryName] => Books >> Fiction Books
                          [categoryId] => 377
                      )
                  [seller] => Array
                      (
                          [feedbackRatingStar] =>
                          [membershipLevel] =>
                          [sellerUserName] => MyUser
                          [availableForChat] => true
                          [userPicture] =>
                          [positiveFeedbackPercent] => 0.0
                      )
                  [convertedBuyItNowPrice] => 30.99
                  [paymentMethods] => Array
                      (
                      )
                  [listingType] => FixedPriceItem
                  [title] => My Item - revised
                  [quantity] => 2
                  [listingStatus] => Ready for sale
                  [country] => US
                  [currentPrice] => 30.99
                  [shippingCostSummary] => Array
                      (
                          [shippingServiceCost] => 0
                          [shippingType] => Free
                          [shipToLocations] => US
                      )
                  [buyItNowPrice] => 30.99
                  [itemID] => 24018222
                  [postalCode] => 98607
                  [pictureURL] => Array
                      (
                          [0] => http://bonanzleimages.s3.amazonaws.com/afu/images/9585/6344/ps_logo2.png
                      )
                  [description] => This item is great.  Any html here.
                  [galleryURL] => http://bonanzleimages.s3.amazonaws.com/afu/images/9585/6344/ps_logo2_thumb155_crop.png
                  [storeFront] => Array
                      (
                          [storeName] => MyUser booth
                          [storeDiscount] =>
                          [storeURL] => http://www.bonanza.com/booths/MyUser
                          [storeHasBonanza] => false
                          [storeItemCount] => 5
                      )
                  [lastChangeTime] => 2010-12-16T09:29:01.000Z
              )
      )
  [version] => 1.0beta
  [ack] => Success
)

PHP Example for updateBooth

The updateBooth call has only 1 input, which is the token. Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a secure API request and requires dev name, cert name, and an authorization token. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print the response.

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "https://api.bonanza.com/api_requests/secure_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$args = array();
$args['requesterCredentials']['bonanzleAuthToken'] = $token;
$post_fields = "updateBoothRequest=" .  json_encode($args, JSON_HEX_AMP);
echo "Request: $post_fields \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "Response: \n";
print_r($response);
Request: updateBoothRequest={"requesterCredentials":{"bonanzleAuthToken":"zzz"}}
Response:
Array
(
  [updateBoothResponse] => Array
      (
          [success] => 1
          [resultMessage] => Booth queued for update
      )
  [timestamp] => 2010-12-11T17:05:20.000Z
  [version] => 1.0beta
  [ack] => Success
)

Get the checkout link for 3 items 404027,404175 and 23997948. Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a standard API request and requires only a dev name header. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print out the link. Print the full response.

$dev_name = "xxx";
$api_url = "https://api.bonanza.com/api_requests/standard_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$ids = array(404027,404175,23997948);
$args = array("itemIds" => $ids);
$post_fields = "getCheckoutLinkRequest=" .  json_encode($args);
echo "Request: $post_fields \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
$url = $response['getCheckoutLinkResponse']['checkoutUrl'];
echo "url: $url  \n";
echo "Response: \n";
print_r($response);
Request: getCheckoutLinkRequest={"itemIds":[404027,404175,23997948]}
url: https://www.bonanza.com/offers/make_cart_from_items?item_ids=404027,404175,23997948
Response:
Array
(
  [timestamp] => 2010-12-15T12:51:30.000Z
  [getCheckoutLinkResponse] => Array
      (
          [checkoutUrl] => https://www.bonanza.com/offers/make_cart_from_items?item_ids=404027,404175,23997948
      )
  [version] => 1.0beta
  [ack] => Success
)

PHP Example for getUserProfile

Get the feedback and rating information for the user with the ID of "hollee". Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a standard API request and requires only a dev name header. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print out the users rating and star information. Print the full response.

$dev_name = "xxx";
$api_url = "https://api.bonanza.com/api_requests/standard_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$args = array("userId" => "BluePennyLady");
$post_fields = "getUserProfileRequest=" .  json_encode($args, JSON_HEX_AMP);
echo "Request: $post_fields \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
$rating = $response['getUserProfileResponse']['feedbackHistory']['averageRatingDetails']['rating'];
$star = $response['getUserProfileResponse']['user']['feedbackRatingStar'];
echo "Rating: $rating  Star: $star \n";
echo "Response: \n";
print_r($response);
Request: getUserProfileRequest={"userId":"hollee"}
Rating: 99.9  Star: Red
Response:
Array
(
  [getUserProfileResponse] => Array
      (
          [feedbackHistory] => Array
              (
                  [uniquePositiveFeedbackCount] => 5000
                  [uniqueNeutralFeedbackCount] => 8
                  [uniqueNegativeFeedbackCount] => 3
                  [averageRatingDetails] => Array
                      (
                          [rating] => 99.9
                          [ratingCount] => 4997
                      )
              )
          [user] => Array
              (
                  [newUser] => true
                  [feedbackRatingStar] => Red
                  [aboutMeURL] => https://www.bonanza.com/users/2163/profile
                  [userId] => 2163
                  [feedbackDetailsURL] => https://www.bonanza.com/users/2163/user_feedbacks
                  [status] => active
                  [registrationDate] => 2008-09-02T06:33:06.000Z
              )
      )
  [timestamp] => 2010-12-15T12:23:31.000Z
  [version] => 1.0beta
  [ack] => Success
)

PHP Example for getSingleItem

Get the data for the Bonanza item ID 23266642. Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a standard API request and requires only a dev name header. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print the response.

$dev_name = "xxx";
$api_url = "https://api.bonanza.com/api_requests/standard_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$args = array("itemId" => "23266642");
$post_fields = "getSingleItemRequest=" .  json_encode($args, JSON_HEX_AMP);
echo "Request: $post_fields \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "Response: \n";
print_r($response);
Request: getSingleItem={"itemId":"23266642"} 
Response:
Array (
  [timestamp] => 2010-12-11T17:00:23.000Z
  [version] => 1.0beta
  [getSingleItemResponse] => Array
      (
          [item] => Array
              (
                  [primaryCategory] => Array
                      (
                          [categoryName] => Clothing, Shoes amp; Accessories >> Women's Accessories amp; Handbags >> Hats >> Beret, Newsboy
                          [categoryId] => 45233
                      )
                  [seller] => Array
                      (
                          [feedbackRatingStar] => Red
                          [membershipLevel] => 2
                          [sellerUserName] => samiamsxa
                          [availableForChat] => false
                          [userPicture] => http://bonanzleimages.s3.amazonaws.com/user_profile_image/afu/user_profile_images/0049/1894/thriftyvaultwithnameTM-2-1.jpg
                          [positiveFeedbackPercent] => 100
                      )
                  [convertedBuyItNowPrice] => 14.99
                  [paymentMethods] => Array
                      (
                          [0] => GoogleCheckout
                          [1] => MOCC
                          [2] => Paypal
                      )
                  [listingType] => FixedPriceItem
                  [title] => Red Crochet Beret Winter Hat
                  [quantity] => 1
                  [listingStatus] => Active
                  [country] => US
                  [currentPrice] => 14.99
                  [shippingCostSummary] => Array
                      (
                          [shippingServiceCost] => 3.5
                          [shippingType] => Flat
                          [shipToLocations] => US
                      )
                  [buyItNowPrice] => 14.99
                  [itemSpecifics] => Array
                      (
                          [0] => Array
                              (
                                  [nameValueList] => Array
                                      (
                                          [name] => Condition
                                          [value] => New: With Tags
                                      )
                              )
                      )
                  [itemID] => 23266642
                  [postalCode] => 70535
                  [pictureURL] => Array
                      (
                          [0] => http://s3.amazonaws.com/bonanzleimages/afu/images/9157/4427/red_crochet_beret_hat.jpg
                      )
                  [description] => Red Crochet Beret Winter Hat, brand new. One size fits most. Other colors available in store.
                  [galleryURL] => http://s3.amazonaws.com/bonanzleimages/afu/images/9157/4427/red_crochet_beret_hat_thumb155_crop.jpg
                  [storeFront] => Array
                      (
                          [storeName] => Thrifty VaultƃĀ¢Ć¢??ƂĀ¢ booth
                          [storeDiscount] => 
                          [storeURL] => http://www.bonanza.com/booths/samiamsxa
                          [storeHasBonanza] => false
                          [storeItemCount] => 1424
                      )
                  [lastChangeTime] => 2010-11-26T23:57:40.000Z
              )
      )
  [ack] => Success
)

PHP Example for getMultipleItems

Get the data for 2 Bonanza items with IDS of 404027 and 404175. Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a standard API request and requires only a dev name header. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Loop thru the returned data and print the price and title of each item. Print the full response.

$dev_name = "xxx";
$api_url = "https://api.bonanza.com/api_requests/standard_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$ids = array(404027,404175);
$args = array("itemId" =>  $ids);
$post_fields = "getMultipleItemsRequest=" .  json_encode($args, JSON_HEX_AMP);
echo "Request: $post_fields \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "  Loop thru the data \n";
while (list(,$item) = each($response['getMultipleItemsResponse']['item'])) {
  echo "  " . $item['currentPrice'] . " - " . $item['title'] . "\n";
}
echo "Response: \n";
print_r($response);
Request: getMultipleItemsRequest={"itemId":[404027,404175]}
Loop thru the data
599.99 - Vintge HAWAIIAN HULA Dancer RHINESTONE ENAMEL Fur Clips
20 - RETRO Vintage MINT GREEN ENAMEL on METAL HOOP Earrings
Response:
Array
(
  [timestamp] => 2010-12-15T12:10:05.000Z
  [version] => 1.0beta
  [getMultipleItemsResponse] => Array
      (
          [item] => Array
              (
                  [0] => Array
                      (
                          [primaryCategory] => Array
                              (
                                  [categoryName] => Jewelry amp; Watches >> Vintage amp; Antique Jewelry
                                  [categoryId] => 48579
                              )
                          [seller] => Array
                              (
                                  [feedbackRatingStar] => Red
                                  [membershipLevel] =>
                                  [sellerUserName] => hollee
                                  [availableForChat] => false
                                  [userPicture] => http://s3.amazonaws.com/bonanzleimages/user_profile_image/afu/user_profile_images/0036/7420/photo-147.jpg
                                  [positiveFeedbackPercent] => 99.9
                              )
                          [convertedBuyItNowPrice] => 599.99
                          [paymentMethods] => Array
                              (
                                  [0] => Paypal
                              )
                          [listingType] => FixedPriceItem
                          [title] => Vintge HAWAIIAN HULA Dancer RHINESTONE ENAMEL Fur Clips
                          [quantity] => 1
                          [listingStatus] => Active
                          [country] => US
                          [currentPrice] => 599.99
                          [shippingCostSummary] => Array
                              (
                                  [shippingServiceCost] => 8
                                  [shippingType] => Flat
                                  [shipToLocations] => US
                              )
                          [buyItNowPrice] => 599.99
                          [itemID] => 404027
                          [postalCode] => 07722
                          [pictureURL] => Array
                              (
                                  [0] => http://bonanzleimages.s3.amazonaws.com/afu/images/0155/7677/hulaclips707gall.jpg
                              )
                          [description] => ...
                          [galleryURL] => http://bonanzleimages.s3.amazonaws.com/afu/images/0155/7677/hulaclips707gall_thumb155_crop.jpg
                          [storeFront] => Array
                              (
                                  [storeName] => hollee's booth
                                  [storeDiscount] =>
                                  [storeURL] => http://www.bonanza.com/booths/hollee
                                  [storeHasBonanza] => false
                                  [storeItemCount] => 620
                              )
                          [lastChangeTime] => 2010-11-18T21:33:42.000Z
                      )
                  [1] => Array
                      (
                          [primaryCategory] => Array
                              (
                                  [categoryName] => Jewelry amp; Watches >> Vintage amp; Antique Jewelry
                                  [categoryId] => 48579
                              )
                          [seller] => Array
                              (
                                  [feedbackRatingStar] => Red
                                  [membershipLevel] =>
                                  [sellerUserName] => hollee
                                  [availableForChat] => false
                                  [userPicture] => http://s3.amazonaws.com/bonanzleimages/user_profile_image/afu/user_profile_images/0036/7420/photo-147.jpg
                                  [positiveFeedbackPercent] => 99.9
                              )
                          [convertedBuyItNowPrice] => 20
                          [paymentMethods] => Array
                              (
                                  [0] => Paypal
                              )
                          [listingType] => FixedPriceItem
                          [title] => RETRO Vintage MINT GREEN ENAMEL on METAL HOOP Earrings
                          [quantity] => 1
                          [listingStatus] => Active
                          [country] => US
                          [currentPrice] => 20
                          [shippingCostSummary] => Array
                              (
                                  [shippingServiceCost] => 3
                                  [shippingType] => Flat
                                  [shipToLocations] => US
                              )
                          [buyItNowPrice] => 20
                          [itemID] => 404175
                          [postalCode] => 07722
                          [pictureURL] => Array
                              (
                                  [0] => http://s3.amazonaws.com/bonanzleimages/afu/images/0155/8535/grnenamhoopears808gall.jpg
                              )
                          [description] => ....
                          [galleryURL] => http://s3.amazonaws.com/bonanzleimages/afu/images/0155/8535/grnenamhoopears808gall_thumb155_crop.jpg
                          [storeFront] => Array
                              (
                                  [storeName] => hollee's booth
                                  [storeDiscount] =>
                                  [storeURL] => http://www.bonanza.com/booths/hollee
                                  [storeHasBonanza] => false
                                  [storeItemCount] => 620
                              )
                          [lastChangeTime] => 2008-10-20T10:26:46.000Z
                      )
              )
      )
  [ack] => Success
)

PHP Example for getBooth

Get the booth for the user ID "rooms_delivered". Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a standard API request and requires only a dev name header. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print the response.

$dev_name = "xxx";
$api_url = "https://api.bonanza.com/api_requests/standard_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$args = array("userId" => "rooms_delivered");
$post_fields = "getBoothRequest=" .  json_encode($args, JSON_HEX_AMP);
echo "Request: $post_fields \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "Response: \n";
print_r($response);
Request: getBoothRequest={"userId":"rooms_delivered"}
Response:
Array
(
  [timestamp] => 2010-12-15T06:41:27.000Z
  [getBoothResponse] => Array
      (
          [store] => Array
              (
                  [subscriptionLevel] => 0
                  [name] => rooms-delivered's booth
                  [url] => http://www.bonanza.com/booths/rooms_delivered
                  [logo] => Array
                      (
                          [url] => http://bonanzapublic.s3.amazonaws.com/images/booth/template_images/Paintbrushes.jpg
                      )
                  [lastUpdated] => 2010-12-06T15:58:15.000Z
                  [policies] =>
                  [description] =>
                  [syndicated] => false
              )
      )
  [version] => 1.0beta
  [ack] => Success
)

PHP Example for getBoothItems

Retrieve items from a specified booth by providing the booth id and - optionally - the statuses of the items you want returned. You can page through all items in a booth by also specifying the page number to retrieve and/or the number of items to list per page. You will also need to provide an authorization token in the $args.

Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a secure API request and requires dev name and cert name headers. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print out the item ID. Print the full response.

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "https://api.bonanza.com/api_requests/secure_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$args = array( 'userId' => 'rooms_delivered', 'itemStatus' => array('for_sale', 'ready_to_post'), 'itemsPerPage' => 10, 'page' => 2);
$args['requesterCredentials']['bonanzleAuthToken'] = $token;   // only necessary if specifying an itemStatus other than "for_sale"
$request_name = "getBoothItemsRequest";
$post_fields = "$request_name=" . json_encode($args) . " \n";
echo "Request: $post_fields \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  // data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "Response: \n";
print_r($response);
Request: getBoothItemsRequest
Response:
Array
(
  [timestamp] => 2010-12-15T12:10:05.000Z
  [version] => 1.0beta
  [getBoothItemsRequest] => Array
      (
          [currentPage] => 2,
          [size] => 10,
          [totalEntries] => 37,
          [items] => Array
              (
                  [0] => Array
                      (
                          [primaryCategory] => Array
                              (
                                  [categoryName] => Jewelry amp; Watches >> Vintage amp; Antique Jewelry
                                  [categoryId] => 48579
                              )
                          [seller] => Array
                              (
                                  [feedbackRatingStar] => Red
                                  [membershipLevel] =>
                                  [sellerUserName] => hollee
                                  [availableForChat] => false
                                  [userPicture] => http://s3.amazonaws.com/bonanzleimages/user_profile_image/afu/user_profile_images/0036/7420/photo-147.jpg
                                  [positiveFeedbackPercent] => 99.9
                              )
                          [convertedBuyItNowPrice] => 599.99
                          [paymentMethods] => Array
                              (
                                  [0] => Paypal
                              )
                          [listingType] => FixedPriceItem
                          [title] => Vintge HAWAIIAN HULA Dancer RHINESTONE ENAMEL Fur Clips
                          [quantity] => 1
                          [listingStatus] => Active
                          [country] => US
                          [currentPrice] => 599.99
                          [shippingCostSummary] => Array
                              (
                                  [shippingServiceCost] => 8
                                  [shippingType] => Flat
                                  [shipToLocations] => US
                              )
                          [buyItNowPrice] => 599.99
                          [itemID] => 404027
                          [postalCode] => 07722
                          [pictureURL] => Array
                              (
                                  [0] => http://bonanzleimages.s3.amazonaws.com/afu/images/0155/7677/hulaclips707gall.jpg
                              )
                          [description] => ...
                          [galleryURL] => http://bonanzleimages.s3.amazonaws.com/afu/images/0155/7677/hulaclips707gall_thumb155_crop.jpg
                          [storeFront] => Array
                              (
                                  [storeName] => hollee's booth
                                  [storeDiscount] =>
                                  [storeURL] => http://www.bonanza.com/booths/hollee
                                  [storeHasBonanza] => false
                                  [storeItemCount] => 620
                              )
                          [lastChangeTime] => 2010-11-18T21:33:42.000Z
                      )
                 ...
              )
      )
  [ack] => Success
)

PHP Example for getCategories

Get the child categories of the "Baby" category (ID 2984). Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a standard API request and requires only a dev name header. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Loop thru the data and print child category ID and Name. Print the response.

$dev_name = "xxx";
$api_url = "https://api.bonanza.com/api_requests/standard_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$args = array("categoryParent" => 2984);
$post_fields = "getCategoriesRequest=" .  json_encode($args, JSON_HEX_AMP);
echo "Request: $post_fields \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "  Loop thru the data \n";
while (list(,$category) = each($response['getCategoriesResponse']['categoryArray'])) {
  echo "  " . $category['categoryId'] . " - " . $category['categoryName'] . "\n";
}
echo "Response: \n";
print_r($response);
Request: getCategoriesRequest={"categoryParent":2984}
Loop thru the data
1261 - Baby >> Other
19068 - Baby >> Toys for Baby
20394 - Baby >> Bathing & Grooming
20400 - Baby >> Feeding
20416 - Baby >> Nursery Bedding
20422 - Baby >> Nursery Furniture
20433 - Baby >> Baby Safety & Health
37631 - Baby >> Potty Training
45455 - Baby >> Diapering
48757 - Baby >> Wholesale Lots
66692 - Baby >> Car Safety Seats
66697 - Baby >> Nursery Decor
66698 - Baby >> Strollers
100223 - Baby >> Baby Gear
117388 - Baby >> Keepsakes & Baby Announcements
Response:
Array
(
  [getCategoriesResponse] => Array
      (
          [categoryArray] => Array
              (
                  [0] => Array
                      (
                          [categoryName] => Baby >> Other
                          [traitCount] => 1
                          [categoryId] => 1261
                          [categoryBriefName] => Other
                          [leafCategory] => true
                          [categoryLevel] => 2
                      )
                  [1] => Array
                      (
                          [categoryName] => Baby >> Toys for Baby
                          [traitCount] => 1
                          [categoryId] => 19068
                          [categoryBriefName] => Toys for Baby
                          [leafCategory] => false
                          [categoryLevel] => 2
                      )
                  [2] => Array
                      (
                          [categoryName] => Baby >> Bathing & Grooming
                          [traitCount] => 1
                          [categoryId] => 20394
                          [categoryBriefName] => Bathing & Grooming
                          [leafCategory] => false
                          [categoryLevel] => 2
                      )
                   ....
              )
      )
  [timestamp] => 2010-12-15T07:09:09.000Z
  [version] => 1.0beta
  [ack] => Success
)

PHP Example for getCategoryTraits

Get the traits for the category "Books >> Fiction Books" (ID 377). This is a LEAF category. Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a standard API request and requires only a dev name header. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Loop thru the data and print trait ID and label. Print the response.

$dev_name = "xxx";
$api_url = "https://api.bonanza.com/api_requests/standard_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$args = array("categoryId" => 377);
$post_fields = "getCategoryTraitsRequest=" .  json_encode($args, JSON_HEX_AMP);
echo "Request: $post_fields \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "  Loop thru the data \n";
while (list(,$trait) = each($response['getCategoryTraitsResponse']['traitArray'])) {
  echo "  " . $trait['id'] . " - " . $trait['label'] . "\n";
}
echo "Response: \n";
print_r($response);
Request: getCategoryTraitsRequest={"categoryId":377}
Loop thru the data
6248 - Condition
6249 - Format
6250 - Publication Year
6251 - Category
6254 - Special Attributes
6255 - Author
6256 - ISBN
6257 - Edition
6258 - Edition Description
6259 - Publisher
85886 - 1st Edition
85887 - Signed
95592 - Age Range
Response:
Array
(
  [timestamp] => 2010-12-15T07:27:42.000Z
  [getCategoryTraitsResponse] => Array
      (
          [traitArray] => Array
              (
                  [0] => Array
                      (
                          [label] => Condition
                          [parentTraitId] => 0
                          [id] => 6248
                          [traitValues] => Array
                              (
                                  [0] => Array
                                      (
                                          [name] => -
                                          [displayOrder] => 7
                                          [searchId] => 102439990
                                          [id] => 70742
                                      )
                                  [1] => Array
                                      (
                                          [name] => Brand New
                                          [displayOrder] => 2
                                          [searchId] => 102450425
                                          [id] => 70743
                                      )
                                  [2] => Array
                                      (
                                          [name] => Like New
                                          [displayOrder] => 3
                                          [searchId] => 102535784
                                          [id] => 70744
                                      )
                                  ....
                              )
                          [htmlInputType] => dropdown
                      )
                  [1] => Array
                      (
                          [label] => Format
                          [parentTraitId] => 0
                          [id] => 6249
                          [traitValues] => Array
                              (
                                  [0] => Array
                                      (
                                          [name] => -
                                          [displayOrder] => 1000
                                          [searchId] => 159609990
                                          [id] => 70748
                                      )
                                  [1] => Array
                                      (
                                          [name] => Hardcover
                                          [displayOrder] => 1000
                                          [searchId] => 159633732
                                          [id] => 70749
                                      )
                                  [2] => Array
                                      (
                                          [name] => Softcover
                                          [displayOrder] => 1000
                                          [searchId] => 159633733
                                          [id] => 70750
                                      )
                                  [3] => Array
                                      (
                                          [name] => Mixed Lot
                                          [displayOrder] => 1000
                                          [searchId] => 159633752
                                          [id] => 70751
                                      )
                                  [4] => Array
                                      (
                                          [name] => Other
                                          [displayOrder] => 1000
                                          [searchId] => 159609994
                                          [id] => 70752
                                      )
                              )
                          [htmlInputType] => dropdown
                      )
                  [2] => Array
                      (
                          [label] => Publication Year
                          [parentTraitId] => 0
                          [id] => 6250
                          [htmlInputType] => textfield
                      )
                 ....
              )
      )
  [version] => 1.0beta
  [ack] => Success
)

PHP Example for findItemsByKeywords

Find the items on Bonanza related to the keywords "Levis Boot Cut" and show page 1 with 5 on a page. Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a standard API request and requires only a dev name header. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Loop thru the data and print item location and title. Print the full response.

$dev_name = "xxx";
$api_url = "https://api.bonanza.com/api_requests/standard_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$paginationInput['entriesPerPage'] = 5;
$paginationInput['pageNumber'] = 1;
$args = array("paginationInput"=> $paginationInput, "keywords" => "Levis Boot Cut");
$post_fields = "findItemsByKeywordsRequest=" .  json_encode($args);
echo "Request: $post_fields \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "  Loop thru the data \n";
while (list(,$item) = each($response['findItemsByKeywordsResponse']['item'])) {
  echo "  " . $item['location'] . " - " . $item['title'] . "\n";
}
echo "Response: \n";
print_r($response);
Request: findItemsByKeywordsRequest={"paginationInput":{"entriesPerPage":5,"pageNumber":1},"keywords":"Levis Boot Cut"}
Loop thru the data
  Lutz, FL - 36X36 Levi Strauss & Co. Low Boot Cut Jeans NWT 36 X 36
  Birmingham, AL - LEVIS 517 Women's Slim Fit Boot Cut Blue Jeans Pants 9 Jr. M
  Texas - LEVI'S LEVIS Boot Cut Super Low Stretch Jeans Jrs 5 NWT
  Leopold, IN - Womens Blue Jeans Levi's 523 Boot Cut nouveau Low SZ 12
  Nashville, TN - Levi's 518 Superlow Boot Cut Jeans Juniors 9M
Response:
Array
(
  [timestamp] => 2010-12-16T13:55:52.000Z
  [version] => 1.0beta
  [findItemsByKeywordsResponse] => Array
      (
          [paginationOutput] => Array
              (
                  [totalEntries] => 64
                  [pageNumber] => 1
                  [entriesPerPage] => 5
              )
          [item] => Array
              (
                  [0] => Array
                      (
                          [primaryCategory] => Array
                              (
                                  [categoryName] => Clothing, Shoes amp; Accessories >> Men's Clothing >> Big amp; Tall >> Jeans
                                  [categoryId] => 155177
                              )
                          [listingInfo] => Array
                              (
                                  [price] => 14.99
                                  [convertedBuyItNowPrice] => 14.99
                                  [bestOfferEnabled] => false
                                  [listingType] => FixedPrice
                                  [buyItNowPrice] => 14.99
                                  [startTime] => 2010-12-15T20:10:41.000Z
                                  [lastChangeTime] => 2010-12-15T20:10:41.000Z
                              )
                          [viewItemURL] => http://www.bonanza.com/booths/espiwear/items/36X36_Levi_Strauss___Co__Low_Boot_Cut_Jeans_NWT_36_X_36
                          [location] => Lutz, FL
                          [title] => 36X36 Levi Strauss & Co. Low Boot Cut Jeans NWT 36 X 36
                          [sellerInfo] => Array
                              (
                                  [feedbackRatingStar] => Green
                                  [membershipLevel] => 2
                                  [sellerUserName] => espiwear
                                  [availableForChat] => true
                                  [userPicture] => http://s3.amazonaws.com/bonanzleimages/user_profile_image/afu/user_profile_images/0041/3750/logo_Espi.jpg
                                  [positiveFeedbackPercent] => 100
                              )
                          [affiliateCommission] => Array
                              (
                                  [enabled] => false
                              )
                          [itemId] => 24009380
                          [storeInfo] => Array
                              (
                                  [storeName] => ESPIWEAR CLOTHING 813-477-2215
                                  [storeDiscount] =>
                                  [storeURL] => http://www.bonanza.com/booths/espiwear
                                  [storeHasBonanza] => false
                                  [storeItemCount] => 1052
                              )
                          [shippingInfo] => Array
                              (
                                  [shippingServiceCost] =>
                                  [shippingType] => NotSpecified
                                  [shipToLocations] => US
                              )
                          [sellingStatus] => Array
                              (
                                  [convertedCurrentPrice] => 14.99
                                  [sellingState] => Active
                                  [currentPrice] => 14.99
                              )
                          [postalCode] => 33548
                          [paymentMethod] => Array
                              (
                                  [0] => MOCC
                                  [1] => Paypal
                              )
                          [galleryURL] => http://bonanzleimages.s3.amazonaws.com/afu/images/9580/3653/_b__j_9gbwk___kgrhqv__leez_5hpmtebnbvrppf5g__0_3_thumb155_crop.jpg
                          [globalId] => BONANZLE
                          [descriptionBrief] =>                                         36X36 Levi Strauss amp Co. Low Boot Cut Jeans NWT 36 X 36                Condition: New with tags, guaranteed to be 100 authentic Features: Levi Strauss amp Co. Low Boot Cut Low Rise Original Riveted 527 J...
                      )
                  ...
              )
      )
  [ack] => Success
)

PHP Example for setNotificationPreferences

Specify the delivery endpoint to receive notifications, and list the notifications to subscribe to (e.g. "askSellerQuestion"). Build the API request in a simple associative array in $args. JSON encode the $args in the variable $post_fields. This call is a secure API request and requires dev name and cert name headers. Set the HTTP headers in $headers. Use CURL to send the API request. Decode the JSON response into an associative array $response. Print the full response.

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "https://api.bonanza.com/api_requests/secure_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);

$delivery_preferences = array();
$delivery_preferences['applicationEnable'] = "Enable";
$delivery_preferences['deliveryURLDetails'] = array(
  'deliveryURL' => "http://foo.com/notifications",
  'status' => "Enable" 
);

$subscribed_notifications = array('notificationEnable' => array());
$notification = array(
  'eventEnable' => "Enable",
  'eventType' => "askSellerQuestion",
  'detailed' => true
);
array_push($subscribed_notifications['notificationEnable'], $notification);

$args = array('applicationDeliveryPreferences' => $delivery_preferences, 'userDeliveryPreferenceArray' => $subscribed_notifications);
$args['requesterCredentials']['bonanzleAuthToken'] = $token;
$post_fields = "setNotificationPreferences=" .  json_encode($args);
echo "Request: $post_fields \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "Response: \n";
print_r($response);
Request: setNotificationPreferences={"applicationDeliveryPreferences":{"applicationEnable":"Enable","deliveryURLDetails":{"deliveryURL":"http:\/\/foo.com\/notifications","status":"Enable"}},"userDeliveryPreferenceArray":{"notificationEnable":[{"eventEnable":"Enable","eventType":"askSellerQuestion","detailed":true}]},"requesterCredentials":{"bonanzleAuthToken":"XehKe4HUVP"}}
Response:
Array
(
    [ack] => Success
    [version] => 1.0
    [timestamp] => 2018-02-20T11:38:49.000Z
    [setNotificationPreferencesResponse] => Array
        (
            [notificationId] => 69537
            [deliveryURLsProcessed] => 1
            [eventsProcessed] => 1
        )

)

PHP Example for updateInventory

Update the price and quantity for Bonanza ItemĀ 1234, and update the quantity for Bonanza ItemĀ 5678 in the same request.

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "https://api.bonanza.com/api_requests/secure_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$updates = array();
$updates["1234"] = array("quantity" => 12, "price" => 14.99);
$updates["5678"] = array("quantity" => 3);
$args = array("updates" => $updates);
$args["requesterCredentials"]["bonanzleAuthToken"] = $token;
$post_fields = "updateInventory=" .  urlencode(json_encode($args));
echo "Request: $post_fields \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "Response: \n";
print_r($response);
Request: updateInventory=%7B%22updates%22%3A%7B%22782383635%22%3A%7B%22quantity%22%3A12%2C%22price%22%3A14.99%7D%2C%22782383633%22%3A%7B%22quantity%22%3A3%7D%7D%2C%22requesterCredentials%22%3A%7B%22bonanzleAuthToken%22%3A%22AnOz8BOaaP%22%7D%7D
Response:
Array
(
    [ack] => Success
    [version] => 1.1.2
    [timestamp] => 2020-02-27T15:56:52.000Z
    [updateInventoryResponse] => Array
        (
            [1234] => Array
                (
                    [success] => 1
                )
            [5678] => Array
                (
                    [success] => 1
                )
        )
)

PHP Examples - Functions That Can Speed Development

PHP Examples - Basic Functions

These 4 functions will help to make API calls using PHP. You can hide a lot of the details when making an API call. See the sample usage below.

# $dev_name = developer name (ID)
# $cert_name = certificate name (ID)
function BonapititSecureApiCall($dev_name, $cert_name, $api_call_and_args) {
  $url = "https://api.bonanza.com/api_requests/secure_request";
  $headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
  $resp = BonapititSendHttpRequest($url,$headers, $api_call_and_args);
  return $resp;
}
# $dev_name = developer ID
# $api_call_and_args - string of the form: api_call={json_data}
function BonapititStandardApiCall($dev_name, $api_call_and_args) {
  $url = "https://api.bonanza.com/api_requests/standard_request";
  $headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
  $resp = BonapititSendHttpRequest($url,$headers, $api_call_and_args);
  return $resp;
}
# $url - string - url of the bonanza api
# $headers - string - http headers containing X-BONANZLE-API-DEV-NAME and/or X-BONANZLE-API-CERT-NAME
# $post_fields - string - data that will be posted to the $url.
function BonapititSendHttpRequest($url, $headers, $post_fields) {
  $connection = curl_init();
  curl_setopt($connection, CURLOPT_URL, $url);
  curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);  //stop CURL from verifying the peer's certificate
  curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($connection, CURLOPT_HTTPHEADER, $headers); //set the headers using the array of headers
  curl_setopt($connection, CURLOPT_POST, 1);  //set method as POST
  curl_setopt($connection, CURLOPT_POSTFIELDS, $post_fields);
  curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);  //set it to return the transfer as a string from curl_exec
  $response = curl_exec($connection);
  curl_close($connection);
  return $response;
}
# $api_call_name - string - like UpdateBooth
# $assoc_array - array - associative array of data
function BonapititBuildRequest($api_call_name, $assoc_array) {
  $request_name = $api_call_name . "Request";
  $json = json_encode($assoc_array, JSON_HEX_AMP);
  $request = $request_name . "=" .  $json;
  return $request;
}

PHP Examples - Usage of functions for updateBooth

Use the Bonapitit functions (above) to update the booth. Build the $request. Make the secure API call. Use JSON to decode the response. Print the full response.

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$args = array();
$args['requesterCredentials']['bonanzleAuthToken'] = $token;
$request = BonapititBuildRequest("updateBooth",$args);
$json_response = BonapititSecureApiCall($dev_name, $cert_name, $request);
$response = json_decode($json_response,true);
print_r($response);

PHP Examples - Usage of functions for getSingleItem

Use the Bonapitit functions (above) to get the item ID 23266642. Build the getSingle Item $request. Make the standard API call. Use JSON to decode the response. Print the full response.

$dev_name = "xxx";
$args = array("itemId" => "23266642");
$request = BonapititBuildRequest("getSingleItem",$args);
$json_response =  BonapititStandardApiCall($dev_name, $request);
$response = json_decode($json_response,true);
print_r($response);