I am trying to use the User API to add users.
I have used it successfully for a long time, but it no longer works recently. I am wondering if something changed.
I am posting my code below.
Could you please review it to see if I am doing anything wrong?
Thank you.
var AddUsers = vaiUsers.Where(p => !kintoneUsers.Any(p2 => p2.employeeNumber == p.WdEmployeeId)).ToList();
var SUBDOMAIN = "example_subdomain";
List<object> NewUsers = new List<object>();
foreach (var item in AddUsers)
{
NewUsers.Add(new
{
code = item.AdUserId.Trim().ToLower(),
valid = true,
password = newKintoneUserPassword,
name = item.FirstName + " " + item.LastName,
surName = item.LastName,
givenName = item.FirstName,
localNameLocale = "en",
timezone = "America/New_York",
locale = "en",
email = item.EmailAddress.ToLower(),
employeeNumber = item.WdEmployeeId,
customItemValues = new List<CustomItemValue> { new CustomItemValue { code = "supervisor", value = (from k in kintoneUsers where k.employeeNumber == item.WdManagerId01 select k.id).FirstOrDefault() } }
});
string jsonUpdateUsers = "{\"users\":" + JsonConvert.SerializeObject(splitAddUserInKintone) + "}";
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), $"https://{SUBDOMAIN}.kintone.com/v1/users.json"))
{
byte[] toBeEncoded = System.Text.ASCIIEncoding.ASCII.GetBytes("apiUser:" + apiUserPassword);
var encoded2 = System.Convert.ToBase64String(toBeEncoded);
request.Headers.TryAddWithoutValidation("X-Cybozu-Authorization", encoded2);
request.Content = new StringContent(jsonUpdateUsers);
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
var response = await httpClient.SendAsync(request);
}
}
}