Before You Begin
This 15-minute tutorial shows you how to get a worker record.
Get a Worker by Email
This exercise demonstrates how to get a worker record by querying the worker's email.
This request uses parameters to:
- Query the worker's child object with the query parameter (q).
- Specify which fields to return with the fields parameter.
- Expand the child object with the expand parameter.
- Suppress the links with the onlyData parameter.
Add a request to ##_WorkersCollection.
- Give the request the name Get Worker by Email.
- Click Save to ##_WorkersCollection.
- Specify the method as GET.
Enter the url:
Note: Replace the ## in the url with the initials used to create the email in your employee body.
{{url}}/hcmRestApi/resources/latest/workers?q=emails.EmailAddress like '##_Work%'&fields=PersonNumber,PersonId;emails:EmailAddress&expand=emails&onlyData=true
Give the request the following headers:
Note: Headers can be saved in presets in postman for reuse.
Key Value REST-Framework-Version 4 Click Send.
You should get your pending worker as a result. Additionally, although you filtered on a specific email address this filter is applied at the worker level, so your response includes all emails for each worker, and not the one you searched on.
- Click Save.
Get a Future Effective Dated Worker
When we created our employee we entered an effective range start date in the future. We need to append the effective date parameter to the Get Worker by Email request to return our employee.
Edit the Get Worker by Email request.
Append the effective date parameter to the URL effectiveDate={{4DaysAhead}}.
The url should now be:
{{url}}/hcmRestApi/resources/latest/workers?q=emails.EmailAddress like '##_Work%'&fields=PersonNumber,PersonId;emails:EmailAddress&expand=emails&onlyData=true&effectiveDate={{4DaysAhead}}
Send the request.
You should now get results for your employee and pending worker.
Make a note of the employee's PersonId.
- Save the request.
Get a Worker Using a Finder
View Available Finders
Use Describe to view available finders for workers.
Add a request to ##_WorkersCollection.
- Give the request the name Get Worker Metadata.
- Click Save to ##_WorkersCollection.
- Specify the method as GET.
Enter the url:
{{url}}/hcmRestApi/resources/latest/workers/describe
Give the request the following headers:
Note: Headers can be saved in presets in postman for reuse.
Key Value REST-Framework-Version 4 Click Send.
The results include the workers object properties including a list of finders.
We are going to use the findByPersonIdFinder. We can see from the metadata this finder has two attributes: a required attribute called PersonId, and an optional attribute called SysEffectiveDate. Since our employee is future effective dated, we will need to use both of these attributes to get our worker using the finder.
Use the PersonId for the employee in the next exercise.
- Save the request.
Get Worker Information Using Finder
Add a request to ##_WorkersCollection.
- Give the request the name Get Worker by Finder.
- Click Save to ##_WorkersCollection.
- Specify the method as GET.
Enter the url:
{{url}}/hcmRestApi/resources/latest/workers?finder=findByPersonId;PersonId=1000,SysEffectiveDate={{5DaysAhead}}&effectiveDate={{5DaysAhead}}&expand=workRelationships.assignments.managers,nationalIdentifiers,addresses,phones
Give the request the following headers:
Key Value REST-Framework-Version 4 Enter the following code in the tests tab of the request.
var jsonData = JSON.parse(responseBody); //Get the link for the nationalIdentifiers collection obj = jsonData.items[0].nationalIdentifiers.links[0].href; pm.globals.set("NIDs_href", obj); //Get the link for the managers collection obj = jsonData.items[0].workRelationships.items[0].assignments.items[0].managers.links[0].href; pm.globals.set("Managers_href", obj); //Get the link for the addresses collection obj = jsonData.items[0].addresses.links[0].href; pm.globals.set("Addresses_href", obj); //Get the link for the address item obj = jsonData.items[0].addresses.items[0].links[0].href; pm.globals.set("Address_href", obj); //Get the link for a phones item obj = jsonData.items[0].phones.items[0].links[0].href; pm.globals.set("Phone_href", obj); //Get the link for the managers collection obj = jsonData.items[0].workRelationships.items[0].assignments.links[0].href; pm.globals.set("Assignment_href", obj); //Get the link for the add temporary assignment action needle = 'addTemporaryAssignment'; obj = jsonData.items[0].workRelationships.items[0].links; ref = ''; // iterate over each element in the array for (var i = 0; i < obj.length; i++){ // look for the entry with a matching `code` value if (obj[i].name == needle){ ref = obj[i].href; } } pm.globals.set("addTempAssignment_href", ref); //Get the link for the h2 email address needle = 'H1_02'; obj = jsonData.items[0].emails.items; ref = ''; // iterate over each element in the array for (var i = 0; i < obj.length; i++){ // look for the entry with a matching `code` value if (obj[i].EmailAddress.includes(needle)){ ref = obj[i].links[0].href; } } pm.globals.set("extra_email_href", ref);
Click Send.
The test script will create global variables for the links needed in the rest of the exercises.
- Save the request.
Next Tutorial
Managing a Worker's Person Information Using Workers REST API