[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
get()method:
$aProduct = $api->product->get(1234567); echo $aProduct['title'];
To create a new product (if your application has write permissions), you can use the product
create()method by passing fields you would like your new product to have:
$fields = array('title' => 'My New Product');
$api->product->create($fields);
To update a product (if your application has write permissions), you can use the product
modify()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.
Outstanding! Thank you! I will be putting this to use today!!
Hi I am not real sure as to what this new development can do for my store. Would it be possible to give some incite as to the benefits of have this in my store front?
Walt,
The benefits to you are more indirect as a merchant. Having an official API client for PHP developers makes it easier for PHP developers to create applications that you can later install in your store.
Nice addition, thanks!!
Nice! I’m just finishing up another Shopify store, and can’t tell you how impressed I am with its functionality. This API looks very clean. Look forward to pumping some apps into the app store.
I’m looking forward to developing some apps for Shopify. Never got around to learning Ruby :-)
Great addition. It will simplify shopify apps development using Php.