CreateUser doesn't recognize userLicenseTypeId parameter

771
0
10-28-2020 09:00 AM
JamisonLovely
New Contributor

When creating a user I get a failure response with an error code of 500 and an error message of "No user license type id specified". But I have specified the license type:

public async Task AddUser(ApplicationUser user)
{
   var addUserURL = Urls.AddUser;
   var tokenResult = await GetTokenForAdmin();

   var parameters = new MultipartFormDataContent
   {
      { new StringContent(tokenResult.token), "token" },
      { new StringContent("json"), "f" },
      { new StringContent(user.Email), "username" },
      { new StringContent(user.Email), "email" },
      { new StringContent("P@ssw0rd"), "password" },
      { new StringContent(user.FirstName), "firstname" },
      { new StringContent(user.LastName), "lastname" },
      { new StringContent("org_user"), "role" },
      { new StringContent("creatorUT"), "userLicenseTypeId" },
   };

   var result = await HttpClient.PostAsync(addUserURL, parameters);

   if (result == null)
   {
      throw new InvalidDataException($"{nameof(AddUser)} POST to {addUserURL} returned null result");
   }
   else if (result.Content == null)
   {
      throw new InvalidDataException($"{nameof(AddUser)} POST to {addUserURL} returned null result.Content");
   }

   using var reader = new StreamReader(await result.Content.ReadAsStreamAsync());
   var addUserResult = await reader.ReadToEndAsync();
   dynamic addUserResponse = JsonConvert.DeserializeObject(addUserResult);
   if (addUserResponse.status != "success")
   {
      throw new Exception($"Failed to add user to ArcGIS Portal. Error: {addUserResponse.error.code}          {addUserResponse.error.message}");
   }
}

0 Replies