Get query builder answer via REST API

Hello ARAS community,

could you tell me if its possible to get aml result of a query via REST API ? (POSTMAN).

I can easily find my query via postman but i cannot execute it.

I tried to creat a method with inside a call to my query and then call the method via POSTMAN but so far it is not working : 

Innovator innovator = this.getInnovator(); / this.newIOMInnovator(); //i think its a Csharp method.
var qry_id = "3880DB6828CC43F7AFE580FD7AB267B4"; // QUERY ID

// get query definition with relationships
var queryDef = inn.newItem("qry_QueryDefinition","get");
queryDef.setID(qry_id);
queryDef.setAttribute("levels","2");
queryDef = queryDef.apply();

// create offset/fetch settings string
var offset = "1";
var ftch = "1";
var offset_fetch = "<configuration><option><offset>" + offset +
"</offset><fetch>" + ftch +
"</fetch></option></configuration>";

thank you

  • Hello,

    I think you're on the right track by creating a separate server method to perform the query. You can check out this blog post which goes over how to run a query from a Query Definition programmatically. Once you have that method written, you can call that custom method from the REST API by doing a POST request with a URL like the one below. You'll just need to update the bolded part of the URL with the name of your custom method.

    POST {base url}/method.RunMyQueryDefinition

    {
        "my_param" : "my_param_value"
    }

    You can also pass a body along with this request if you need to pass in any additional parameters into your custom method. This body will turn into the this context item of your custom method. As an example, with the body above, I could add a line like this to my custom method to get the parameter passed in.

    this.getProperty("my_param");


    Chris

    Christopher Gillis

    Aras Labs Software Engineer

  • here is the solution : 

    rest request :

    http://localhost/GTSI_I2/server/odata/method.*method_name*

    methode : 

    Innovator inn = this.getInnovator();
    var qry_id = "9D6022A8359748F7BB50AF18F6A41830"; // QD id

    // get query definition with relationships
    var queryDef = inn.newItem("qry_QueryDefinition","get");
    queryDef.setID(qry_id);
    queryDef.setAttribute("levels","10");
    queryDef = queryDef.apply();

    // execute query
    queryDef.setAction("qry_ExecuteQueryDefinition");
    queryDef.setAttribute("levels","10");
    var res = queryDef.apply();

    return res;

    With this we got all the item type and their dependancy of the database.

    Now I need to select only one choosen item type and his dependency.

    any idea ?

    thanks :)

  • Hello,

    The easiest way to do this would be to add a parameter to your query definition to hold some identifying information about the item like the name. You can then add a condition to your query definition like 'Name = $my_name_param'. This will allow you to filter your query by passing in optional parameters.

    In order to add this parameter programmatically, you can get the qry_QueryParameter relationship and set the value of that in order to filter your query. For example,

    queryDef.getRelationships("qry_QueryParameter").getItemByIndex(0).setProperty("value", "My Specific Item Name");

    If you're new to using parameters with query definitions, I'd recommend checking out the first part of this blog post which goes into more specific steps on how to set up and use a parameter.

    Chris