Search code examples
c#versionone

Accesing to specific attribute into rest1-v1 threw versionone.sdk.Api in C#


I'm trying to access to a specific value stored in the rest1-v1 api of versionOne.

I can acces to it typing the whole adress into my favorite navigator

rest-1.v1/Data/Actual?sel=Date,Value&where=Workitem.ID='Story:114192'

which returns:

<Assets total="1" pageSize="2147483647" pageStart="0">
    <Asset href="/VersionOne/rest-1.v1/Data/Actual/158630" id="Actual:158630">
        <Attribute name="Date">2014-10-23</Attribute>
        <Attribute name="Value">40</Attribute>
    </Asset>
</Assets>

What I would like to do, is to access to the attribute "Value" listed above but threw the versionone.sdk.ApiClient.

I did all the stuff about connector (meta and data), but I really do not figure out how to make my query to return this value stored into this API.

I hope I am clear enough,

Regards,


Solution

  •         V1APIConnector dataConnector = new V1APIConnector("YourVersionOne/rest-1.v1/","username", "password");
            V1APIConnector metaConnector = new V1APIConnector("YourVersionOne/meta.v1/");
    
            IMetaModel metaModel = new MetaModel(metaConnector);
            IServices services = new Services(metaModel, dataConnector);
            IAssetType actualType = metaModel.GetAssetType("Actual");
    
            IAttributeDefinition dateAttribute = actualType.GetAttributeDefinition("Date");
            IAttributeDefinition valueAttribute = actualType.GetAttributeDefinition("Value");
            IAttributeDefinition workitemAttribute = actualType.GetAttributeDefinition("Workitem");
            Query query = new Query(actualType);
    
            query.Selection.Add(dateAttribute);
            query.Selection.Add(valueAttribute);
    
            FilterTerm term = new FilterTerm(workitemAttribute);
            term.Equal("Story:114192");
            query.Filter = term;
    
            QueryResult result = services.Retrieve(query);
    

    BTW, you didn't need Workitem.ID in your url query. Workitem is fine.