Need a REST API with a GET method where in the URL, the user’s email address sent as a query param
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 12:15 AM
Need a REST API with a GET method where in the URL, the user’s email address sent as a query param so that in the response we could receive a Boolean response in JSON format is this possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 10:41 PM
@kiran kumar m1 No, the sample response is as follows-
{
"result": [
{
"calendar_integration": "1",
"country": "",
"last_position_update": "",
"user_password": "$s$RVw2zmwlhreWxVznzmtsev3LLjdHKoySUTvl2W0Q328=$ltNsTS8p/M7E4ucVxBJaq0vAuTNBAGrq1hZq8wxUvNE=",
"last_login_time": "2020-04-01 10:18:29",
"source": "",
"sys_updated_on": "2024-02-26 06:07:42",
"u_national_id_number": "",
"building": "",
"u_national_id_type": "",
"web_service_access_only": "false",
"notification": "2",
"u_assigned_cases": "",
"enable_multifactor_authn": "false",
"sys_updated_by": "guest",
"sso_source": "",
"sys_created_on": "2007-07-03 18:48:47",
"agent_status": "",
"sys_domain": {
"link": "/api/now/table/sys_user_group/global",
"value": "global"
},
"u_password_last_reset": "",
"state": "",
"vip": "false",
"sys_created_by": "fred.luddy",
"longitude": "",
"u_type_of_user": "Vendor Manager",
"zip": "",
"home_phone": "",
"u_country": "",
"time_format": "",
"last_login": "2020-04-01",
"default_perspective": "",
"geolocation_tracked": "false",
"active": "true",
"time_sheet_policy": "",
"sys_domain_path": "/",
"cost_center": "",
"phone": "",
"name": "System Administrator",
"employee_number": "",
"u_assigned_case_tasks": "",
"password_needs_reset": "false",
"gender": "",
"city": "",
"failed_attempts": "5",
"user_name": "admin",
"latitude": "",
"roles": "admin",
"title": "System Administrator",
"sys_class_name": "sys_user",
"sys_id": "6816f7***be04be441",
"internal_integration_user": "false",
"ldap_server": "",
"mobile_phone": "",
"street": "",
"company": "",
"u_password": "",
"u_xbl_device_token": "",
"department": {
"link": "/api/now/table/cmn_department/a581ab703710200044e0bfc8bcbe5de8",
"value": "a581ab**8bcbe5de8"
},
"first_name": "System",
"email": "admin@example.com",
"introduction": "",
"preferred_language": "",
"manager": "",
"locked_out": "false",
"sys_mod_count": "109",
"last_name": "Administrator",
"photo": "",
"avatar": "c148e1de41f149",
"u_last_latitude": "",
"middle_name": "",
"sys_tags": "",
"time_zone": "",
"schedule": "",
"on_schedule": "",
"date_format": "",
"location": "",
"u_last_longitude": ""
}
]
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 12:53 AM
Hi @kiran kumar m1,
Try this :
GET https://<instance_name>.service-now.com/api/<api_version>/<resource_path>?email=user@example.com
or make user@example.com as ${email} variable and do variable subistutions from related link.
var email = request.queryParams.email;
var user = new GlideRecord('sys_user');
user.addQuery('email', email);
user.query();
if(user.next()){
var responseBody = {
"emailExists": exists
};
}
I hope this helps...
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 12:17 AM
Hi @Sohail Khilji its throwing an error stating that email exists is not defined , I have defined that and trying that but its giving true for all the cases
this is my code
may I know where I am going wrong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 01:32 AM
Why are you not using OOB Table API? For this, please try-
(function process(request, response) {
// Extract the email parameter from the request query parameters
var email = request.queryParams.email;
// Initialize a GlideRecord object for the sys_user table
var user = new GlideRecord('sys_user');
// Add a query to find the user with the specified email
user.addQuery('email', email);
// Execute the query
user.query();
// Check if any user with the specified email exists
var emailExists = user.hasNext();
// Prepare the response body
var responseBody = {
"emailExists": emailExists
};
// Set the response body and status
response.setBody(responseBody);
response.setStatus(200);
})(request, response);
Please mark my answer helpful and correct.
Regards,
Amit