Avatar

User API and User Custom Fields

Diana Lewis

I added a custom field to my users and use the api to add/inactivate/update users. The http request works fine without the custom field but when I add custom field to it I get error 520. Has anyone added custom fields to their users and also added users via the User API? When I look at the json, the format looks correct according to the add user tutorial. 

Follow 3 followers
0

4 comments

Avatar
William Sayama 0 votes

Hi Diana, could you share with us what your request looks like? That will help us debug the issue.

0
Comment actions Permalink
Avatar
Diana Lewis 0 votes

Yes, thank you. The custom field type is "user selection". I'm wondering if the issue could have something to do with the field type since this code worked until I added the "customItemValues" part in the json below. 

string jsonUsers = "{\"users\":" + JsonConvert.SerializeObject(addNewUsers) + "}";
 
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://###.kintone.com/v1/users.json"))
{
 
byte[] toBeEncoded = System.Text.ASCIIEncoding.ASCII.GetBytes("username:" + "userpassword");
 
var encoded2 = System.Convert.ToBase64String(toBeEncoded);
 
request.Headers.TryAddWithoutValidation("X-Cybozu-Authorization", encoded2);
 
request.Content = new StringContent(jsonUsers);
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
 
var response = await httpClient.SendAsync(request);
}
}
 
jsonUsers value:
{"users":[
     {
          "code":"UserCode",
         "valid":"True",
        "password":"#####",
        "name":"User Name",
        "surName":"LastName",
       "givenName":"FirstName",
       "LocalNameLocale":"en",
       "timezone":"America/New_York",
       "locale":"en",
       "email":"email@email.org",
       "employeeNumber":"#####",
      "customItemValues":[
          {
                 "code":"supervisor",                       //This is a custom user field of "User Selection" Type
                 "value":"UserCode". 
          }
        ]
     }
]}
0
Comment actions Permalink
Avatar
Sean Tachibana 1 vote

Hi Diana,

After opening "kintone", start the developer tools and execute the following request on the console screen.
I was able to add the user.
 
var parm = {

"users": [

{

"code" : "UserCode",

"valid" : true,

"password" : "#####",

"name" : "User Name",

"surName" : "LastName",

"givenName": "FirstName",

"localNameLocale": 'en',

"surNameReading": "hogehoge",

"givenNameReading": "hogehoge",

"localName": "hogehoge",

"timezone": 'America/New_York',

"locale": 'en',

"customItemValues":[

{

"code":"supervisor",

"value":"1"

}

]

}

]

}




kintone.api(

'/v1/users',

'POST',

parm,

function(event){console.log(event);},

function(err){console.log(err);}

);

 

The following "520" error occurred when the "value" value in the "customItemValues" array was specified
as a login name, such as "user".
 
---<< Error details >>---
 
code: "SLASH_IL22"
id: "xPu5BmUYMXdAZrD5l7uM"
message: "The JSON data of the user (code: UserCode) is invalid. "
 
Perhaps the error is caused by specifying the login name for the "Select User" type customization item.
 
Could please check if the login name is not specified in the "value" value in the "customItemValues" array,
or if it is, please change it to the user ID (numerical value) to see if that improves the situation?
 
Also, if possible, please let us know the details of the response when the "520" error occurs.
 
Hopefully, this helps.
1
Comment actions Permalink
Avatar
Diana Lewis 1 vote

Thank you for your help!

That was it exactly. I had to use the user ID for it to work.

1
Comment actions Permalink