forked from nyalex/shopify-generating-api-token-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_call_write_products.php
34 lines (26 loc) · 948 Bytes
/
api_call_write_products.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
// Get our helper functions
require_once("inc/functions.php");
// Set variables for our request
$shop = "demo-shop";
$token = "SWplI7gKAckAlF9QfAvv9yrI3grYsSkw";
$query = array(
"Content-type" => "application/json" // Tell Shopify that we're expecting a response in JSON format
);
// Run API call to get products
$products = shopify_call($token, $shop, "/admin/products.json", array(), 'GET');
// Convert product JSON information into an array
$products = json_decode($products['response'], TRUE);
// Get the ID of the first product
$product_id = $products['products'][0]['id'];
// Modify product data
$modify_data = array(
"product" => array(
"id" => $product_id,
"title" => "My New Title"
)
);
// Run API call to modify the product
$modified_product = shopify_call($token, $shop, "/admin/products/" . $product_id . ".json", $modify_data, 'PUT');
// Storage response
$modified_product_response = $modified_product['response'];