shopify_api
Simple Shopify API client in PHP, (*1)
Requirements
Getting Started
Create a composer.json
file if you don't already have one in your projects root directory and require shopify_api:, (*2)
{
"minimum-stability": "dev",
"require": {
"secomapp/shopify_api": "dev-master"
}
}
Install Composer:, (*3)
$ curl -s http://getcomposer.org/installer | php
Run the install command:, (*4)
$ php composer.phar install
This will download shopify_api into the vendor/sandeepshetty/shopify_api
directory., (*5)
To learn more about Composer visit http://getcomposer.org/, (*6)
Require and use
Usage
Generating the app's installation URL for a given store:
Verify the origin of all requests/redirects from Shopify:
Generating the oAuth2 permission URL:
Get the permanent oAuth2 access token:
Making API calls:
'published'));
// Create a new recurring charge
$charge = array
(
"recurring_application_charge"=>array
(
"price"=>10.0,
"name"=>"Super Duper Plan",
"return_url"=>"http://super-duper.shopifyapps.com",
"test"=>true
)
);
try
{
// All requests accept an optional fourth parameter, that is populated with the response headers.
$recurring_application_charge = $shopify('POST', '/admin/recurring_application_charges.json', $charge, $response_headers);
// API call limit helpers
echo shopify_api\calls_made($response_headers); // 2
echo shopify_api\calls_left($response_headers); // 298
echo shopify_api\call_limit($response_headers); // 300
}
catch (shopify_api\Exception $e)
{
// If you're here, either HTTP status code was >= 400 or response contained the key 'errors'
}
}
catch (shopify_api\Exception $e)
{
/* $e->getInfo() will return an array with keys:
* method
* path
* params (third parameter passed to $shopify)
* response_headers
* response
* shops_myshopify_domain
* shops_token
*/
}
catch (shopify_api\CurlException $e)
{
// $e->getMessage() returns value of curl_error() and $e->getCode() returns value of curl_errno()
}
?>