Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"Unexpected {" shopify admin api get request in php

I’m trying to issue a get request in php with the shopify admin api.

$productId = "11235813213455"
// `session` is built as part of the OAuth process
$client = new Shopify\Clients\Rest(
    $session->getShop(),
    $session->getAccessToken()
);
$response = $client->get({
    path: "products/$productId",
    query: ["id" => 1, "title" => "title"]
});

It says that there is an unexpected {. Why is this and how do I fix it?

I’m new to stack overflow so please ask if you need more information.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are attempting to put raw JSON into PHP, you can’t do this. You need to build a PHP array:

$productId = "11235813213455"
// `session` is built as part of the OAuth process
$client = new Shopify\Clients\Rest(
    $session->getShop(),
    $session->getAccessToken()
);
$product = [
    'path' => "products/$productId",
    'query' => ['id' => 1, 'title' => 'title']
];
$response = $client->get($product);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading