Oracle by Example brandingGet Started with Workers REST API - Get a Worker

section 0Before You Begin

This 15-minute tutorial shows you how to get a worker record.


section 1Get 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.
  1. Add a request to ##_WorkersCollection.

  2. Give the request the name Get Worker by Email.
  3. Click Save to ##_WorkersCollection.
  4. Specify the method as GET.
  5. 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

  6. Give the request the following headers:

    Note: Headers can be saved in presets in postman for reuse.

    Key Value
    REST-Framework-Version 4
  7. 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.

  8. Click Save.

section 2Get 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.

  1. Edit the Get Worker by Email request.

  2. 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}}

  3. Send the request.

    You should now get results for your employee and pending worker.

    Make a note of the employee's PersonId.

  4. Save the request.

section 3Get a Worker Using a Finder

View Available Finders

Use Describe to view available finders for workers.

  1. Add a request to ##_WorkersCollection.

  2. Give the request the name Get Worker Metadata.
  3. Click Save to ##_WorkersCollection.
  4. Specify the method as GET.
  5. Enter the url:

    {{url}}/hcmRestApi/resources/latest/workers/describe

  6. Give the request the following headers:

    Note: Headers can be saved in presets in postman for reuse.

    Key Value
    REST-Framework-Version 4
  7. Click Send.

  8. 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.

  9. Save the request.

Get Worker Information Using Finder

  1. Add a request to ##_WorkersCollection.

  2. Give the request the name Get Worker by Finder.
  3. Click Save to ##_WorkersCollection.
  4. Specify the method as GET.
  5. Enter the url:

    {{url}}/hcmRestApi/resources/latest/workers?finder=findByPersonId;PersonId=1000,SysEffectiveDate={{5DaysAhead}}&effectiveDate={{5DaysAhead}}&expand=workRelationships.assignments.managers,nationalIdentifiers,addresses,phones

  6. Give the request the following headers:

    Key Value
    REST-Framework-Version 4
  7. 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);
     
  8. Click Send.

    The test script will create global variables for the links needed in the rest of the exercises.

  9. Save the request.

next stepNext Tutorial

Managing a Worker's Person Information Using Workers REST API