Creating an Endpoint URL for UKG Webhooks
Introduction
In this document, we will explain what it means to create an endpoint URL for a webhook in simple, non-technical terms. Webhooks are a way for different software systems to communicate with each other automatically. Creating an endpoint URL is an essential step in setting up a webhook. Additionally, we will guide you on how to consume the webhook payload and use that data to automate business processes with subsequent API (Application Programming Interface) calls to other SaaS (Software As A Service) providers you may utilize.
What is a Webhook?
A webhook is like a digital message that gets sent from one system to another when something specific happens. For example, if you receive a new message on a social media platform, a webhook can automatically send that information to another system, like an email or a chat application.
What is an Endpoint URL?
An endpoint URL is like a digital mailbox where these webhook messages are sent. It is a web address (URL) that tells the system where to deliver the webhook messages. When you create an endpoint URL, you’re setting up this digital mailbox to receive the information you want.
Steps to Create an Endpoint URL
1. Choose a Platform
First, decide where you want to receive the webhook messages. This could be a website, an application, or a service that can handle webhooks. Here are some common platforms:
- Zapier
- IFTTT
- Microsoft Teams
- ServiceNow
- Salesforce
- Postman
2. Set Up Your Endpoint With Chosen Platform
Using Zapier
To set up your endpoint with Zapier, use the following steps:
- Sign in to Zapier.
- Create a New Zap: Look for an option to create a new Webhook or custom trigger.
- Select Webhooks by Zapier: Choose the Webhook option when prompted.
- Copy the URL: The service will provide you with a unique URL. This is your endpoint URL.
Using IFTTT
To set up your endpoint with IFTTT, use the following steps:
- Sign in to IFTTT.
- Create a New Applet: Click Create to start a new applet.
- Click + this and search for “Webhooks”.
- Select “Receive a web request” as the trigger.
- Enter an Event Name (e.g., incoming_webhook).
- Click Create trigger.
- Click + that to define what happens when the Webhook is received.
- Select the service and action you want to perform when the Webhook is triggered (e.g., send an email, create a spreadsheet row, etc.).
- Click Finish to complete the configuration.
- Copy the URL: Go to the Webhooks service page on IFTTT, click Documentation, and copy the URL provided, for example:
https://maker.ifttt.com/trigger/{event_name}/with/key/{your_key}
.
Using Microsoft Teams
To set up your endpoint with Microsoft Teams, use the following steps:
- Open MS Teams and log in with your account.
- Navigate to the channel where you want to receive the Webhook messages.
- Click on the ellipsis (...) next to the channel name and select Connectors to add a connector.
- In the connectors list, search for Incoming Webhook.
- To add an incoming Webhook, click Add and then Add to a team.
- Configure the Webhook:
- Use the Name field to give your Webhook a meaningful name.
- Click Create to generate the Webhook URL.
- Copy the generated Webhook URL which will be used to send data to the MS Teams channel.
Using ServiceNow
To set up your endpoint with ServiceNow, use the following steps:
- Go to your ServiceNow instance and log in with an account that has administrative privileges.
- To view your Scripted Rest APIs, navigate to System Web Services > Scripted REST APIs or search for Scripted REST APIs in the application navigator.
- Click New to create a Scripted REST API:
- Name: Give your API a meaningful name.
- API ID: This will be auto-generated based on the name.
- Base API Path: Define a base path for your API. For example: /api/webhook.
- Within the newly created API, click New under the Resources related list to add a resource:
- Name: Give your resource a name.
- HTTP Method: Select POST as the method since webhooks typically send data via POST requests.
- Relative Path: Define a relative path for this resource. For example: /receive.
- In the resource, add your script logic.
- Ensure that the assigned user roles have the necessary permissions to execute this API.
- Go to System Web Services > REST API Access and configure the access controls for your API.
- Get the Endpoint URL: The URL for your webhook endpoint will be in the format: https://.service-now.com/api/<base_api_path>/<relative_path>
Example URL: If your instance is named dev12345, and you used /api/webhook as the base path and /receive as the resource path, the URL would be: https://dev12345.service-now.com/api/webhook/receive
Using Salesforce
To set up your endpoint with Salesforce, use the following steps:
- Go to your Salesforce instance and log in.
- Navigate to Setup > Apex Classes.
- To create a new Apex class, click on New and create an Apex class, for example:
```java @RestResource(urlMapping='/webhook/*') global with sharing class WebhookReceiver { @HttpPost global static void doPost() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; // Process the incoming request String requestBody = req.requestBody.toString(); // Add your custom logic to handle the webhook payload System.debug('Received webhook: ' + requestBody); res.responseBody = Blob.valueOf('Webhook received'); res.statusCode = 200; } } ```
- (Optional) Set up a Salesforce site: If you want the webhook to be accessible from the internet without requiring authentication, you need to set up a Salesforce site.
- Navigate to Setup > Sites and click New, following the steps to create a new site and ensuring that the site is active. To set up the site, configure the site settings (including the URL) and ensure that the necessary Apex class is accessible by the guest user profile.
- To set guest user permissions, navigate to Setup > Sites, click on the name of your site, then click on Public Access Settings.
- In the profile, add permissions for the
WebhookReceiver
Apex class. Click Enabled Apex Class Access. Add theWebhookReceiver
class to the enabled list. - Get the URL: The URL for your webhook endpoint will be in the format: https://.force.com/services/apexrest/webhook/
Note: Replace ` with the actual name of your Salesforce site.
Using Postman
To set up your endpoint with Postman, use the following steps:
- Go to your Postman account and log in.
- To create a new Mock Server, navigate to New in the top left corner and select Mock Server.
- Select Collection: Choose an existing collection or create a new one.
- Add a Mock Server: Click Add Example and give the example a name (for example: "Webhook Request").
- Define URL Path: Set the request type to POST and define a path for the webhook (for example: /webhook).
- Save and Mock Server URL: Save the example and note the mock server URL provided by Postman. This URL will be used to receive the webhooks.To navigate to Postman Flows in Postman, select the Flows tab. If it is not already visible, the Flows feature must be enabled.
- To create a new flow, click New Flow and name your flow (for example: Webhook Flow).
- Add a Request Block by dragging and dropping a Request block onto the canvas.
- Method: Set it to POST.
- URL: Use the mock server URL you created earlier (e.g., https://<mock_server_id>.mock.pstmn.io/webhook).
- Body: You can define the expected body schema here.
- To add a Test Block, drag and drop a Test block after the Request block to process the incoming webhook data.
- Script: Add JavaScript to process the incoming data. Here's an example script that logs the webhook payload:
let webhookData = pm.request.body.raw;
console.log('Received webhook payload:', webhookData);
// Add your custom processing logic here
- Connect Blocks: Ensure that the Request block is connected to the Test block.
- Click Save to save your flow.
- Get the URL: The URL for your webhook will be the mock server URL you noted earlier (e.g., https://<mock_server_id>.mock.pstmn.io/webhook). If your mock server ID is 123456, the URL would be: https://123456.mock.pstmn.io/webhook
3. Integrate with Your Source System UKG Webhooks
Now, you need to tell your UKG Webhooks subscription that will be sending the webhooks where to send them. This involves:
- Login to UKG Webhooks: UKG Webhooks - Login
- Add a subscription: Add Subscription
- Enter or paste the URL you got from your chosen platform into the "Endpoint URL" field.
4. Test the Webhook
It’s important to make sure everything is set up correctly:
- Trigger an Event: Perform an action that should trigger the webhook, see event catalog: UKG Webhooks Events Catalog or use the UKG Webhooks "Test an endpoint" feature: Test an endpoint
- Check the Delivery: Go back to your chosen service and check if the webhook was received. The service should show the received data.
5. Monitor and Maintain
Once everything is set up:
- Monitor the Webhooks: Regularly check to ensure that webhooks are being sent and received correctly.
- Update as Needed: If you change services or need to update the URL, repeat the steps above.
Consuming the Webhook Payload
When a webhook is triggered, it sends data (payload) to your endpoint URL. Here’s how to handle that data:
1. Understanding the Payload
The payload is the data sent by the webhook. It usually contains information about the event that triggered the webhook. This data is typically in JSON format, which looks something like this:
{
"EventId": 518577181,
"EventTime": "2024-06-03T17:38:57.397",
"EventType": "EmployeeAddressChangeEvent",
"Operation": "Update",
"Payload": {
"CoId": “YOUR_COMPANY_IDENTIFIER”,
"EeId": “YOUR_EMPLOYEE_IDENTIFIER”,
"IntegrationRecordId": null
},
"Tenant": "YOUR_TENANT"
}
2. Processing the Payload
You’ll need to set up a way to receive and process this data. Here’s a basic approach:
- Server Setup: Set up a server to receive the webhook data. This could be a simple script running on a web server that listens for incoming requests at your endpoint URL.
- Parse the Data: Write a script to parse the JSON payload. Extract the necessary information from the payload to use in your business logic.
3. Automate Business Processes
Once you have the payload data, you can use it to automate various business processes by making API calls or posting data to other SaaS providers. Here’s how:
Example: Using UKG API for retrieving Employee demographics
- Receive Webhook: Your server receives a webhook payload from UKG Webhooks for an employee address change event.
- Parse Payload: Extract relevant details like EeId, CoId from payload, US-Customer-API-Key From the headers.
- Get the change details for the Employee: Use UKG’s API to get the Employee demographic details that have changed. Employee Demographic API
import requests
url = "https://YOUR_COMPANY_HOST/personnel/v1/employee-demographic-details?employeeId=YOUR_EMPLOYEE_IDENTIFIER&companyId=YOUR_COMPANY_IDENTIFIER”
payload = {}
headers = {
'US-Customer-Api-Key': ‘YOUR_API_KEY’,
'Authorization': 'Basic YOUR_BASIC_AUTH’
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
- Use the data from the API response: Using MS Team’s channel webhook URL to post a message in a specific channel with the employees changed data.
import requests
import json
# Get the endpoint URL from Teams channel > Manage Channel > Connectors > Incoming Webhook
url = "https://your_company.webhook.office.com/webhookb2/0e14d875-7242-462e-ae19/IncomingWebhook/8afebe45bb64450bb3938f4c74/"
payload = json.dumps({
"personId": "{personId}",
"employeeId": "{employeeId}",
"companyId": "{companyId}",
"addressLine1": "{addressLine1}",
"addressLine2": "{addressLine2}",
"addressLine3": "{addressLine3}",
"addressLine4": "{addressLine4}",
"addressCity": "{addressCity}",
"addressState": "{addressState}",
"addressZipCode": "{addressZipCode}",
"addressCountry": "{addressCountry}",
"addressCounty": "{addressCounty}"
})
headers = {
'Content-Type': 'application/json'
}
# Send employee adderess details from the response to my Teams Channel
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Updated 3 months ago