POST 用户导入 v2 内部服务器错误

POST users import v2 internal server error

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

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

我们正在使用 two-legged 身份验证方法,因此 header 看起来像这样:

授权: Bearer (拥有account:write权限)

x-user-id: ************(我的管理员帐户的用户名)

Content-Type: application/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 header 之前我得到了一个不同的错误,它只是说禁止这使得感觉。这使我认为它与 x-user-id header 有关,但我无法弄清楚。

不要像我一样忘记按照文档中的说明将有效载荷包装到数组中。将其用作有效载荷

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