'Understand the Range while adding text in Google Doc using Google API in PHP

I want to add text on Google Doc but confused with "range" parameter. I want to understand the role of "range" parameter while adding text to any Google Doc. I will be adding text always on top of the doc only, so please guide me where I am doing wrong. Additionally I will be adding checkboxes as well against some text too. Following is the code which I am using currently to add text and then add checkbox:

$requests[] = new \Google_Service_Docs_Request(
        array(
            'insertText' => array(
                'text' => 'abcdtrig',
                'location' => array(
                    'index' => 10),
            ),
        )
    );

    $requests[] = new \Google_Service_Docs_Request(
        array(
            'createParagraphBullets' => array(
                'range' => array(
                    'startIndex' => 1,
                    'endIndex' => 25
                ),
                'bulletPreset' => 'BULLET_CHECKBOX'
            ),
        )
    );

    $requests[] = new \Google_Service_Docs_Request(
        array(
            'deleteParagraphBullets' => array(
                'range' => array(
                    'startIndex' => 1,
                    'endIndex' => 2
                )
            ),
        )
    );

    $requests[] = new \Google_Service_Docs_Request(
        array(
            'insertText' => array(
                'text' => '#milk',
                'location' => array(
                    'index' => 1),
            ),
        )
    );


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

I want it to work in a way that whenever I run this script it should add text on top of the doc and existing content of the doc will shift down.

Please help me to understand the concept of range because other things are working fine and I am clear on that. Just need to understand the "range" concept only.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source