Error: object code name '' is not valid, while creating user using API,

joyanta sen asked on June 19, 2018 19:19

Hi, I am getting the following error while inserting new user using the API. I am trying to create user by running a task, which will read a csv file and create the user.

The object code name '' is not valid. The code name can contain only alphanumeric characters, some special characters (_, -, .) and cannot start or end with '.'.,

Could you please let me know how to resolve this.

Thanks, Joyanta

Correct Answer

Brenden Kehren answered on June 19, 2018 19:54

The code name for a user object is the username. Set the username to the email address and debug the code on task execution and look through the object to find out what's null.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on June 19, 2018 19:24

What does your code look like which runs in the scheduled task? Looks like you're not passing a proper code name for possibly a user object.

0 votesVote for this answer Mark as a Correct answer

joyanta sen answered on June 19, 2018 19:36

Dear Brenden, Thanks for your response. I not passing anything from the Task. Its a simple code of creating User like below: public string Execute(TaskInfo task) { UserInfo userInfo = UserInfoProvider.GetUsers().WhereEquals("CWID", userData[1]).FirstOrDefault(); if (userInfo == null) { userInfo = new UserInfo(); userInfo.SetValue("CWID", userData[1]); userInfo.FirstName = userData[2]; userInfo.LastName = userData[3]; userInfo.Email = userData[4]; userInfo.SetValue("UserCode", userData[5]); userInfo.SetValue("StreetAddressOne", userData[6]); userInfo.SetValue("StreetAddressTwo", userData[7]); UserInfoProvider.SetUserInfo(userInfo); } }

Could you please let me know what do I need to pass and how?

Thanks.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 19, 2018 19:45

I'd suggest adding in the UserName property and setting that to the users email address. Keep in mind you may want to update your query though to make sure it doesn't find an email in the username as well.

UserInfo userInfo = UserInfoProvider.GetUsers().WhereEquals("CWID", userData[1]).Or().WhereEquals("Email", userData[4]).FirstOrDefault();

1 votesVote for this answer Mark as a Correct answer

joyanta sen answered on June 19, 2018 19:51

Hi, I am getting the issue while user is not present into the database(when userInfo is null) and I am creating new user. In that case how to set the code name?

Thanks.

0 votesVote for this answer Mark as a Correct answer

joyanta sen answered on June 19, 2018 19:56

Hi,

It resolved after assigning the UserName property.

Thanks a lot..

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 19, 2018 19:59

Great to hear! Be sure to mark the correct answer and vote up any answers which helped you.

0 votesVote for this answer Mark as a Correct answer

joyanta sen answered on June 19, 2018 20:15

Hi, One question, is there any document or link which tells, which field to be used as a code name for the build in objects? And in case of custom object, how will we decide the code name?

Thanks.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 19, 2018 20:18

You can read through the API documentation but I don't believe it says which fields are code name and which aren't. You can always look in the Modules as well and see if you can find it too but as you work with Kentico more you'll find out how things work.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.