Guest User

Untitled

a guest
Feb 12th, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. define( 'SHOPIFY_DOMAIN', 'domain.myshopify.com');
  2. define( 'SHOPIFY_API_KEY', 'API KEY');
  3. define( 'SHOPIFY_API_PASS', 'PASS HERE');
  4. define( 'SHOPIFY_SECRET', 'SECRET HERE');
  5.  
  6. require 'shopify/shopify.php';
  7.  
  8.  
  9. // For regular apps:
  10. $shopify = shopify_api_client(SHOPIFY_DOMAIN, NULL, SHOPIFY_API_KEY, SHOPIFY_API_PASS, true);
  11.  
  12. // For private apps:
  13. // $shopify = shopify_api_client($shops_myshopify_domain, NULL, $api_key, $password, true);
  14. try
  15. {
  16. // Get all products
  17. // $products = $shopify('GET', '/admin/products.json', array('published_status'=>'published'));
  18.  
  19.  
  20. // Create a new recurring charge
  21. $charge = array
  22. (
  23. "custom_collection"=>array
  24. (
  25. "title"=>"IPods",
  26. "collects"=>array(
  27. "product_id"=>99395362
  28. )
  29. )
  30. );
  31.  
  32. try
  33. {
  34. // All requests accept an optional fourth parameter, that is populated with the response headers.
  35. $recurring_application_charge = $shopify('POST', '/admin/custom_collections.json', $charge, $response_headers);
  36. // pr($response_headers);
  37. // pr($recurring_application_charge);
  38. // API call limit helpers
  39. echo shopify_calls_made($response_headers); // 2
  40. echo shopify_calls_left($response_headers); // 298
  41. echo shopify_call_limit($response_headers); // 300
  42.  
  43. }
  44. catch (ShopifyApiException $e)
  45. {
  46. pr($e);
  47. // If you're here, either HTTP status code was >= 400 or response contained the key 'errors'
  48. }
  49.  
  50. }
  51. catch (ShopifyApiException $e)
  52. {
  53. // $err = $e->getInfo();
  54. pr($e);
  55. /* $e->getInfo() will return an array with keys:
  56. * method
  57. * path
  58. * params (third parameter passed to $shopify)
  59. * response_headers
  60. * response
  61. * shops_myshopify_domain
  62. * shops_token
  63. */
  64. }
  65. catch (ShopifyCurlException $e)
  66. {
  67. pr($e);
  68. // $e->getMessage() returns value of curl_errno() and $e->getCode() returns value of curl_ error()
  69. }
  70.  
  71. ShopifyApiException Object
  72. (
  73. [info:protected] => Array
  74. (
  75. [method] => POST
  76. [path] => /admin/custom_collections.json
  77. [params] => Array
  78. (
  79. [custom_collection] => Array
  80. (
  81. [title] => IPods
  82. [collects] => Array
  83. (
  84. [product_id] => 99395362
  85. )
  86.  
  87. )
  88.  
  89. )
  90.  
  91. [response_headers] => Array
  92. (
  93. [http_status_message] => Internal Server Error
  94. [http_status_code] => 500
  95. [server] => nginx
  96. [date] => Sat, 15 Sep 2012 18:56:36 GMT
  97. [content-type] => application/json; charset=utf-8
  98. [transfer-encoding] => chunked
  99. [connection] => keep-alive
  100. [status] => 500 Internal Server Error
  101. [x-shopify-shop-api-call-limit] => 1/500
  102. [http_x_shopify_shop_api_call_limit] => 1/500
  103. [cache-control] => no-cache
  104. [x-request-id] => f6fdb72b6cabf22a73207d82b8ea16d9
  105. [x-ua-compatible] => IE=Edge,chrome=1
  106. [set-cookie] => _secure_session_id=cf2648422369ee231220b6f1f1efdb3b; path=/; secure; HttpOnly
  107. [x-runtime] => 0.047004
  108. )
  109.  
  110. [response] => Array
  111. (
  112. [errors] => Error
  113. )
  114.  
  115. )
  116.  
  117. [message:protected] => Internal Server Error
  118. [string:Exception:private] =>
  119. [code:protected] => 500
  120. [file:protected] =>PATH.TO.FILEshopifyshopify.php
  121. [line:protected] => 28
  122. [trace:Exception:private] => Array
  123. (
  124. [0] => Array
  125. (
  126. [file] => PATH.TO.FILEindex.php
  127. [line] => 44
  128. [function] => {closure}
  129. [args] => Array
  130. (
  131. [0] => POST
  132. [1] => /admin/custom_collections.json
  133. [2] => Array
  134. (
  135. [custom_collection] => Array
  136. (
  137. [title] => IPods
  138. [collects] => Array
  139. (
  140. [product_id] => 99395362
  141. )
  142.  
  143. )
  144.  
  145. )
  146.  
  147. [3] => Array
  148. (
  149. [http_status_message] => Internal Server Error
  150. [http_status_code] => 500
  151. [server] => nginx
  152. [date] => Sat, 15 Sep 2012 18:56:36 GMT
  153. [content-type] => application/json; charset=utf-8
  154. [transfer-encoding] => chunked
  155. [connection] => keep-alive
  156. [status] => 500 Internal Server Error
  157. [x-shopify-shop-api-call-limit] => 1/500
  158. [http_x_shopify_shop_api_call_limit] => 1/500
  159. [cache-control] => no-cache
  160. [x-request-id] => f6fdb72b6cabf22a73207d82b8ea16d9
  161. [x-ua-compatible] => IE=Edge,chrome=1
  162. [set-cookie] => _secure_session_id=cf2648422369ee231220b6f1f1efdb3b; path=/; secure; HttpOnly
  163. [x-runtime] => 0.047004
  164. )
  165.  
  166. )
  167.  
  168. )
  169.  
  170. )
  171.  
  172. [previous:Exception:private] =>
  173. )
  174.  
  175. $url = YOUR_SOPIFY_URL_WHERE_YOU_WANT_TO_POST.
  176. $username = "username";
  177. $password = "password";
  178.  
  179. $product = array();
  180. $ch = curl_init();
  181. $opts = array(
  182. CURLOPT_URL => $url,
  183. CURLOPT_RETURNTRANSFER => 1,
  184. CURLOPT_POST => 1,
  185. CURLOPT_POSTFIELDS => array('data' => json_encode($product)),
  186. CURLOPT_TIMEOUT => 120,
  187. CURLOPT_FAILONERROR => 1,
  188. CURLOPT_HTTPAUTH => CURLAUTH_ANY,
  189. CURLOPT_USERPWD => "$username:$password"
  190. );
  191.  
  192. curl_setopt_array($ch, $opts);
  193. $response = curl_exec($ch);
  194. curl_close($ch);
  195.  
  196. return json_decode($response);
Add Comment
Please, Sign In to add comment