Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Using REST to find User ID from email address

ScottNess3
Collaborator III

I need to take an email address that is entered on a web form and find the Archer user ID number in order to update a user field.  In testing, I can update the field with a hard coded value for the user ID 3166:

 

"27654": {
"Type": 8,
"Tag": "director",
"Value":{
"UserList":
[{"ID":3166}],
"GroupList":
[{"ID":1}]},
"FieldID": 27654" 

 

The web form will capture an email address that matches the user, and I think I may have to use the "usercontact" API endpoint?  But am not clear on how to find the user ID value?

 

I looked through PowerShell REST API Get User Info -Body?? but I'm not going to have the value for UserName.

Jeff Letterman

TIA

16 REPLIES 16

I looked through both of those, but for my use I do not have an instance with Visual Studio installed where I can test.

Ok, my ODATA testing was with the API Templates application...sorry about that.  

 

The last issues with the code is the dollar sign for "$filter" in the value and the letter V is not capitalized for "s/Value".  PowerShell sees $filter as a variable and inserts a blank value.  To escape the dollar sign, use the backtick (`).  For more details, check out about_Quoting_Rules - PowerShell | Microsoft Docs and about_Special_Characters - PowerShell | Microsoft Docs.

 

URL method

$api_url = $base_url + "/api/core/system/usercontact?`$filter=Contacts/any(s:tolower(s/Value) eq 'scott.ness@sabre.com')"‍‍

 

Body method using back-to-back double-quotes to make one double-quote.

$body = "{""Value"": ""?`$filter=Contacts/any(s:tolower(s/Value) eq 'scott.ness@sabre.com')""}"‍‍‍

or use a Here-String.

$body = @"
{
"Value": "?`$filter=Contacts/any(s:tolower(s/Value) eq 'scott.ness@sabre.com')"
}
"@‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

That did it.  Thanks for all of the assistance.

Jeff - can you provide some information on the part of the ODATA filter using "s:tolower".  I've found that if the email value is all lower case, then there is no issue.  However, if the email value is "Scott.Ness@sabre.com" then no result is returned.  The same when using the API tool, so that's why I'm guessing it is related to that piece of filter condition.  Are there other options that will allow for an upper case character?  

 

This returns a value:

{
"Value": "?$filter=Contacts/any(s:tolower(s/Value) eq 'scott.ness@sabre.com')"
}‍‍‍

{
"Links": [],
"RequestedObject": {
"UserId": 10492,
"Contacts": [
{
"ContactType": 7,
"ContactSubType": 2,
"IsDefault": true,
"Value": "Scott.Ness@sabre.com",
"Id": 14809
},

But this returns no value:

{
"Value": "?$filter=Contacts/any(s:tolower(s/Value) eq 'Scott.Ness@sabre.com')"
}

Thanks

In the filter, the s:tolower(s/Value) function will convert the API response values into all lower case and then compare it to the value you are looking up.  The lookup value (scott.ness@sabre.com) needs to be in all lower case too because the equals operator (eq) is case sensitive.

Thanks for that clarification.  Means I need to ensure the team developing the web form converts the email address value to all lower case before passing the value to the API call.

RyanSwank1
Advocate

@JeffLetterman  love this example and is almost exactly what I'm looking to do but more of a 'contains' use case.

I am trying endswith instead b/c there is no 'contains' operator in ODATA (could use substring but in my use case the text is at the end - email domain).

My use case is to find all user accounts where the default email for the user account is NOT my company's main email domain. 

I'm using the API add-in and used the following in the request object but getting an error:
{ "Value": "?$filter=endswith(Contacts/any(s:endswith(s/Value),'@mydomain.com') eq false)" }‍‍‍‍‍‍‍‍‍

"WebApi:WebApiOdataValidationException",
"Description": "')' or ',' expected at position 41 in 'endswith(Contacts/any(s:tolower(s/Value),'@mydomain.com') eq false)'.",

My parens seems to align but is the problem that endswith is nested w/ any?
thanks!