Geovisualization Developer's Guide

Creating a Query

To create a new query, you first need to define a JSON object that contains the query code, and then POST it to the Geovisualization REST API. See defining a query for details on defining queries.

Once you have defined a query, include the query code as the request body in an authenticated POST to the following resource:

https://datalens.api.here.com/v1/queries?app_id={YOUR_APP_ID}&app_code={YOUR_APP_CODE}

You will receive a response body that includes the new query ID inside a JSON object with metadata about the query, including its source code.

You can also use the queries endpoint in the 07. Query CRUD folder of our Postman collection.

The response will look something like this:

{
  "origin": "user",
  "description": "Earthquake data from 2012 - Absolute value of depths",
  "tags": [],
  "updated_at": "2017-02-10T14:33:50Z",
  "visibility": "private",
  "dataset": "90af668484394fa782cc103409cafe39",
  "query": {
  "metrics": [
    "avg_magnitude",
    "count"
  ],
  "facets": [
    "Src"
  ],
  "namespace": {
    "count": {
    "source": [
      "region"
    ],
    "apply": [{
      "type": "aggregate",
      "fn": "count"
    }]
    },
    "avg_magnitude": {
    "source": [
      "Magnitude"
    ],
    "apply": [{
      "type": "aggregate",
      "fn": "average"
    }]
    }
  },
  "order": [{
    "Src": "asc"
    },
    {
    "count": "desc"
    }
  ],
  "dataset": "90af668484394fa782cc103409cafe39"
  },
  "id": "6fad8374f8bc4470b1d71f802cc5537d",
  "kind": "datalens#query",
  "created_at": "2017-02-10T14:33:50Z",
  "request_id": "5c447143-9682-4ae4-ca62-e09ce038e318",
  "estimated_rows": 13
}
Note: The value for the id field is the unique identifier for the new query. You reference this ID in a JavaScript service to fetch the query results in your visualizations.