Forge Model Derivatives: GET metadata always returns 202

Viewed 31

I'm trying to get the Derivative Tree Json view of a large file in nwd format, but it always responds with the status code 202:

{"result":"success"}

My objective is to get the dbids of the first level of the tree with its name. If this works, it would be to get their properties via {urn}/metadata/{modelGuid}/properties

RestClient client = new RestClient("https://developer.api.autodesk.com");
RestRequest request = new RestRequest("/modelderivative/v2/designdata/{urn}/metadata/{modelGuid}", Method.Get);
request.AddHeader("Authorization", "Bearer " + authenticate.access_token);

//request.AddHeader("x-ads-force", true);                
request.AddHeader("Content-Type", "application/json");
request.AddParameter("urn", urn, ParameterType.UrlSegment);
request.AddParameter("modelGuid", guid, ParameterType.UrlSegment);
request.AddParameter("forceget", true, ParameterType.QueryString);
request.AddParameter("objectid", 1, ParameterType.QueryString);
request.AddParameter("level", 1, ParameterType.QueryString);

var response = await client.ExecuteAsync(request);

if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
{
    var result = response.Content;
}

Who can help? Thanks

2 Answers

According to the documentation Fetch Object Tree, the status code 202 means : "Request accepted but processing not complete. Call this endpoint iteratively until a 200 is returned."

It seems pretty normal if you are working with a large model. But you should be able to get the 200 response after waiting some time.

Appending what Alex said, you can use do-while to check if the response code is 200.

ApiResponse<dynamic> treeRes = null;
do
{
    treeRes = await // Your API reqeust here

    if (treeRes == null) throw new InvalidOperationException('Failed to get tree');

    if (treeRes.StatusCode != 200)
        System.Threading.Thread.Sleep(60 * 1000);
}
while (treeRes.StatusCode != 200);

var properties = treeRes.Data;

Related