Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

End-to-end implementation of a REST API POST method

This document outlines the end-to-end implementation of a REST API POST method using PeopleCode and JSON to fetch employee details from a third-party system and update a custom record in PeopleSoft. It includes steps for configuring the Integration Broker, creating a REST API, and writing PeopleCode to handle API requests and responses. The process involves setting up service operations, messages, routes, and handling JSON data to update employee records accordingly.

Uploaded by

shefali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

End-to-end implementation of a REST API POST method

This document outlines the end-to-end implementation of a REST API POST method using PeopleCode and JSON to fetch employee details from a third-party system and update a custom record in PeopleSoft. It includes steps for configuring the Integration Broker, creating a REST API, and writing PeopleCode to handle API requests and responses. The process involves setting up service operations, messages, routes, and handling JSON data to update employee records accordingly.

Uploaded by

shefali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

End-to-end implementation of a REST API POST method

End-to-end implementation of a REST API POST method using PeopleCode and JSON to fetch employee
details from a third-party system and update a custom record in PeopleSoft, you will need to follow
several steps. This involves setting up a REST API integration, handling JSON data, and updating
PeopleSoft records. Below is a detailed guide:

1. Configure Integration Broker

1. Create a Service Operation:

o Go to PeopleTools > Integration Broker > Service Operations.

o Click Add a New Value and enter a name for your service operation.

o Set the Service Operation Type to Request/Response.

2. Define the Service Operation:

o Define the Service Operation with a name, e.g., EMPLOYEE_API.

o Set Service Operation Type to Request/Response.

3. Create a Message:

o Go to Integration Broker > Integration Setup > Messages.

o Click Add a New Value to create a new message.

o Define the message type as XML or JSON based on your needs.

4. Create a Route:

o Go to Integration Broker > Integration Setup > Routes.

o Create a new route to connect to the third-party system's endpoint.

2. Create the REST API and PeopleCode

1. Define the REST API in PeopleSoft:

o Go to PeopleTools > Integration Broker > REST Services.

o Define a new REST service to interface with the third-party system.

2. Create a Custom Record:

o Go to PeopleTools > Application Designer > Records.


o Create a custom record to store employee details.

o Ensure this record has fields that match the data returned by the third-party system.

3. Write PeopleCode to Handle the REST API:

1. Define the REST API Consumer in PeopleCode:

import PS_PTRESTClient:RESTClient;
import PS_PTRESTClient:RESTResponse;

/* Define the API URL and Authentication if needed */


&apiUrl = "https://thirdpartyapi.com/getEmployeeDetails";
&authHeader = "Authorization: Bearer your_access_token";

/* Create a RESTClient object */


&restClient = CreateObject(PS_PTRESTClient:RESTClient);

/* Set the URL and Headers */


&restClient.URL = &apiUrl;
&restClient.SetHeader("Content-Type", "application/json");
&restClient.SetHeader("Authorization", &authHeader);

/* Prepare JSON payload */


&employeeId = "12345"; /* Replace with dynamic value if needed */
&doj = "2023-01-01"; /* Replace with dynamic value if needed */

&jsonPayload = CreateObject("PS_JSON:JSON");
&jsonPayload.SetValue("employeeId", &employeeId);
&jsonPayload.SetValue("doj", &doj);

/* Make the POST Request */


&response = &restClient.Post("", &jsonPayload.ToString());

/* Check for successful response */


If &response.StatusCode = 200 Then
&jsonResponse = &response.Body;
/* Process the JSON response */
&employeeData = CreateObject("PS_JSON:JSON");
&employeeData.LoadJSON(&jsonResponse);

/* Loop through the employee data and update the custom record */
For &i = 1 To &employeeData.GetItemCount()
&item = &employeeData.GetItem(&i);

&emplId = &item.GetValue("EMPLID");
&firstName = &item.GetValue("FIRST_NAME");
&lastName = &item.GetValue("LAST_NAME");
&email = &item.GetValue("EMAIL");

/* Update or Insert Record */


&record = CreateRecord(Record.PS_CUSTOM_EMPLOYEE);
&record.EMPLID = &emplId;
&record.FIRST_NAME = &firstName;
&record.LAST_NAME = &lastName;
&record.EMAIL = &email;

/* Check if the record exists */


&record.SelectByKey();
If &record.IsNull Then
/* Insert if not found */
&record.Insert();
Else
/* Update if found */
&record.Update();
End-If;
End-For;
Else
/* Handle errors */
MessageBox(0, "", 0, 0, "Error: " | &response.StatusCode | " " | &response.StatusMessage);
End-If;
2. Parse JSON and Update the Custom Record:

/* Example of parsing JSON and updating the custom record */


For &i = 1 To &employeeData.Len
&record = CreateRecord(Record.PS_CUSTOM_EMPLOYEE);
&record.EMPLID = &employeeData.GetItem(&i).EMPLID;
&record.FIRST_NAME = &employeeData.GetItem(&i).FIRST_NAME;
&record.LAST_NAME = &employeeData.GetItem(&i).LAST_NAME;
&record.EMAIL = &employeeData.GetItem(&i).EMAIL;

/* Update or Insert Record */


&record.Update();
End-For;

You might also like