This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C# Rest Api Getting the unique id of the object

I have a web project that I am developing for mfiles. My main goal is to reach the document object under the personnel object. I have tried many ways for this, but I keep getting errors because the data is too much. I also want to access the unique id of the document object to try another way. How can I view id of document objects with rest api.
Parents
  • When you retrieve object data from the vault, you'll retrieve an "ObjVer" property.  This ObjVer property contains the ID, type, and version numbers of the object.  The combination of the type and ID uniquely identify the object in the vault.  The addition of the version number uniquely identifies this version of this object in the vault.

  • Well then How can I implement this in my code to access attached child objects? My codes are as follows.

     

    var conditions = new List<ISearchCondition>
    {
    new QuickSearchCondition(nameSurname),
    new ObjectTypeSearchCondition(0),
    };

    var results = client.ObjectSearchOperations.SearchForObjectsByConditions(conditions.ToArray());

    foreach (var objectVersion in results)
    {
    var number = objectVersion.DisplayID;
    var folderPath = new System.IO.DirectoryInfo(System.IO.Path.Combine(downloadFolder,objectVersion.ObjVer.ID.ToString()));
    if (false == folderPath.Exists)
    folderPath.Create();
    if (objectVersion.ObjVer.ID==)
    foreach (var file in objectVersion.Files)
    {
    var fileName = System.IO.Path.Combine(folderPath.FullName, file.ID + "." + file.Extension);
    await client.ObjectFileOperations.DownloadFileAsync(objectVersion.ObjVer.Type,
    objectVersion.ObjVer.ID,
    objectVersion.Files[0].ID,
    fileName,
    objectVersion.ObjVer.Version);
    return Ok($"{fileName}");
    }
    }

  • What do you mean by "child object"?  There are a few things you could mean by this.

    Can you show a screenshot of M-Files, showing the object you have in the search results plus its metadata plus the object that you want to retrieve?

  • I want to access "Documents" object under the Austin District Redevevolopment object. How can I do this with c# rest api?  I am using the MFaaP.MFWSClient library.

  • Okay.  Whilst there is a concept of "owner" or "parent" objects (i.e. one object can be the "child" of another), that is not what's happening here.  What you are seeing is the result of relationships.

    In M-Files objects can have relationships.  A relationship is created by a property on one object (e.g. object A) pointing at a property on another object (e.g. object B).  In this case, object A is related to object B and object B is related to object A.

    When you view objects in the desktop or web clients, M-Files allows you to "expand" one object and see what relationships it has.  In the screenshot you posted, "Austin District Redevelopment" has relationships to a number of other objects, including some documents.

    Using the REST API you can retrieve relationships using this endpoint.  This allows you to optionally define whether you want objects that relate from the current object to others (e.g. objects that Austin District Redevelopment points to), or other objects that relate to the current object (e.g. objects that point to Austin District Redevelopment), or both.

    I don't think that the sample C# library has an existing wrapper for this endpoint.  As the library says: it is only for reference, may be incomplete, and has no support.  If you wanted to add support then you should follow the contribution guidelines to create a pull request containing the change.  The method signature and parameters should follow the conventions used in the COM API equivalent, where possible.

Reply
  • Okay.  Whilst there is a concept of "owner" or "parent" objects (i.e. one object can be the "child" of another), that is not what's happening here.  What you are seeing is the result of relationships.

    In M-Files objects can have relationships.  A relationship is created by a property on one object (e.g. object A) pointing at a property on another object (e.g. object B).  In this case, object A is related to object B and object B is related to object A.

    When you view objects in the desktop or web clients, M-Files allows you to "expand" one object and see what relationships it has.  In the screenshot you posted, "Austin District Redevelopment" has relationships to a number of other objects, including some documents.

    Using the REST API you can retrieve relationships using this endpoint.  This allows you to optionally define whether you want objects that relate from the current object to others (e.g. objects that Austin District Redevelopment points to), or other objects that relate to the current object (e.g. objects that point to Austin District Redevelopment), or both.

    I don't think that the sample C# library has an existing wrapper for this endpoint.  As the library says: it is only for reference, may be incomplete, and has no support.  If you wanted to add support then you should follow the contribution guidelines to create a pull request containing the change.  The method signature and parameters should follow the conventions used in the COM API equivalent, where possible.

Children
  • So is there any other way to achieve this other than relationships? Can't we find it by comparing it over a property that is the same in both objects?
  • Let's say you have loaded an object and its properties - Austin District Redevelopment.  Some of these properties will be lookups that may point to other objects in the vault (they may also point to value list items, not objects, but let's ignore that for now).

    In this particular case you could read the properties for Austin District Redevelopment and use those to identify the properties that indicate relationships FROM that object TO others, but you cannot use that to identify relationships in the other direction; those FROM other objects TO it.  The only way to do that is to effectively execute a search ("find me all objects that have a property that point to Austin District Redevelopment"), which is effectively what happens when you request those types of relationships via the API methods.

    In the SPECIFIC screenshot you posted, it's likely that the majority of the objects shown point TO Austin District Redevelopment, not FROM it.

    So, no, at a practical level you would need to use the API endpoints (or manually replicate what they do with searches) to achieve what you want.  My strong suggestion is to use the dedicated endpoints.