Skip to main content
Question

What's the best practice to use the POST /models/instances/query endpoint?

  • December 15, 2025
  • 1 reply
  • 28 views

Hi community,

I’m learning to use the /models/instances/query endpoint (with Open Industrial Data, public project) and experiencing some confusion about how cursors and pagination work.


{
    "with": {
        "cities": {
            "nodes": {
                "filter": {
                    "and": [
                        {
                            "exists": {
                                "property": [
                                    "Geography",
                                    "City",
                                    "name"
                                ]
                            }
                        }
                    ]
                }
            }
        },
        "continents": {
            "nodes": {
                "filter": {
                    "and": [
                        {
                            "exists": {
                                "property": [
                                    "Geography",
                                    "Continent",
                                    "name"
                                ]
                            }
                        }
                    ]
                }
            }
        }
    },
    "select": {
        "cities": {
            "sources": [
                {
                    "source": {
                        "type": "view",
                        "space": "Geography",
                        "externalId": "City",
                        "version": "1"
                    },
                    "properties": [
                        "continent",
                        "country",
                        "name",
                        "iso2",
                        "iso3",
                        "population"
                    ]
                }
            ]
        },
        "continents": {
            "sources": [
                {
                    "source": {
                        "type": "view",
                        "space": "Geography",
                        "externalId": "Continent",
                        "version": "1"
                    },
                    "properties": [
                        "name"
                    ]
                }
            ]
        }
    }
}

I built the following query (see above) to fetch cities and continents. I sent the request with no cursors, and got this response: "nextCursor" with both "cities" and "continents", "items" with 100 cities and 6 continents

So, for the next request, I put nextCursor values into the "cursors" field. This time, I only get a nextCursor for cities, and the items are 100 cities and 0 continents.
For the third request, I use the new cursor. And I get 100 more cities, but for continents, I again get the same 6 as in the first request.

 

Actually I just want to get all cities and continents with the cursors without expecting I might get repeated data.

 

 

I want to know:

  1. Is this the correct usage for pagination with multiple entities?
  2. Is there a recommended best practice for getting all data when querying multiple collections like this?

 

Additionally, I tried to use data_modeling.instances.query in the Python SDK, but it seems there’s no auto-pagination and I need to pass cursors manually in each call.

 

Thanks!

 

1 reply

Arild  Eide
Seasoned Practitioner
Forum|alt.badge.img
  • Seasoned Practitioner
  • December 17, 2025

Hi ​@qiuwu 

 

In your current query you fetch cities and continents independently. You will probably want to follow a direct relation, which is described here. Another change you can consider is to use the HasData filter instead of applying an exists filter for a given property.

You will receive a cursors object that you will need to pass in the subsequent call until each cursor is exhausted (none returned), this goes for the Python SDK as well. There is also Pygen that let’s you generate an SDK tailored to your datamodel, that has built-in support for pagination.

 

Hope this helps!

 

Regards,

 

Arild Eide