Skip to main content
System StatusContact Support
VersionOne Community

Executing Pass-Through Queries

Overview

In addition to providing object model-like access to the VersionOne Data API, the .NET SDK also provides a way to execute queries against the Query API. The Query API provides read-only access to VersionOne data, and allows you to submit hierarchical queries in a JSON or YAML format. In addition, data returned from the Query API is in a JSON format.

To execute Query API queries with the SDK, use the ExecutePassThroughQuery method of the Services object. This method does not parse the query that you provide, it simply passes the query through to the query.v1 endpoint and returns the raw JSON response. If the server returns an error regarding the validity of the query, the error is returned as an inner exception.

Prior to executing a pass-through query, you must first instantiate a V1Connector and Services object:

V1Connector connector = V1Connector
    .WithInstanceUrl("<Server Base URI>")
    .WithUserAgentHeader("AppName", "1.0")
    .WithAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
    .Build();
   
IServices services = new Services(connector);

In versions of the SDK prior to the 15.0.0.0 release, you would also have to instantiate a connector for the MetaModel object. However, starting with the 15.0.0.0 release, that is no longer necessary. The MetaModel object is now available from the Meta property of the Services object.

Executing a JSON Query

In this example, a JSON query is used to get all Story assets with an estimate greater than ten:

var query =
    "{" +
    "  \"from\": \"Story\"," +
    "  \"select\": [\"Name\",\"Estimate\"]," +
    "  \"filter\": [\"Estimate>'10'\"]" +
    "}";
            
var result = services.ExecutePassThroughQuery(query);
Console.WriteLine(result);

This is an example of the raw JSON data that is returned:

[
  [
    {
      "_oid": "Story:6555",
      "Name": "Test Story on Scope:6527 - Name attribute",
      "Estimate": "24"
    },
    {
      "_oid": "Story:6588",
      "Name": "Test Story Scope:6527 Query filter with multiple attributes",
      "Estimate": "24"
    }
  ]
]

Executing a YAML Query

In this example, a YAML query is used to get all Story assets with an estimate greater than ten, the raw JSON that is returned is the same as when submitting the query in a JSON format:

var query =
    "from: Story\n" +
    "select:\n" +
    "  - Name\n" +
    "  - Estimate\n" +
    "filter:\n" +
    "  - Estimate>'10'";
            
var result = services.ExecutePassThroughQuery(query);
Console.WriteLine(result);
  • Was this article helpful?