1

I tried multiple time and double check the item ID and project Id I am useing are correct, but still I get this error response:

{ "developerMessage":"The requested resource does not exist.", "moreInfo": "https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/", "errorCode": ""}

Could there anyone help to suggest if there something wrong with my code here below?

Console.WriteLine("start");
// Set up HttpClient
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://developer.api.autodesk.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

// Set up access token
string accessToken = GetToken().Result;
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

// Set up request parameters
string projectId = Program.projectId;

// Get project attributes
string requestUrl = $"bim360/docs/v1/projects/{projectId}/folders/{folderId}/custom-attribute-definitions";
HttpResponseMessage response = client.GetAsync(requestUrl).Result;
string responseContent = response.Content.ReadAsStringAsync().Result;

// Verify version id
var versionApi = new VersionsApi();
versionApi.Configuration.AccessToken = GetToken().Result;
//Console.WriteLine(versionApi.GetVersion("b."+projectId,versionId_TestFile));
Console.WriteLine();

// Parse response JSON
dynamic attributes = JsonConvert.DeserializeObject(responseContent);
Console.WriteLine(attributes.results);

dynamic updatedAttributes = new[]
{
    new { id = 3630054, value = "I luv uu" },
    new { id = 3555365, value = "I luv uu" },
};

// Update project attributes
requestUrl = $"bim360/docs/v1/projects/{projectId}/versions/{versionId_TestFile}/custom-attributes:batch-update";
var patchContent = new StringContent(JsonConvert.SerializeObject(updatedAttributes), Encoding.UTF8, "application/json");
var patchResponse = await client.PostAsync(requestUrl, patchContent);
string patchResponseContent = await patchResponse.Content.ReadAsStringAsync();
Console.WriteLine(patchResponseContent);

Console.Read();

I am trying to update the customs attribute for the file saved in ACC.

user16217248
  • 3,119
  • 19
  • 19
  • 37

1 Answers1

0

Please, certify you're using:

  • Valid token with data:read and data:write scopes
  • Valid project id (without b.)
  • Version id (URL encoded)
  • Folder id (URL encoded)
  • Valid custom attribute id

A tool such as Insomnia or Postman can be very helpful for testing in these cases ;)

Just updated a custom attribute with your snippet (tried to change the least possible, just hard-coded some variables).

// Set up access token
        string accessToken = "your token here";

        // Set up HttpClient
        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri("https://developer.api.autodesk.com/");
        //client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);


        // Set up request parameters
        string projectId = "project id without b. prefix here";
        string folderId = "URL encoded folder id";

        // Get project attributes
        string requestUrl = $"bim360/docs/v1/projects/{projectId}/folders/{folderId}/custom-attribute-definitions";
        //dynamic responsenew = await GetRequest(baseAddress + requestUrl, accessToken);
        HttpResponseMessage response = client.GetAsync(requestUrl).Result;
        string responseContent = response.Content.ReadAsStringAsync().Result;

        // Verify version id
        var versionApi = new VersionsApi();
        versionApi.Configuration.AccessToken = accessToken; 

        // Parse response JSON
        dynamic attributes = JsonConvert.DeserializeObject(responseContent);
        Console.WriteLine(attributes.results);

        dynamic updatedAttributes = new[]
        {
                new { id = custom_attribute_id, value = "I luv uu" }
        };

        
        string versionId_urlencoded = "your version id URL encoded";

        // Update project attributes
        requestUrl = $"bim360/docs/v1/projects/{projectId}/versions/{versionId_urlencoded}/custom-attributes:batch-update";
        var patchContent = new StringContent(JsonConvert.SerializeObject(updatedAttributes), Encoding.UTF8, "application/json");
        var patchResponse = await client.PostAsync(requestUrl, patchContent);
        string patchResponseContent = await patchResponse.Content.ReadAsStringAsync();
        Console.WriteLine(patchResponseContent);

        Console.Read();
João Martins
  • 388
  • 3
  • 10