【问题标题】:POST users import v2 internal server errorPOST 用户导入 v2 内部服务器错误
【发布时间】:2021-07-29 12:39:05
【问题描述】:

我正在为我的公司开发一个全自动管道,我们在其中自动设置项目、添加用户并使用 BIM360 上的不同 API 上传文件。在添加用户的阶段,我收到 500 内部服务器错误:

{"code":2000,"message":"no implicit conversion of String into Integer"}

我们使用的是双腿身份验证方法,因此标头如下所示:

授权: Bearer (拥有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 标头有关,但我无法弄清楚。

【问题讨论】:

  • 这似乎是后端代码问题。您需要包含代码。
  • 使用代码对帖子进行了编辑。
  • accountIdprojectId 字符串还是整数?
  • 它们是字符串

标签: autodesk-forge


【解决方案1】:

不要像我一样忘记将有效负载包装到一个数组中,如文档中所述。将其用作有效负载

@"[{
                      ""email"": """ + userToAddEmail + @""",
                      ""services"": {
                                ""project_administration"": {
                                    ""access_level"": """ + userPrivilege + @"""
                                },
                                ""document_management"": {
                                    ""access_level"": """ + userPrivilege + @"""
                                }
                            },
                      ""industry_roles"": []
                    }]";

【讨论】:

    猜你喜欢
    • 2019-10-03
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 2014-09-24
    相关资源
    最近更新 更多