0

I'm querying an Azure Digital Twin instance using the query API, which is fine, it authenticates, and I can get results back. The issue I'm having is when I need to make a subsequent API call with the continuation token. The call works, and I'm passing in the continuationToken property instead of the query property in the message body, but I'm getting duplicated results.

For example, If I run a query which I know returns 22 records and set max-items-per-page to 100 then I get the results I'm expecting. If I do the same but set max-items-per-page to 3, I still get 22 results back, but most of them are duplicated. I could set the max-items-per-page to a ridiculously high number, but that doesn't feel like the right approach.

Not sure if I've missed something in the documentation, or if this is a known issue, but any help is welcome.

Edit:

The overall flow is this

API Call #1: Made with body {"query": "select * from digitaltwins"}

API Call #2: Made with body {"continuationToken": "<token here>"}

And so on, each new call using the continuation token from the previous call until the continuation token is null.

As part of this I'm also correctly escaping the continuation token before passing it back in the API call as the code reads the content as JSON but then has to escape the JSON string continuation token.

The following is an example token where I've set max-items-per-page to 1 to highlight the issue.

"{\"_t\":1,\"_s\":3,\"_rc\":null,\"_q\":\"SELECT dt FROM digitaltwins dt\",\"_id\":\"c50ef08b-abcd-1234-9baa-c93226665e34\",\"_tr\":3,\"_pn\":3}"
daz-fuller
  • 1,191
  • 1
  • 10
  • 18

1 Answers1

-1

As per Microsoft Documents, a query specification containing either a query statement or a continuation token from a previous query result.

How to use Continuation token in Digital Twins, this post will help you to sort out your issue.

Special thanks to @SatishBoddu-MSFT in which he addressed the below notes,

Step 1: On first time call request returns results values and continuation token.
Step 2: On second call request with headers set value Sphere-Continuation=<yourContinuationtoken>` .
Step 3: On last and final request you set continuationToken=null. if you get all the result data and no more data else in call request.

RajkumarPalnati
  • 541
  • 2
  • 6
  • I think that missed the question though. The API calls are being made that way as per the documentation and as detailed in the question. The linked post only sort of helped in getting there as the continuation token that comes back from Digital Twins needs to be escaped when it's passed back as it's not a token but a json object that includes the original query. So the question isn't "how do I use a continuation token", it's "why am I getting some duplicate results when I do" – daz-fuller Jun 21 '22 at 14:00
  • Just to confirm, I've tried with the "Sphere-Continuation" header as well which makes no difference to the outcome. – daz-fuller Jun 29 '22 at 15:47
  • I've managed to reproduce the issue using both the REST API and the .NET SDK, so have raised this as a bug instead. https://github.com/Azure/azure-sdk-for-net/issues/29551 – daz-fuller Jun 29 '22 at 16:33