When updating the primary category using Google My Business API, it shows this error:
+"error": {#278 ▼
+"code": 400
+"message": "Request contains an invalid argument."
+"status": "INVALID_ARGUMENT"
+"details": array:1 [▼
0 => {#269 ▼
+"@type": "type.googleapis.com/google.rpc.BadRequest"
+"fieldViolations": array:1 [▼
0 => {#275 ▼
+"field": "update_mask"
+"description": "primary or additional categories cannot be updated independently."
}
]
}
]
}
Here's my PHP Code :
<?php
$locationData = array();
$locationData['title'] = $data['title'];
$locationData['categories']['primaryCategory']['name'] = 'gcid:website_designer';
$updateMask = array(
'title',
'categories.primaryCategory.name'
);
$queryParams = array(
'updateMask' => implode(',', $updateMask)
);
// Prepare new cURL resource
$curl = curl_init('https://mybusinessbusinessinformation.googleapis.com/v1/locations/'.$locationId.'/?'.http_build_query($queryParams));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($curl, CURLOPT_POSTFIELDS, $locationData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $accessToken,
));
// Submit the DELETE request
$response = curl_exec($curl);
// Close cURL session handle
curl_close($curl);
$location = json_decode($response);
echo "<pre>";
print_r($location);
echo "</pre>";
What does this error means?
primary or additional categories cannot be updated independently.
it successfully update the business name when I removed this mask
categories.primaryCategory.name
So, I'm confused what mask should I add to update the primary category or is there a separate API for that?
I based on this documentation:
https://developers.google.com/my-business/reference/businessinformation/rest/v1/locations/patch
In your update mask you need to specify just categories
and supply both.
Same goes for phoneNumbers