# Test API in Sandbox using Insomnia
source: https://developer.mastercard.com/community-pass-payment-apis/documentation/api-tutorials/backup/test-api-using-insomania-old/index.md

[Insomnia](https://insomnia.rest/) is a popular open-source REST client application that works on Windows, Mac, and Linux operating systems. It is a handy tool for developers to test API calls by simply filling in the parameters without writing any code.

The MCPP APIs can also be tested with this tool. This tutorial will help you set up the Insomnia tool and test the API in Sandbox. You can follow similar steps to test API in Production once your access is approved.

### What you will learn: {#what-you-will-learn}

> * How to configure the API for testing via the Insomnia tool.
> * How to set up the Sandbox environment in the Insomnia tool.
> * How to encrypt and decrypt payloads.
> * How to test MCPP APIs in the Insomnia tool.

### Estimated time to complete this tutorial {#estimated-time-to-complete-this-tutorial}

> * 15-20 minutes

## Pre-requisites {#pre-requisites}

1. Create a project for the MCPP APIs.
2. [Insomnia](https://insomnia.rest/download/) tool installed.
3. [Mastercard Insomnia Plugin](https://developers.mastercard.com) installed.

Tip: To create your project on Mastercard Developers, refer to [Getting Started](https://developer.mastercard.com/community-pass-payment-apis/documentation/getting-started/index.md) for more information.

## Set up Sandbox Environment {#set-up-sandbox-environment}

1. Create a new workspace by selecting the "Create Workspace" option from the drop-down of the top-left purple bar.
2. Name the workspace as "MCPP APIs" and click **Create** . ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia1.PNG "Test API in Sandbox using Insomnia")
3. Add Sandbox as one of the environments.
4. Go to "Manage Environments" from the "No Environment" drop-down list. ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia2.PNG "Test API in Sandbox using Insomnia")
5. Click '+' and select "Environment" to create a new environment. ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia3.PNG "Test API in Sandbox using Insomnia")
6. Name the new environment as "Sandbox" by double-clicking the "New Environment" on the left-side under "Sub Environments". ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia4.PNG "Test API in Sandbox using Insomnia")
7. Copy and paste the below configuration under Sandbox and click **Done** to finish.

```Java
{
    "host": "<HOST URL>",
    "mastercard": {
        "consumerKey": "<CONSUMER KEY>",
        "keyAlias": "<KEY ALIAS>",
        "keystoreP12Path": "<PATH to .p12 FILE>",
        "keystorePassword": "<KEYSTORE PASSWORD>"
    }
}
```

![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia5.PNG "Test API in Sandbox using Insomnia")

8.The Insomnia tool is successfully set up. Follow the next section.

## Configure Sandbox Environment {#configure-sandbox-environment}

Now, as your Insomnia tool has been set up, let's configure it by adding the Sandbox environment.

1. Log in to your Mastercard Developers account and go to your project.
2. Use the following details from the "Sandbox" section of your project:
   * Consumer Key
   * Key Alias
   * Keystore Password
3. Use the following details:
   * host as `https://sandbox.api.mastercard.com`
   * keystoreP12Path as the absolute location of the .p12 file which was generated during your project creation
4. Go to the **Manage Environments** of Insomnia tool and update the configurations as shown below and click Done to finish. ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia6.PNG "Test API in Sandbox using Insomnia")
5. The Insomnia tool is successfully configured and ready to test the API in Sandbox. Follow the next section below.

## Invoking MCPP APIs {#invoking-mcpp-apis}

This section provides step-by-step directions to call the /payment service from the Insomnia tool.

1. Click '+' beside the 'Filter' text-box and select the "New Request" option to create a new request. ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia7.PNG "Test API in Sandbox using Insomnia")
2. Name the request as "Callback", select the request method as "POST", body type as "JSON" and click Create. ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia8.PNG "Test API in Sandbox using Insomnia") ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia9.PNG "Test API in Sandbox using Insomnia") ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia10.PNG "Test API in Sandbox using Insomnia")
3. Configure the request URL by copy and pasting the text **{{host}}/community-pass/payment/callbacks** in the request URL. ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia11.PNG "Test API in Sandbox using Insomnia")
4. The endpoint you will call requires [payload encryption](https://developer.mastercard.com/platform/documentation/security-and-authentication/securing-sensitive-data-using-payload-encryption/).


Tip: You can also refer to the reference application
[client-encryption-app.zip](https://static.developer.mastercard.com/content/community-pass-payment-apis/referenceapp/client-encryption-app.zip) (2MB) which we have created for you to encrypt the request payload. Please walkthrough the steps mentioned in README.md to generate encrypted request payload.
Sample encrypted request payload generated from client encryption reference application. ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia-payload-encrypt.PNG "Test API in Sandbox using Insomnia") 5. Configure the request payload by copy and paste encrypted payload from Step-4. ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia12.PNG "Test API in Sandbox using Insomnia") 6. Send the request by clicking the **Send** button. You should see a successful response with **200** OK. ![Test API in Sandbox using Insomnia](https://static.developer.mastercard.com/content/community-pass-payment-apis/uploads/insomnia13.PNG "Test API in Sandbox using Insomnia") 7. You have successfully invoked MCPP APIs `/callbacks` end point from the Insomnia tool. 8. You can invoke other services by following steps 1-6 of this section. Check other service endpoints on the [API Reference](https://developer.mastercard.com/community-pass-payment-apis/documentation/api-reference/index.md) page.

<br />

### Services Testability list {#services-testability-list}

The following table captures the services of MCPP APIs that can be tested using Insomnia:

|        Service        |        Endpoint         | Testable using Insomnia |
|-----------------------|-------------------------|-------------------------|
| Payment Callbacks     | /payments/callbacks     | Yes                     |
| Payment Notifications | /payments/notifications | Yes                     |
| Payment Validations   | /payments/validations   | Yes                     |

Note: The [Community Pass Payment service](https://developer.mastercard.com/community-pass-payment-apis/documentation/use-cases/index.md) expects an encrypted request object as it contains PCI data. To understand how to encrypt a request object, refer to the [Build an end-to-end application](https://developer.mastercard.com/community-pass-payment-apis/documentation/api-tutorials/build-end-to-end-application/index.md) tutorial.

### Congratulations {#congratulations}

You have successfully completed this tutorial and setup Insomnia tool to call MCPP APIs.

### Next Steps {#next-steps}

You should check out the following resources:

* [Request for Production Access](https://developer.mastercard.com/community-pass-payment-apis/documentation/api-tutorials/move-to-production/index.md)
* [API Reference](https://developer.mastercard.com/community-pass-payment-apis/documentation/api-reference/index.md)
