Shopify / shopify-api-php

MIT License
392 stars 176 forks source link

How does one connect a private app? #111

Closed hessel-bb closed 2 years ago

hessel-bb commented 2 years ago

I wanted to test this package for my laravel app and i am very confused on how to define my private app. Which fields do i need? Because the fields in a private app are different from a public app. For example i don't need to get my session etc. because i only want to write products to my store from my Laravel app.

Thanks in advance.

hessel-bb commented 2 years ago

For anyone in the future. If you want to interact with the REST php api you do the following:

This is in laravel

use Shopify\Context;
use Shopify\Clients\Rest;

$shopify = Context::initialize(
            env('SHOPIFY_API_KEY'),
            env('SHOPIFY_API_SECRET'), //Your shopify private app pasword
            ["read_products", "write_products"],
            env('SHOPIFY_APP_HOST_NAME'),
            new FileSessionStorage('/tmp/php_sessions'),
            '2021-04',
            true,
            true,

        );

        $domain = env('SHOPIFY_APP_HOST_NAME'); //domain.myshopify.com
        $secret = env('SHOPIFY_API_SECRET'); //Your shopify password of the private app
        $client = new Rest($domain, $secret);
        $body = [
            "product" => [
                "title" => "Hiking backpack"
            ]
        ];

        $response = $client->post('products', $body);