public function post(ProductCategory $productCategory) { $payload = $productCategory->toPost(); $parentId = $productCategory->getParentId(); // if this is the root category, specify that by making the parentId -1 and it will make sure the URL doesn't // have a parent ID appended and instead posts straight to /ProductCategories/ for adding the root and not // /ProductCategories/{categoryId} where categoryId is the parent $urlExtension = $parentId == -1 ? '' : '/' . $parentId; $response = $this->connection->post('/ProductCategories' . $urlExtension, $payload); $body = $response->getBody(); return $this->getResponseFromBody($body); }