-1

I am looking for PHP samples on the Sales Maximizes API for ebay. (Formally called the Related Items API).

However, the details for this particular API seem to be scattered unlike other eBay API's. Is there a source with a simple PHP call to create a product bundle or fetch a product bundle?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
hitwill
  • 575
  • 1
  • 9
  • 25
  • Please read [What topics can I ask about](http://stackoverflow.com/help/on-topic) and [How to ask a good question](http://stackoverflow.com/help/how-to-ask) and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) – RiggsFolly Feb 08 '17 at 22:52
  • Thanks for the comment @RiggsFolly. Please read [How do I write a good answer](http://stackoverflow.com/help/how-to-answer) :-) – hitwill Feb 09 '17 at 01:11
  • I did, thanks for the comment. But here is the problem. _Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem_ ___and what has been done so far to solve it.___ – RiggsFolly Feb 09 '17 at 13:25
  • 1
    @RiggsFolly - Thanks Riggs - I understand now!!!! Great community, nice to keep it clean – hitwill Feb 09 '17 at 21:03

1 Answers1

0

If you are familiar with using Composer for PHP there is a SDK available at https://github.com/davidtsadler/ebay-sdk-php, that will help with using the eBay API. (Full disclosure: I'm the author of the SDK).

Below is an example of how to create a bundle using the Related Items service. In order to use the example you will need your developer App, Cert and Dev IDs for the sandbox environment. You also require an auth token for the sandbox eBay seller that you wish to create bundles for.

Please note that while the SDK makes it easier to integrate with the API, it will not teach you everything about it. It's important that you read the documentation for the createBundles operation to see what fields and options are available.

Examples of how to find and delete bundles can also be found at https://github.com/davidtsadler/ebay-sdk-examples/tree/master/related-items

<?php

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

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

/**
 * Request to the API are made through a service object.
 */
$service = new Services\RelatedItemsManagementService([
    'credentials' =>  [
        'appId'  => 'your-app-id',
        'certId' => 'your-cert-id',
        'devId'  => 'your-dev-id'
    ],
    'authToken'   => 'your-auth-token',
    'globalId'    => Constants\GlobalIds::US,
    'sandbox'     => true
]);

$request = new Types\CreateBundlesRequest();

/**
 * A bundle has a primary product and related products in the bundle.
 */
$bundle = new Types\Bundle();
$bundle->bundleName = "Example Bundle";
$bundle->primarySKU = ['123456789'];
$bundle->scheduledStartTime = new \DateTime('2017-03-01 00:00:00', new \DateTimeZone('UTC'));
$bundle->scheduledEndTime = new \DateTime('2017-03-07 00:00:00', new \DateTimeZone('UTC'));

/**
 * Add two products that will be bundled with the main product.
 */
$group = new Types\RelatedProductGroup();
$group->groupName = "Example Group";

$product = new Types\RelatedProduct();
$product->SKU = 'AAABBBCCC';
$group->relatedProduct[] = $product;

$product = new Types\RelatedProduct();
$product->SKU = 'DDDEEEFFF';
$group->relatedProduct[] = $product;

$bundle->relatedProductGroup[] = $group;

$request->bundle[] = $bundle;

/**
 * Send the request.
 */
$response = $service->createBundles($request);

/**
 * Output the result of the operation.
 */
foreach ($response->bundleStatus as $bundleStatus) {
    if ($bundleStatus->ack !== 'Failure') {
        printf(
            "Bundle Created (%s) %s\n",
            $bundleStatus->bundleID,
            $bundleStatus->bundleName
        );
    }
}
  • Thank you this is fantastic! This is exactly what I was looking for, and I felt that the ebay documentation on the bundles was a bit lacking – hitwill Feb 11 '17 at 04:29
  • @david-t-sadler This is a really great tool - However, I seem to be running into the following error from eBay: _ Uncaught exception 'GuzzleHttp\Exception\ServerException' with message 'Server error: `POST https://svcs.ebay.com/services/sellerinventory/v1/BundleManagementService` resulted in a `500 Internal Server Error_ Any thoughts? – hitwill Feb 13 '17 at 21:28
  • At the moment I would suggest that you ensure the correct credentials for the environment are been used. Sandbox credentials and authtokens won't work on the production server and vice versa. –  Feb 13 '17 at 22:18