Search code examples
phpcurlgoogle-my-business-api

Updating/Patching a Local Post with Google My Business API and PHP


I'm trying to update/patch a specific GMB Local Post using curl. For this example, I'm only trying to update the summary of the post.

Here's my code:

    $url = "https://mybusiness.googleapis.com/v4/".$postId."?updateMask=1";

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $pQuery = array(
        "summary" => $postMessage
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($pQuery));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer '.$access_token.'', 'Content-Type: application/json', 'Content-Length: ' . strlen(json_encode($pQuery))));

    $updatePostDetails = curl_exec($ch);

I get no error, but the response body I get is the same Local Post as before, ignoring the new summary I updated.

I assume my issue comes from the updateMask parameter, but I can't find how to make it work.

Thanks for your help.


Solution

  • updateMask parameter expects path of the field that needs change. So you should provide as updateMask=summary. So your URL should be as

       $url = "https://mybusiness.googleapis.com/v4/".$postId."?updateMask=summary";