PHP

From Shopify Wiki

Jump to: navigation, search

You can use PHP to connect to the Shopify API.

For this you need SimpleXML and CURL support.

Example


<?php
  //Modify these
  $API_KEY = 'your-token-here';
  $SECRET = 'your-secret-here';
  $TOKEN = 'your-secret-here';
  $STORE_URL = 'yourestore.myshopify.com';
  $PRODUCT_ID = 'product-id-here';

  $url = 'https://' . $API_KEY . ':' . md5($SECRET . $TOKEN) . '@' . $STORE_URL . '/admin/products/' . $PRODUCT_ID . '.xml';

  $session = curl_init();

  curl_setopt($session, CURLOPT_URL, $url);
  curl_setopt($session, CURLOPT_HTTPGET, 1); 
  curl_setopt($session, CURLOPT_HEADER, false);
  curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml'));
  curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

  if(ereg("^(https)",$url)) curl_setopt($session,CURLOPT_SSL_VERIFYPEER,false);

  $response = curl_exec($session);
  curl_close($session);

  $product_xml = new SimpleXMLElement($response); 

  echo $product_xml->title;
  echo $product_xml->variants->variant->{'inventory-quantity'};
?>

PHP Active Resource

There is a PHP implementation of the active resource style API that Shopify adheres to. This *may* work:

http://code.google.com/p/phpactiveresource/

Retrieved from "http://wiki.shopify.com/PHP"