使用APS Forge API更新ACC文件自定义属性失败求助
问题排查请求
我多次确认所用的project ID和item ID均正确,但调用APS Forge API更新存储在ACC中的文件自定义属性时,仍收到如下错误响应:
{ "developerMessage":"The requested resource does not exist.", "moreInfo": "https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/", "errorCode": ""}
麻烦帮忙排查以下代码是否存在问题:
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();
排查方向
- Project ID格式一致性:调用VersionsApi时用了
"b."+projectId,但更新属性的请求直接用projectId。ACC/BIM 360的project ID部分接口要求带前缀(如b.或a.),需确认更新接口是否需要带前缀的ID。 - Version ID有效性:取消注释
versionApi.GetVersion的输出,确认该version ID确实存在且属于目标项目,避免无效ID导致资源不存在。 - 属性ID匹配性:确认
3630054和3555365这两个属性ID属于当前文件所在的文件夹/项目,且该文件版本允许使用这些属性。 - 请求方法正确性:
custom-attributes:batch-update接口可能要求用PATCH而非POST,需核对官方文档确认正确请求方法,当前代码用PostAsync可能不符合要求。 - 异步调用混用问题:代码同时用
.Result(同步阻塞)和await,可能引发死锁或上下文异常,建议统一改为异步方式(外层方法设为async,替换所有.Result为await)。 - 权限范围验证:确认access token包含
data:write权限,且对应的用户拥有修改该文件属性的权限。
内容的提问来源于stack exchange,提问作者Zepeng Zhao
相关产品推荐
相关产品推荐

