Skip to content

Instantly share code, notes, and snippets.

View fditrapani's full-sized avatar

Filippo Di Trapani fditrapani

View GitHub Profile
// Set variables for our request
$shop = "demo-shop";
$api_key = "1r30mrvCFMfq2DLGuIXyY2veEJVgTtDD";
$scopes = "read_orders,write_products";
$redirect_uri = "http://localhost/generate_token.php";
// Build install/approval URL to redirect to
$install_url = "https://" . $shop . ".myshopify.com/admin/oauth/authorize?client_id=" . $api_key . "&scope=" . $scopes . "&redirect_uri=" . urlencode($redirect_uri);
// Redirect
// Set variables for our request
$shared_secret = "TBB5wltKarRtKn5mUVZck9RxHePNN6Jo";
$code = $_GET["code"];
$timestamp = $_GET["timestamp"];
$signature = $_GET["signature"];
// Compile signature data
$signature_data = $shared_secret . "code=" . $code . "shop=". $shop . ".myshopify.comtimestamp=" . $timestamp;
// Use signature data to check that the response is from Shopify or not
// Set variables for our request
$shop = "demo-shop";
$request_headers = array(
"Content-type" => "application/json", // Tell Shopify that we're expecting a response in JSON format
"client_id" => "1r30mrvCFMfq2DLGuIXyY2veEJVgTtDD", // Your app API key
"client_secret" => "TBB5wltKarRtKn5mUVZck9RxHePNN6Jo", // Your app credentials (secret key)
"code" => $_GET["code"] // Grab the access key from the URL
);
// Call our Shopify function
// 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 all 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'];
// 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');
https://localhost/generate_token.php?code={authorization_code}&signature=da9d83c171400a41f8db91a950508985&timestamp=1409617544
select
LOWER(ep2.value) as value,
count( * ) as counts
from
tracks.prod_events as events,
events.eventprops as ep,
events.eventprops as ep2
where
dateymd between 20190110 and 20190212 and
eventname = 'wpcom_hook_wpmu_new_blog' and