Search code examples
phpgoogle-apigoogle-docsgoogle-docs-api

How can we get HeaderId and FooterId from the response we get after batchUpdate request in google docs api using PHP?


I am working on google docs api. I want to insert text into header and footer simultaneously and for that I need header/footer id. So, for that I firstly created header/footer like this-

$requests[] = new Google_Service_Docs_Request(array(
  "createFooter" => [
    "sectionBreakLocation" => [
      "index" => 0,
      "segmentId" => "1",
    ],
    "type" => "DEFAULT",
  ],
));

$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(array(
    'requests' => $requests
));

$response = $service->documents->batchUpdate($documentId, $batchUpdateRequest);

After this, when I print my $response using print_r($response), I can see my footer id.Like this -


                    [createFooter] => Google\Service\Docs\CreateFooterResponse Object
                        (
                            [footerId] => kix.vv5nq4qsqioo
                            [internal_gapi_mappings:protected] => Array
                                (
                                )

                            [modelData:protected] => Array
                                (
                                )

                            [processed:protected] => Array
                                (
                                )

                        )

                )

but,after this I am unable to get my footer id dynamically. How I can fetch my footer id from this response using PHP.


Solution

  • You can just access the footerId from the response:

    $response = $service->documents->batchUpdate($documentId, $batchUpdateRequest);
    $footerId = $response->replies[0]->createFooter->footerId;
    print($footerId);
    

    Ref: