Nexttoken value in QueryTableRows API

I am working on a lambda to export the data present in Honeycode. I am using QueryTableRows API to get the selected rows from the table. API reference: https://docs.aws.amazon.com/honeycode/latest/APIReference/API_QueryTableRows.html

Sample code:
def fetch_proposal_data(): response = honeycode_client.query_table_rows( workbookId=WORKBOOK_ID, tableId=PROPOSAL_TABLE_ID, filterFormula = {"formula": f'=FILTER(Proposals,"Proposals[Status]=""MEDICAL_EVALUATION_REQUIRED"" OR Proposals[Status]=""UNDER_WRITER_REVIEW""")'} ) return response

Above code might not return all data present in DB if the table size is huge, we probably need to fetch the records in pagination form. API reference mentioned here https://docs.aws.amazon.com/honeycode/latest/APIReference/API_QueryTableRows.html
From the above link, this is not very clear about how we can provide nextToken as the reference to the API call. What value should we pass as nextToken in the API request?

Hi @Jhut-caa0,

Thank you so much for your question.

On first call, the nextToken can be nul in the request. Upon getting the response from the first call, you will receive the nextToken from that response, you can then set it to 2nd request to paginate. Keep doing this in a loop until the response has no nextToken, then you know you have exhausted all result rows.

More details in our API guide QueryTableRows - Amazon Honeycode

Here's how to paginate through the result with page size of 100:

nextToken = None

while True:
    response = honeycode_client.query_table_rows(
        workbookId = <WORKBOOK_ID>,
        tableId = <TABLE_ID>,
        filterFormula = <...>,
        maxResults = 100,
        nextToken = nextToken
    )
    
    <do something with the response>
    
    nextToken = response.get('nextToken', None)

    if not nextToken:
       break

Please let us know if you have any other questions!

Thank you,
Evelyn

This seem to be not working due to a validation error:

def fetch_proposal_data():
    proposal_data_rows = []
    nextToken = None
    while True:
        response = honeycode_client.query_table_rows(
            workbookId=WORKBOOK_ID,
            tableId=<TABLE_ID>,
            filterFormula = <..>,
            maxResults = 100,
            nextToken = nextToken
            )
        proposal_data_rows.append(response.get('rows'))
        nextToken = response.get('nextToken', None)
        if not nextToken:
            break

Error:

Response
{
  "errorMessage": "Parameter validation failed:\nInvalid type for parameter nextToken, value: None, type: <class 'NoneType'>, valid types: <class 'str'>",
  "errorType": "ParamValidationError",
  "requestId": "996b102a-c822-4a0b-8849-d63577b82053",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 27, in lambda_handler\n    proposal_data = fetch_proposal_data()\n",
    "  File \"/var/task/lambda_function.py\", line 47, in fetch_proposal_data\n    response = honeycode_client.query_table_rows(\n",
    "  File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",
    "  File \"/var/runtime/botocore/client.py\", line 691, in _make_api_call\n    request_dict = self._convert_to_request_dict(\n",
    "  File \"/var/runtime/botocore/client.py\", line 739, in _convert_to_request_dict\n    request_dict = self._serializer.serialize_to_request(\n",
    "  File \"/var/runtime/botocore/validate.py\", line 360, in serialize_to_request\n    raise ParamValidationError(report=report.generate_report())\n"
  ]
}