autodesk-forge - POST 用户导入 v2 内部服务器错误
问题描述
我正在为我的公司开发一个全自动管道,我们在 BIM360 上使用不同的 API 自动设置项目、添加用户和上传文件。在添加用户的阶段,我收到 500 内部服务器错误:
{"code":2000,"message":"no implicit conversion of String into Integer"}
我们使用的是两条腿的身份验证方法,因此标头如下所示:
授权: Bearer <token>(拥有account:write权限)
x-user-id: ************ (我的管理员帐户的 uid)
内容类型:应用程序/json
请求内容是这样的:
@"{
""email"": """ + ***@********.** + @""",
""services"": {
""document_management"": {
""access_level"": """ + admin+ @"""
},
""project_administration"": {
""access_level"": """ + admin+ @"""
}
},
""industry_roles"": []}";
我只是似乎无法弄清楚我做错了什么。希望可以有人帮帮我。
编辑:此请求的完整代码
public async static Task<HttpStatusCode> AddUserToProjectEmail(string projectId, string accountId, string accessToken, string userToAddEmail, string userPrivilege, string adminUserId)
{
using (HttpClient httpClient = new HttpClient())
{
using (HttpRequestMessage request = new HttpRequestMessage())
{
//Documentation for what to put in the Http POST: https://forge.autodesk.com/en/docs/bim360/v1/reference/http/projects-project_id-users-import-POST/
request.Method = new HttpMethod("POST");
request.RequestUri = new Uri("https://developer.api.autodesk.com/hq/v2/regions/eu/accounts/" + accountId + "/projects/" + projectId + "/users/import");
//Make the request payload
string jsonPayload = AddPayloadToUserAddEmail(userToAddEmail, userPrivilege);
request.Content = new StringContent(jsonPayload);
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
request.Headers.Add("x-user-id", adminUserId);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
//Send request
var response = await httpClient.SendAsync(request);
return response.StatusCode;
}
}
}
以及请求有效载荷方法:
private static string AddPayloadToUserAddEmail(string userToAddEmail, string userPrivilege)
{
string payload = @"{
""email"": """ + userToAddEmail + @""",
""services"": {
""project_administration"": {
""access_level"": """ + userPrivilege + @"""
},
""document_management"": {
""access_level"": """ + userPrivilege + @"""
}
},
""industry_roles"": []
}";
return payload;
}
我已经通过 BIM360 上的 URL 检查了所有 ID,但是我认为无法检查我的帐户的 Uid。
编辑 2:我应该注意,在添加 x-user-id 标头之前,我遇到了一个不同的错误,它只是说禁止,这是有道理的。这使我认为它与 x-user-id 标头有关,但我无法弄清楚。
解决方案
不要像我一样忘记将有效负载包装到一个数组中,如文档中所述。使用它作为有效载荷工作
@"[{
""email"": """ + userToAddEmail + @""",
""services"": {
""project_administration"": {
""access_level"": """ + userPrivilege + @"""
},
""document_management"": {
""access_level"": """ + userPrivilege + @"""
}
},
""industry_roles"": []
}]";
推荐阅读
- python - 覆盖属性获取行为,但只能通过 Python 中的外部方法
- html - 如何将我的网址从 https://example.com/name.html 更改为 https://example.com/name?
- javascript - 使用map循环遍历数组时返回null而不是JSX
- ruby-on-rails - 设计 current_user 不是用户实例
- opengl - textureLodOffset 和 texelFetchOffset 相对于它们的预期偏移量有什么区别?
- javascript - 我的功能没有按照定义进行识别(React)
- javascript - 单击窗口/另一个元素时如何更改所有元素的颜色?
- iis - 如何使用 IIS 压缩所有文件
- javascript - 修改 JS 代码以导入 ES 模块以修复错误:Uncaught SyntaxError: Unexpected token 'export'
- python - 如果我导入它,是否可以以某种方式在一个文件中编写一个 def 函数并在另一个文件中使用它?