Closed Miminoux closed 3 years ago
By the way, can you tell me what is the field name to set the e-mail address plz ?
Hi
When you create a user and want to add him some email addresses you need to send an additional key in your input _useremails. This key is an array associating an numbeed index to an email address. To specify the default email address (the radio button in the GLPI UI) add an other key _default_email containing the numbered index of one of your email addresses provided in _useremails
See in inc/user.class.php User::post_addItem() to understand the implementation of the feature.
About the HTTP error code, I agree with you, only for creation of a single item. For multiple items, the HTTP return code shall be 207. It seems to be easy to implement.
@orthagh how would you vote for this suggestion ?
for a single item, without right, yes, we should have 401. For multiples items:
Hi, It doesn't seem to work for me : { "input": { "realname": "BOVAIS", "firstname": "José", "_profiles_id": 13, "name": "jose.bauvais@tutu.tata", "phone": 332, "_default_email": 0, "_useremails[0]": "jose.bauvais@tutu.tata", "usercategories_id": 1 } }
It creates José but with no email. I've read the PHP file you mentioned which helped me. Is this payload right for you ? I'm not and expert but I don't find in this function any line setting the user name according to input['name'] for example, same with realname, firstname... although it works.
Thank you Bye bye
Hello @Miminoux This is not the way to do an array with json. Here is a fixed example (Note the [...]):
{
"input": {
"realname": "BOVAIS",
"firstname": "José",
"_profiles_id": 13,
"name": "jose.bauvais@tutu.tata",
"phone": 332,
"_default_email": 0,
"_useremails": [
"jose.bauvais@tutu.tata"
],
"usercategories_id": 1
}
}
This one works too and has the advantage to give you control on indexes for each email address for use with _default_email (tested before sharing it here):
{
"input": {
"realname": "BOVAIS",
"firstname": "José",
"_profiles_id": 13,
"name": "jose.bauvais@tutu.tata",
"phone": 332,
"_default_email": 1,
"_useremails": { "0": "jose.bauvais@tutu.tata", "1": "jose.beauvais2@toto.tata"},
"usercategories_id": 1
}
}
Oh gosh, thanks... I'm also in trouble with the groups, I don't get hos to add my newly created user to a specific group. I've tried to pass the group ID in _groups : { "input": {... "_groups": [ "106" ]... I'm trying to use the search webservice to search my group but it does not return the ID field, I'm kinda lost... I search further later. Thanks anyway.
If you can read PHP, your best resource is reading the following methods for the classes related to your action:
sometimes (by the way, emails for an added user is a perfect example):
To add a group for a user you need
Again, read the code of the methods I pointed.
One more thing, when searching a group "/apirest.php.search/group?$search", using search : "criteria[0][field]=14&criteria[0][searchtype]=equals&criteria[0][value]=HAS" I can't find a group named "HAS" but when changing "equals" by "contains" then it works (the group is exactly "HAS"). I then tried the following search : "criteria[0][field]=14&criteria[0][searchtype]=equals&criteria[0][value]=106" And surprisingly, it worked ! What drives me mad is that field 14 is the name, not the ID... I don't know if it's a bug or if I misunderstood something ? Maybe you prefer a new ticket for this ? Just let me know.
And one last thing when searching for groups, the result doesn't show the ID, how can I get it when I only have the group name ? This is just for information because I tried a little bit to search group_user with group contains HAS and it returned some groups, I'm not blocked.
Thanks a lot for your replies, Bye bye
@Miminoux
This is normal. the operator Equals is not handled for most fields. If I remember correctly, this operator works for numeric values, not strings. So you need to use the operator contains.
Again, if I remember correctly, you may use regex anchors ^ and $ to have the same effect as equal operator. Try searching for ^HAS$ You should get your group, and it will exclude items like a_HAS a_HAS_b or HAS_B.
@bry, i think about this recurrent issue with has
/contains
.
It should be good if we detect a numeric or string value for has operator and in case of string value, shortcut with contains
'^string$'
OK I'll think improve the API this way
There has been no activity on this issue for some time and therefore it is considered stale and will be closed automatically in 10 days.
If this issue is related to a bug, please try to reproduce on latest release. If the problem persist, feel free to add a comment to revive this issue. If it is related to a new feature, please open a topic to discuss with community about this enhancement on suggestion website.
You may also consider taking a subscription to get professionnal support or contact GLPI editor team directly.
Hi, I'm using GLPI 9.2.1 (thanks for the late upgrade) and I have had troubles creating a user. Actually, I was lacking the appropriate right to do so. I think I have been lead in error by the return code which was 400 and not 401. Which one is the best in such a case ? I would vote for 401 ^^ Bye bye.