Confused with new API to receive data

I’ve been using a code like this to get the data from a Stream and Branch:

    public class SpeckleModel
    {
        public Client Client { get; private set; }
        public Account Account { get; private set; }
        public Stream Stream { get; private set; }
        public Branch Branch { get; private set; }

        public SpeckleModel(Client client, Account account, Stream stream, Branch branch)
        {
            Client = client;
            Account = account;
            Stream = stream;
            Branch = branch;
        }

        public async Task<Base> GetData()
        {
            var objectId = Branch.commits.items[0].referencedObject;
            var transport = new ServerTransport(Client.Account, Stream.id);
            return await Operations.Receive(objectId, remoteTransport: transport);
        }
    }

Now I’m not sure how to get the objectId to get the data:

using System.Linq;
using System.Threading.Tasks;
using Speckle.Core.Api;
using Speckle.Core.Api.GraphQL.Models;
using Speckle.Core.Credentials;
using Speckle.Core.Models;
using Speckle.Core.Transports;

namespace EdsaSpeckleManager.Command.Core.Models
{
    public class SpeckleModel
    {
        public Client Client { get; private set; }
        public Account Account { get; private set; }
        public Project Project { get; private set; }
        public Model Model { get; private set; }

        public SpeckleModel(Client client, Account account, Project project, Model model)
        {
            Client = client;
            Account = account;
            Project = project;
            Model = model;
        }

        public async Task<Base> GetData()
        {
            
            var objectId = // ?????
            var transport = new ServerTransport(Client.Account, Project.id);
            return await Operations.Receive(objectId, remoteTransport: transport);
        }
    }
}

I couldn’t find any documentation regarding this new API.

Thanks!

Try,

    var objectId = Model.versions.items[0].referencedObject;

We indeed have a lot of documentation to renew.

The API you have been using will not stop working for now if you can bear waiting. If not, in the meantime, your IDE will be your guide.

1 Like

you can also use dotpeek to see the .dll library as a reference, works for me :slight_smile:
dotPeek: Free .NET Decompiler & Assembly Browser by JetBrains

2 Likes

Hi @jonathon . I’ve tried using your solution but it’s giving me null in versions and version properties:

This is the url for reference:

main - VDC Project | Speckle

Hi @efdiloreto ,

how are you fetching these Model objects?

If you’re using client.Model.Get then this will fetch the model only, no versions.
If you want versions, you need to call client.Model.GetWithVersions

see speckle-sharp-sdk/src/Speckle.Sdk/Api/GraphQL/Resources/ModelResource.cs at 6f5f0440959fbd5a655e85ce084d62b6d39deb2f · specklesystems/speckle-sharp-sdk · GitHub

Alternatively, you can use client.Version.GetVersions if it suits your needs better

2 Likes

To demystify this a little,

All plain Get functions (Project.Get , Model.Get , Version.Get ) are not nested queries, they just fetch the Project/Model/Version requested. We weren’t being super consistent with this in the past, with some functions being nested, and others not.
You’ll also notice that all the nested functions expose extra parameters for limits, filters, and cursors. These are all optional but useful if you need to query for lots of Projects/Models/Versions.

For this reason, the doc comments we added to the old BranchGet does reference the existence of both Model.Get and Model.GetWithVersions as potential upgrades. But the best docs for what is/isn’t queried is the source code its self - which is freely available on GitHub.


You can also craft your own GraphQL queries/mutations, and execute them with Client.ExecuteGraphQLRequest<T>, however, you’ll need to define a suitable query string and response class.

Thanks @Jedd ! For taking the time to help and explaining this. Will try it and if it’s works will put it as solution.

2 Likes