Table of contents

To increase the reusability of queries created in Graphlytic the option to “publish” a query under a custom API name was implemented.

Every project query or query in a library can have the “queryId” parameter defined (this is the API name).

Such query is then accessible at POST https://mygraphlytic.domain/projects/{projectId}/data/query/{queryId}

1. Authentication

API authentication using the Basic Auth method is needed to run any query. This ensures that every query is processed in Graphlytic authorization and security layers and is logged.

2. Authorization

Every query is processed in multiple authorization and security steps:

  1. Every query is defined in the context of a Project. To run a query the authenticated account has to have the PERM_EXPORING permission for the accessed project.

  2. To run a WRITE query the authenticated account has to have also the PERM_DATA_MGMT permission for the accessed project.

  3. Data returned from a query is post-processed in the security layer:

    1. Removed all nodes and relationships that are not allowed for the authenticated account.

    2. Removed all properties that are not allowed for the authenticated account.

3. How to publish a query in the API

To publish a query stored in a Query Library just add the “queryId” unique value to the query definition object (see example below).

This value will be used in the URL so only URL-allowed characters can be used, do not use space or any of these /&?=:%.

To publish a project query just add the “API name” value in the query edit form:

queries_add_api_name.png

Published queries can be easily identified by the API name listed below the query name:

queries_api_names.png

4. Examples

4.1. Example 1

A simple example of a query template available at POST https://mygraphlytic.domain/projects/1/data/query/my-first-query

{
"queryId": "my-first-query",
"queryType": "cypherTemplate",
"title":"TOP n nodes",
"description":"",
"template":{
"textTemplate" : "Return first $limit nodes",
"cypherTemplate" : "MATCH (n) RETURN n LIMIT $limit",
"parameters" : [
{
"parameter" : "limit",
"type" : "NUMBER",
"config" : {
"placeholder" : "Select the limit",
"multiple" : false,
"strict" : true,
"values" : [2,5,10,20,30,40,50]
}
}
]
}
}

Request example

[
{
"parameter":"limit",
"values":2
}
]

Response example

{
"records":[
{
"keys":["n"],
"values":[
{
"_dbId":"0",
"properties":{
"profile":"Application Component",
"default_impact":"3 - Several users",
"_updated":1709739594674,
"status":"Disposed"
},
"_entityType":"node",
"_dbLabels":["CI", "Application Component"]
}
]
},
{
"keys":["n"],
"values":[
{
"_dbId":"1",
"properties":{
"endDate":1.533351879255258E12,
"profile":"Application Component",
"information_system":"System A",
"status":"Disposed"
},
"_entityType":"node",
"_dbLabels":["CI", "Application Component"]
}
]
}
],
"count":2
}