Leverage ServiceNow REST API: Integrate & Create Records Selectively
Tags: api, webdev, cloud, cloudcomputing
Published: 2024-06-19 19:27:45

**ServiceNow** offers a powerful tool for integrating with external applications: the REST (Representational State Transfer) API. This inbound web service allows external applications and clients to interact with data within your ServiceNow instance in a controlled manner.

Think of it as a set of well-defined functions that enable you to send requests and receive responses from other applications using HTTP protocols. 
Common REST HTTP methods include:
	•	GET: Retrieve data from a third-party application.
	•	PUT: Update data within a third-party application.
	•	POST: Create new data within a third-party application.
	•	DELETE: Delete data from a third-party application.
	•	PATCH: Partially update data within a third-party application.

###Use Case: Creating a ServiceNow Record from Another Application with Selective Field Copying

This scenario demonstrates how to create a ServiceNow record from another application while including specific fields from being copied into the ServiceNow record.

####1. Setting Up the Inbound Web Service

•Navigate to **Web Services > Inbound**. This is where you define how external applications can interact with your ServiceNow data.
•Fill in the **Label Name** (a user-friendly name for your integration).
Select the **Target Table** where the data will be stored (e.g., Incident table).
•Under **Web Service Fields**, define the fields you'll receive from the third-party application. These are the fields required to create a record in ServiceNow (e.g., caller, short description).
•Click **Create**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/840wfeefyee9fj13xg52.jpeg)

####2. Configuring the Transform Map

•Upon creation, a **Transform Map** is generated. This map translates data from the source table (where the third-party application sends data) to the target table (the ServiceNow table you selected).
•Click on **Automapping Assist** to automatically map fields from source to target.
Review and adjust the mappings as needed.
•Click **Save** to save the transform map.

####3. Testing the Web Service

•Locate your newly created inbound web service in the **Application Navigator**.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/64i9fweicjx7j0jt1cvr.jpeg)

•Under **Related Links**, click **Explore REST API**. This interface allows you to test the web service before integrating with the third-party application.
•On the **Explore REST API** interface, you'll see the staging table name and a request body section.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p2340y1oszv53jhmktiw.jpeg)

•In the request body, enter test data for the fields you defined earlier.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/athhwhqymn1or9foz70d.jpeg)

•Click **Send**. 
Remember, request formats for ServiceNow REST APIs are always in JSON format.

####4. Verifying Successful Test

•A successful test will return a status code of **201 (Created)**.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1ynp3z8o8tp79lgm9du.jpeg)

•The response body will display a newly created test record.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qgl4krg8fe8ejvv72gah.jpeg)

•Double-check by navigating to **Incident > Open** to confirm the test record exists.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2524sg1fawam0zsbouf9.jpeg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vaa7rsiz5piqdldkfy8.jpeg)

####5. Integration with Third-Party Application (HoppScotch)
🔗:https://hoppscotch.com/

Now, let's integrate your ServiceNow instance with a third-party application called HoppScotch to create records directly from HoppScotch.
#####Configuration on HoppScotch

•Use the **POST** method as you're creating a new record.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4pgrkht8io7gb9r71cy.jpeg)

•In the **Request URL**, copy the **method URL** from the ServiceNow REST API Explorer. This URL defines the resource where data will be posted.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qw1jvacdj9uvd688nigg.jpeg)

•For **Authorization**, select **Basic Auth** and enter your ServiceNow username and password. This ensures secure communication between applications.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awvuklaoi3frkm7dxic9.jpeg)

•Under **Headers**, set the **Content-Type** to **application/json**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v8j8j3m2m150mfrh2z3l.png)

•In the **Body** section, copy and paste the request body data from the ServiceNow REST API Explorer. This data defines the information to be included in the new record.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lw7mnt8mv523wvxnli4h.jpeg)

•Click **Send**.

####6. Confirmation and Verification

•A successful creation will return a status code of **201 (Created)**.
The response body will contain details about the import set, staging table, and the newly created ServiceNow record.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bt6g0qttjiv193lny667.jpeg)

•Navigate back to your ServiceNow instance under **Incident > Open** to confirm the record was successfully created.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ij8kdyp16jrpko3ptfci.jpeg)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7l6vt1d2ujgec2d5huak.jpeg)

###Conclusion

Congratulations! You've successfully utilized ServiceNow's REST API to create a record in your instance through a third-party application.
                🎊🎊
####Expand Your Toolkit: Exploring Additional REST API Clients
Beyond HoppScotch, several other tools offer functionalities similar to API testing, development, and collaboration. Here are a few popular options:

•Insomnia:[https://insomnia.rest/]
•Paw: [https://paw.cloud/]
•Postman:[https://www.postman.com/]
•SwaggerHub: [https://swagger.io/tools/swaggerhub/]
________________
####Further Learning:
For a deeper dive into ServiceNow REST API functionalities and methods, refer to the ServiceNow product documentation on REST APIs.
•ServiceNow REST API: https://docs.servicenow.com/bundle/washingtondc-application-development/page/integrate/inbound-rest/concept/c_RESTAPI.html

•ServiceNow REST API reference: https://docs.servicenow.com/bundle/washingtondc-api-reference/page/build/applications/concept/api-rest.html