Home > Back-end >  "Unexpected {" shopify admin api get request in php
"Unexpected {" shopify admin api get request in php

Time:08-04

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.

CodePudding user response:

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);
  • Related