first of all, my english is not that good. I hope you still understand what I mean.
I'm trying to upload a product to my feed using google api 2.1. Here, however, I always get an error message that I can't make any sense of.
Curl request to https://shoppingcontent.googleapis.com/content/v2.1/{merchantId}/products?feedId=XXX
Link to Doc https://developers.google.com/shopping-content/reference/rest/v2.1/products/insert
public function postRequest($url, $data, $accessToken)
{
$ch = curl_init();
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
"Authorization: $accessToken"
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
$body = json_encode($data);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$data = curl_exec($ch);
$data = json_decode($data);
return $data;
}
$productData = [
"merchantId" => GOOGLE_MERCHANT_ID,
"offerId" => "DE_" . $modelNumber,
"title" => $productName,
"description" => $description,
"link" => $productLink,
"imageLink" => $mainImageLink,
"contentLanguage" => $this->countriesData["DE"]["langIso6391Codes"],
"targetCountry" => $this->countriesData["DE"]["cldrTerritoryCode"],
"channel" => "online",
"adult" => false,
"kind" => "content#product",
"brand" => $manufacturerName,
"googleProductCategory" => $googleCategory,
"gtin" => $productEan,
"mpn" => $modelNumber,
"price" => [
"value" => $productPrice,
"currency" => $this->countriesData["DE"]["currency"]
],
"productWeight" => [
"value" => $productWeight,
"unit" => "kg"
],
"shipping" => [
"price" => [
"value" => $shippingPrice,
"currency" => $this->countriesData["DE"]["currency"]
],
"country" => $this->countriesData["DE"]["cldrTerritoryCode"],
"region" => $this->countriesData["DE"]["region"],
"service" => $shippingTimeName,
],
"productTypes" => ["test"],
"identifierExists" => true,
"source" => "api",
"availability" => "on stock",
"condition" => $this->countriesData["DE"]["productCondition"],
];
Here I get the following error message:
object(stdClass)#32 (1) {
["error"]=>
object(stdClass)#31 (4) {
["code"]=>
int(400)
["message"]=>
string(305) "Invalid JSON payload received. Unknown name "price": Cannot find field.
Invalid JSON payload received. Unknown name "productWeight": Cannot find field.
Invalid JSON payload received. Unknown name "shipping": Cannot find field.
Invalid JSON payload received. Unknown name "productTypes": Cannot find field."
["errors"]=>
array(1) {
[0]=>
object(stdClass)#44 (2) {
["message"]=>
string(305) "Invalid JSON payload received. Unknown name "price": Cannot find field.
Invalid JSON payload received. Unknown name "productWeight": Cannot find field.
Invalid JSON payload received. Unknown name "shipping": Cannot find field.
Invalid JSON payload received. Unknown name "productTypes": Cannot find field."
["reason"]=>
string(7) "invalid"
}
}
["status"]=>
string(16) "INVALID_ARGUMENT"
}
}
If I comment out the criticized fields:
// "price" => [
// "value" => $productPrice,
// "currency" => $this->countriesData["DE"]["currency"]
// ],
// "productWeight" => [
// "value" => $productWeight,
// "unit" => "kg"
// ],
// "shipping" => [
// "price" => [
// "value" => $shippingPrice,
// "currency" => $this->countriesData["DE"]["currency"]
// ],
// "country" => $this->countriesData["DE"]["cldrTerritoryCode"],
// "region" => $this->countriesData["DE"]["region"],
// "service" => $shippingTimeName,
// ],
// "productTypes" => ["test"],
I get the following error message
object(stdClass)#32 (1) {
["error"]=>
object(stdClass)#31 (3) {
["code"]=>
int(400)
["message"]=>
string(45) "[product] INSERT request must specify product"
["errors"]=>
array(1) {
[0]=>
object(stdClass)#44 (3) {
["message"]=>
string(45) "[product] INSERT request must specify product"
["domain"]=>
string(6) "global"
["reason"]=>
string(8) "required"
}
}
}
}
Do any of you have any idea where my mistake is?