Testing DataMotion APIs with Insomnia REST Client

janellephalon

Janelle Phalon

Posted on June 19, 2023

Testing DataMotion APIs with Insomnia REST Client

Video demonstration

Introduction

APIs, or Application Programming Interfaces, play a critical role in enabling seamless interaction and data exchange between software applications. As the backbone of many web-based services, APIs have become increasingly important, delivering efficiency and functionality across platforms.

Testing these APIs is a crucial step to ensure smooth operation and early detection of any potential issues. In this guide, we'll walk you through how to test and validate DataMotion's Secure Message Center API using the Insomnia REST Client, a user-friendly tool suitable for developers of all experience levels.

DataMotion aims to empower users to seamlessly integrate secure data exchange directly into their workflows. By leveraging DataMotion's robust APIs and no-code solutions, you can work within your enterprise applications while delivering a secure and streamlined experience to your end-users.

Prerequisites

Before we begin, ensure you have the following:

  • An active DataMotion account. You'll need this to access the Secure Message Center API.
  • The Insomnia REST Client installed on your system. If you haven't installed it yet, download it from the official website.

Acquiring the Access Token

The first step in API testing is authentication. To make API calls to DataMotion's v3 APIs, an Access Token is required. This token can be obtained by making a POST request to the Token endpoint.

Detailed information about the Token API endpoint, along with other Secure Message Center APIs, can be found in DataMotion's Developer Center. For the sake of this tutorial, here are the steps to obtain the Access Token:

  • In your Insomnia workspace, create a new POST request and name it Get Access Token.
  • The URL for the request is: https://api.datamotion.com/SMC/Messaging/v3/token for DataMotion customers, and https://api.datamotion.com/SMC-Sandbox/Messaging/v3/token for trial members.
  • In the Body section of the request, select JSON and input the following:
{
    "grant_type": "client_credentials",
    "client_id": "your-client-id",
    "client_secret": "your-client-secret"
}
Enter fullscreen mode Exit fullscreen mode

Remember to replace "your-client-id" and "your-client-secret" with your actual credentials.

  • After confirming that your details are correct, send the request. A successful request will return a 200 status code and your Access Token in the response.

Here's what a successful token request looks like:

Token API Call

Testing the 'Get Message Summaries' API Call

With your Access Token in hand, you're now ready to start testing the various Secure Message Center API endpoints. We'll start with the 'Get Message Summaries' API call, which provides a summary of all your messages.

Following the same process as above, we can find details for the 'Get Message Summaries' API call in DataMotion's Developer Center. Here's how to set up the request in Insomnia:

  • Create a new GET request and name it Get Message Summaries.
  • The URL for this request is: https://api.datamotion.com/SMC/Messaging/v3/content/messages/?folderId=1&pageSize=10&pageNumber=1&sortDirection=DESC&metadata=true for DataMotion customers, and https://api.datamotion.com/SMC-Sandbox/Messaging/v3/content/messages/?folderId=1&pageSize=10&pageNumber=1&sortDirection=DESC&metadata=true for trial members.
  • In the Headers section, add your Access Token for authorization and set the "Content-Type" to "application/json".
{
    "Authorization": "Bearer your-access-token",
    "Content-Type": "application/json"
}
Enter fullscreen mode Exit fullscreen mode

Ensure you replace "your-access-token" with the actual Access Token.

  • After confirming your details are correct, send the request. If successful, you'll receive a summary of your messages in the response.

Here's how a successful API call setup looks:

Get Messages API Call

Handling API Errors

During testing, you may encounter errors, which typically appear as 400, 401, 403, or 500 response codes. These codes often signal issues with your request parameters or Access Token. In case of an error, carefully review your request setup and retry the request.

Here's an example of what an error response may look like:

{
    "error": "InvalidRequest",
    "errorMessage": "Invalid request.",
    "data": null
}
Enter fullscreen mode Exit fullscreen mode

Remember, encountering errors is part of the learning process. Troubleshooting these issues will further hone your proficiency in API testing!

Conclusion

Congrats - you've successfully begun testing APIs using DataMotion's Secure Message Center APIs and the Insomnia REST Client. This is just the start—continue applying these principles to other APIs and advancing your skills.

For more examples, check out my previous blog post on Composing and Sending a Secure Message with DataMotion APIs. Further, DataMotion's Developer Center is a comprehensive resource on all their APIs.

Keep learning, keep testing, and happy coding!

💖 💪 🙅 🚩
janellephalon
Janelle Phalon

Posted on June 19, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related