# Postman: SeaLights API Collection

## Using the SeaLights Public API Postman Collection <a href="#using-the-sealights-public-api-postman-collection" id="using-the-sealights-public-api-postman-collection"></a>

This guide will walk you through using the Postman collection provided for our public API. The collection utilizes environment variables to streamline your requests.

**Target Audience**

This guide is intended for users with a basic understanding of Postman and API interactions.

**Prerequisites**

* A Postman account (free or paid) - [Postman: The World's Leading API Platform | Sign Up for Free](https://www.postman.com/)
* Our [Public API Documentation](https://api-doc.sealights.io/)

*Note: Throughout this guide, we'll use the term "env file" to refer to the Postman environment file.*

### Importing the Collection <a href="#importing-the-collection" id="importing-the-collection"></a>

1. Navigate to our [Public API Documentation](https://api-doc.sealights.io/).
2. Locate the "Run in Postman" button and click it.
   * Select your preference: Postman for Web or the Postman Desktop Client.

     <figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FLxvd7oxi7uEqHnn4OFsh%2FScreenshot%202024-04-30%20at%2016.36.39.png?alt=media&#x26;token=c089af56-533d-43cb-bacd-de4c248b3e8c" alt=""><figcaption><p><em>In this example, we’ll select Postman for Web</em></p></figcaption></figure>
3. Select the workspace into which you want to import the collection and click “Import”<br>

   <figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2F3KBreV4IEf9DoO0TOg0A%2FScreenshot%202024-04-30%20at%2016.47.22.png?alt=media&#x26;token=549ffa84-c108-4b05-91b1-4f58b99befb2" alt=""><figcaption><p><em>n this example, we’re importing to a workspace named Demo</em></p></figcaption></figure>

### Setting Up Your Environment <a href="#setting-up-your-environment" id="setting-up-your-environment"></a>

1. In the Postman sidebar, select Environments. Right-click on the pre-populated environment named "Demo Env" and select Duplicate.

   <figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Ffi1X22qKviXkz6MR49r5%2FScreenshot%202024-04-30%20at%2017.05.54.png?alt=media&#x26;token=cff104bd-7aa3-4280-8d34-da844baac5d4" alt=""><figcaption></figcaption></figure>
2. Right-click on "Demo Env Copy" and select Rename.<br>

   <figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FuS3diy72WlLoozMKeUc8%2FScreenshot%202024-04-30%20at%2016.49.10.png?alt=media&#x26;token=965c5d2f-aec8-4077-b68f-b37a1b2903e4" alt=""><figcaption></figcaption></figure>
3. Choose a descriptive name for your environment (e.g., "CompanyName Env") and save. *This will allow you to keep our demo environment file as a boilerplate, should you ever need to create more than one Postman environment.*

   <figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FgiEPU8fyKw1CcyG9SF5i%2FScreenshot%202024-04-30%20at%2016.49.23.png?alt=media&#x26;token=11ccf222-3bdd-4788-bb9d-6c8307048143" alt=""><figcaption></figcaption></figure>
4. At the top right of the Postman workspace, click the environment selection dropdown. (If you don't have another environment already set, this will say "No Environment".) Select your new environment "CompanyName Env" from the list.

   <figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2Fr82HCl9x91nDdUX1k9bZ%2FScreenshot%202024-04-30%20at%2017.11.10.png?alt=media&#x26;token=75b4e610-e001-494d-a6a3-e19e39ee4c33" alt=""><figcaption></figcaption></figure>

Next, we'll walk through setting the value of your variables in your new environment

#### Understanding Environment Variables <a href="#understanding-environment-variables" id="understanding-environment-variables"></a>

The provided "Demo Env" includes several pre-defined variables. THREE of these variables are **required** for basic API interaction.

* SL\_DOMAIN: This variable holds the base URL for our API. **Be sure to remove a trailing slash from your URL!**
  * e.g. `https://your-domain.sealights.co`
* SEALIGHTS\_API\_TOKEN: Found in your SeaLights UI (/settings/tokens/api-tokens).
  * Click the Gear Icon to access Settings >> From left sidebar: Integration >> API Tokens
* SEALIGHTS\_AGENT\_TOKEN: Found in your SeaLights UI (/settings/tokens/agent-tokens).
  * Click the Gear Icon to access Settings >> From left sidebar: Cockpit & Onboarding >> Agent Tokens

{% hint style="info" %}
IMPORTANT: The remaining variables in the "Demo Env" are for demonstration and documentation purposes only. These variables represent query parameters or path variables specific to individual API requests. It's generally recommended to set these directly within each request, not globally in the environment.
{% endhint %}

&#x20;

Once you have updated your new environment file with these three variables, uncheck the remaining variables in the environment file. This will guard against using “dummy” information throughout the collection. Click “Save” near the top right.

<figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2F0uQfrG2sDRKAI9hVSSQg%2FScreenshot%202024-04-30%20at%2017.23.31.png?alt=media&#x26;token=4c2096e8-a3eb-45b0-a5ae-04ddc30a4418" alt=""><figcaption></figcaption></figure>

<details>

<summary>Using Multiple Environments (Advanced Users)</summary>

#### Using Multiple Environments <a href="#using-multiple-environments" id="using-multiple-environments"></a>

Postman allows you to manage and switch between multiple environment files. This is useful for testing different API configurations or managing access for various accounts.

In the Postman sidebar, navigate to the Environments tab. Click the Manage Environments button (gear icon). Here you can create additional environment files from our boilerplate, using the same "duplicate and rename" process we used at the beginning of this guide.

Tip: Users who need to interact with multiple SeaLights instances, should consider creating a dedicated environment file with only the relevant variables for each instance. This helps maintain organization and clarity.

**Additional Considerations**

* **Security**: It's crucial to safeguard your API Key. Avoid committing it to public repositories like version control systems.
* **Updates**: We may occasionally update the Postman collection structure or environment variables. Refer to our API documentation for the latest version.

By following these steps and understanding environment variable usage, you'll be well on your way to efficiently interacting with our Public API using Postman.

</details>

### Working with the Collection <a href="#working-with-the-collection" id="working-with-the-collection"></a>

1. Click on **Collections** in the left sidebar to return to your imported collection.
2. Select your newly created environment from the dropdown at the top right of the Postman window (if not already set)

   <figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FM5LKNslUxJk12oEuTz9v%2FScreenshot%202024-05-02%20at%2016.49.26.png?alt=media&#x26;token=4710ecc7-304c-4d05-8a47-099018aba425" alt=""><figcaption><p><em>Setting your environment</em></p></figcaption></figure>

#### **Using Requests:** <a href="#using-requests" id="using-requests"></a>

* The collection's requests will now utilize the `SL_DOMAIN`, `SEALIGHTS_API_TOKEN`, and `SEALIGHTS_AGENT_TOKEN` you defined in your environment.
* Each request may have additional query parameters and/or path variables. These can be updated within the request's **Parameters** tab.

  <figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FYWEznFZxDuWrtXbzl1HF%2FScreenshot%202024-05-02%20at%2014.30.07.png?alt=media&#x26;token=2fd84c5b-6cb5-43d2-94ae-6e14f0e50473" alt=""><figcaption></figcaption></figure>
* Only query parameters that are “checked” will be sent with the request
* Path variables are always sent with the request
* NOTE: The value of variables is not shown in the URL string, but if the variable is set, it will be used when the request is sent. For this reason, in the screenshot above, the value of `:appName` has not been replaced by “DemoApp”, but the query parameter of “offset” is being sent with a value of “3”<br>

{% hint style="warning" %}
REMEMBER: Throughout the collection, variables other than the “Top 3” (such as `{{branch_name}}` or `{{bsid_var}}`) may be referenced in query parameters and path variables. These are ONLY PLACEHOLDERS. Feel free to overwrite them - they do not need to be managed at the Environment level.
{% endhint %}

#### “In-Context” Documentation <a href="#in-context-documentation" id="in-context-documentation"></a>

Using the “paper” icon found on the right toolbar will reveal additional API documentation without leaving Postman’s interface.

<figure><img src="https://4057366433-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAjqTCMRYvHhDgsdPLUnc%2Fuploads%2FWQoBdNDCfM7r1UJ2fNIZ%2FScreenshot%202024-05-02%20at%2017.38.21.png?alt=media&#x26;token=ba2d616a-8549-452e-9384-02d3d11e8742" alt=""><figcaption></figcaption></figure>

This documentation is context sensitive: what is revealed is based on the endpoint/request you have open.
