title: How do I set continuation tokens for Cosmos DB queries sent by document_client objects in Python?
body: <p>I have an API that retrieves documents based on keywords that appear in document fields. I would like to paginate results so that I can return documents to a client sending a request, as well as allowing them to request more documents if they want. The query itself only takes a second or so in the browser when I am in the Azure Data Explorer, but it takes about a minute when I query using the Python DocumentDB library.</p>
  
  <p>Looking at the <a href="https://docs.microsoft.com/en-us/rest/api/documentdb/querying-documentdb-resources-using-the-rest-api#pagination-of-query-results" rel="nofollow noreferrer">Microsoft Cosmos DB REST API</a>, it appears as if there are two tokens, <strong>x-ms_continuation</strong> and <strong>x-ms-max-item-count</strong> that are used.</p>
  
  <p>It doesn't appear that putting these as entries in the <em>options</em> dictionary of <code>document_client.QueryDocuments()</code> does the trick.</p>
  
  <p>In the GitHub repository, the <a href="https://github.com/Azure/azure-documentdb-python/blob/master/pydocumentdb/document_client.py#L162" rel="nofollow noreferrer">Read()</a> method references the <em>options</em> parameter:</p>
  
  <pre><code>    headers = base.GetHeaders(self,
                                initial_headers,
                                'get',
                                path,
                                id,
                                type,
                                options)
      # Read will use ReadEndpoint since it uses GET operation
      url_connection = self._global_endpoint_manager.ReadEndpoint
      result, self.last_response_headers = self.__Get(url_connection,
                                                      path,
                                                      headers)
  </code></pre>
  
  <p>Looking in <a href="https://github.com/Azure/azure-documentdb-python/blob/master/pydocumentdb/base.py#L67" rel="nofollow noreferrer">base.py</a>, where the file is located, I saw these two blocks of code</p>
  
  <pre><code>if options.get('continuation'):
      headers[http_constants.HttpHeaders.Continuation] = (
          options['continuation'])
  
  if options.get('maxItemCount'):
      headers[http_constants.HttpHeaders.PageSize] = options['maxItemCount']
  </code></pre>
  
  <p>This would appear to correspond to the two parameters above. However, when I set them as options in the query (<code>{'continuation':True,'maxItemCount':10}</code>), nothing changes.</p>
  
  <p>The final query looks like </p>
  
  <pre><code>client.QueryDocuments(collection_link, query, {'continuation':True,'maxItemCount':10})
  </code></pre>
  
  <p>I have also tried using a string instead of an int for <code>maxItemCount</code>.</p>
  
  <p>What am I doing incorrectly here?</p>
  
  <p>Edit: The headers are the same as the two from the documentation above, from <a href="https://github.com/Azure/azure-documentdb-python/blob/master/pydocumentdb/http_constants.py#L91" rel="nofollow noreferrer">http_constants.py</a>:</p>
  
  <pre><code># Our custom DocDB headers
  Continuation = 'x-ms-continuation'
  PageSize = 'x-ms-max-item-count'
  </code></pre>