我尝试了多次并仔细检查了我使用的项目 ID 和项目 ID 是否正确,但我仍然收到此错误响应
{ "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();
我正在尝试更新保存在 ACC 中的文件的海关属性。
请证明您正在使用:
诸如Insomnia或Postman之类的工具在这些情况下对测试非常有帮助;)
刚刚用您的代码片段更新了自定义属性(尝试尽可能少地更改,只是硬编码了一些变量)。
// 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();