Edward Ocampo-Gooding 06/18/2010

Official PHP adapter for Shopify API

[Note: This adapter has since been deprecated; use the awesome community-supported adapters instead.]

We’re happy to announce the open source release of an official PHP adapter for the Shopify API. It’s got all the bells and whistles of its Ruby counterpart to help you create great applications for release in the Shopify App Store.

Forget having to write installation & authentication code yourself. Generating an installation link and redirecting the merchant to a screen asking for permission to access their shop’s data is now just these two lines:

$api = new Session('mystore.myshopify.com', '', 'YOUR_API_KEY', 'YOUR_SECRET');
header("Location: " $api->create_permission_url());

After the merchant gives your app permission to access their data, Shopify redirects the user to the return URL you set up for your app, along with their shop name, token and signature.

Finish authentication by passing the shop name, token, and signature into the Session:

$shop = $_GET['url'];
$token = $_GET['t'];
$api = new Session($shop, $token, 'YOUR_API_KEY', 'YOUR_SECRET');

That’s it! Now that your application’s been installed, you’re ready to make API calls to the merchant’s shop.

Here’s an example that prints the title of each product:

$storeProducts = $api->product->get();

foreach($storeProducts as $product) {
       echo $product['title'].'<br />';
You can also request a specific product by passing its product id to the product
$aProduct = $api->product->get(1234567);
echo $aProduct['title'];

To create a new product (if your application has write permissions), you can use the product

method by passing fields you would like your new product to have:
$fields = array('title' => 'My New Product');

To update a product (if your application has write permissions), you can use the product

method by passing the product id and the fields you would like to modify:
$fields = array('title' => 'My Updated Title');
$api->product->modify(1234567, $fields);

Download and try the new PHP API for yourself by going to its GitHub repository. Forks and feature requests are encouraged.

Give us, the Shopify Developers, a shout in the developer forums if you need a hand or want to pass on a compliment to William Lang, one of our newest developers and the man behind this library.