I am trying to link items with categories and I am having trouble using Php. I am able to submit a curl post item and get it to work but when I am using the GuzzleHttp method, it is not working.
In curl I use:
$curl=curl_init('https://sandbox.dev.clover.com/v3/merchants/{MID}/category_items'); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "Authorization:Bearer {access token}", 'Content-Type: application/json', ) ); $data='{"elements":[{"category":{"id":"category_id"},"item":{"id":"item_id"}}]}'; curl_setopt( $curl, CURLOPT_POST, true ); curl_setopt( $curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $auth = curl_exec($curl);
This works properly.
With guzzlehttp I am using this method but it is not working. I use similar methods for creating an Item and it works fine but on this method for linking item and category I am not able to get it working. I am not getting an error but I am also not getting the item and category link. What am I doing wrong?
$client = new \GuzzleHttp\Client(); $data='{"elements":[{"category":{"id":"category_id"},"item":{"id":"item_id"}}]}'; $response = $client->request('POST', 'https://sandbox.dev.clover.com/v3/merchants/{MID}/category_items', [ 'data' => $data, 'headers' => [ 'authorization' => 'Bearer {access token}', 'content-type' => 'application/json', ], ]);