Magento – How to get a Product ID after a product post via REST api to update product category

apicategoryproductrest

I want to insert products from a csv-file into the Magento DB via the REST API.
First I try to update one single product.

The product is inserted into the db but this product needs to be assigned to a category.

How do I get the productID from the result?

// post method
$restClient->setMethod('POST');
$restClient->setRawBody(json_encode($data));

//Make REST request
$response = $restClient->send();

Because I have to make another call for the catagory.

$restClient->setUri($apiURL . '/products/' . $id . '/categories');
$restClient->setRawBody(); //will be filled with the categoryID

When I dump the $response, the content is protected and gives me a lot of questionmarks.
When I say: var_dump($response->getBody());
The body is empty = ''

I don't think it would be necessary to make another call for getting the last product update/insert

Best Answer

The answer is simply in the $response.

echo $response->getBody();

$headers = $response->getHeaders();
$location = $headers->toArray();
$product_id = $location['Location'];

return $product_id;