# Building your first connector

> This section explains how to create a connector using Connector Builder and use it within an automation. The example covers
creating a connector through a manual process, so we automatically address points that can otherwise typically be skipped.

This section explains how to create a connector using Connector Builder and use it within an automation. The example covers
creating a connector through a manual process, so we automatically address points that can otherwise typically be skipped.

The workflow we are designing is meant to receive daily Slack messages of stock prices that are of interest. [Polygon.io](http://polygon.io/) provides a set of free APIs that retrieve stock information and can be used for our purpose. They have a quick sign up process
that, in return, provides us with an API key to make the API calls that we need to make.

:::note
You can also check out the [Building your connector from an API definition](https://docs.uipath.com/integration-service/automation-cloud/latest/user-guide/from-an-api-definition#building-your-connector-from-an-api-definition) section. This explains how to import a Swagger definition and let Connector Builder complete most of the work for you.
:::

## Sign up with Polygon.io

Most vendor applications require authentication details in the form of username and
password, OAuth App, API key, etc. Polygon.io is no different. It provides a free sign
up to try out some of their APIs.

1. Go to [polygon.io](https://polygon.io/) and create an account.
2. Open your Dashboard and select API Keys to view your key.

![docs image](https://dev-assets.cms.uipath.com/assets/images/integration-service/integration-service-docs-image-390128-0ce2e749.webp)

## Create a connector in Connector Builder

Navigate to **Integration Service** and select **Build your connector**.

Let's start with **A blank connector**. If you have any form of API definition at hand (Swagger, YAML, etc.), you can select **Start from API definition** and let Connector Builder do most of the configuration work for you.

1. Download the `polygon.svg` icon from the web to add their logo to your catalog.

   Note:
   All image types are supported, but we recommend using a square SVG.
2. Add a name and description for your custom connector, then select **Create**.

![docs image](https://dev-assets.cms.uipath.com/assets/images/integration-service/integration-service-docs-image-390133-4c9a6353.webp)

## Set up the authentication and connect

The Polygon [Getting started documentation](https://polygon.io/docs/stocks/getting-started) references that any API call to their platform requires you to send your API key in the headers or as a query parameter.
To do this, you need to add it into the headers, as explained in the following example:

1. Pass your API key in the query string as follows, where `<your_token>` is the API key:

   ```
   https://api.polygon.io/v2/aggs/ticker/AAPL/range/1/day/2023-01-09/2023-01-09?apiKey=<your_token>
   ```
2. Alternatively, you can add an **Authorization header** to the request with your API Key as the token, in the following form, where `<your_token>` is the API key:

   ```
   Authorization: Bearer <your_token>
   ```
3. In Connector Builder, navigate to **Settings** and select the **Base API** tab. Set the **Base URL** to `https://api.polygon.io`.

   :::note
   In this example, we do not add the `version "v2"` section to the Base URL. This allows us to run some of the older stock API calls.
   :::

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/integration-service/integration-service-docs-image-390137-4e284e16.webp)
4. Next, go to the **Authentication** tab to select your preferred **Authentication type** from the drop-down list. For this example, let's select **Personal Access Token (PAT)**.
   Note:
   The Polygon documentation refers to an **API key**, but given that it has to be sent as **Authorization: Bearer \<your\\_token\>**, it is actually closer to an OAuth style token. Therefore, Personal Access Token (PAT) is technically the better definition.
   Read more about the different [Authentication types](https://docs.uipath.com/integration-service/automation-cloud/latest/user-guide/authentication-configuration#authentication-types).
5. Copy your API key from Polygon and set the **Value** as: `Bearer <your_key>`.
6. Set the **Ask the user** field to **No**, so that users are not asked for their key when creating a connection to this connector. This is because we are not going
   to share this connector beyond our tenant. If, however, you want to share the connector beyond the tenant, don’t add your
   own key. Set **Ask the user** to **Yes**, so that other users are prompted to subscribe to the Polygon service themselves.
   The preconfigured authentication types in Connector Builder take care of most of the work for you. For example,  **Personal Access Token** automatically sends **Authorization: Bearer \<your\\_token\>** as an auth header, rather than you having to build this configuration yourself.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/integration-service/integration-service-docs-image-336962-dc3a5da9.webp)
7. Set up a connection with the aforementioned configuration by selecting the **Not connected \> Add connection** button. Notice how this already works as any other Integration Service connector. Select **Connect** so that you have a test connection to make API calls to.

## Test your API calls

After establishing a connection to the third-party software, we move on to performing the actual API calls.

1. Navigate to the left-side panel to **API \> Create new resource group**. The goal is to get a daily Slack notification on the opening price of a given stock. The endpoint we are going to implement
   now is Polygon's [Daily open/close API](https://polygon.io/docs/stocks/get_v1_open-close__stocksticker___date).

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/integration-service/integration-service-docs-image-336978-11db0175.webp)
2. In the **Create new resource group** window, copy the endpoint information from the Polygon docs.
3. Set the **Path** to `/open-close/{stocksTicker}/{date}`.
4. From the **Select methods** list, enable **Get record (GETBYID)**, since we select a single object, rather than an array of objects.
5. Provide a display name, such as **Open - Close for stock**. Connector Builder will automatically convert the `{x}` variables to path variables.
6. Select **Create** to add this resource.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/integration-service/integration-service-docs-image-336986-156efecb.webp)

     
     

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/integration-service/integration-service-docs-image-390147-67870f80.webp)
7. To test if the setup is working, select the **Send request** button next to your resource. This creates values for the two path parameters. We can take them from the usage example in
   the Polygon docs.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/integration-service/integration-service-docs-image-336982-aad49394.webp)

## Publish the connector to the catalog

You can take a few extra steps to make resources and parameters look and behave better. For example, identify that the **Date** parameter is of type `DateTime` and provide the mask as example. Providing **Display names** makes your connector show up better within the Studio activity. The following image shows how to set up these fields:

![docs image](https://dev-assets.cms.uipath.com/assets/images/integration-service/integration-service-docs-image-390152-fdab6e34.webp)

Before publishing, use the [Connector Builder checklist](connector-builder-checklist.md) to verify that all required steps — Base URL, authentication, and at least one resource — are complete.

As the final step, select **Publish** to publish your connector to your tenant. The connector appears in the list of connectors featured on your tenant, and anyone
that is using the same tenant can use the Polygon connector.

For more information, refer to the detailed [Publishing your connector](https://docs.uipath.com/integration-service/automation-cloud/latest/user-guide/connector-builder-publishing) section.

![docs image](https://dev-assets.cms.uipath.com/assets/images/integration-service/integration-service-docs-image-390319-b3699e7f.webp)

## Use the connector in UiPath Studio

Building a custom connector in Integration Service is only relevant if you can actually
use it in a workflow.

To test your custom connector in a workflow:

1. Open UiPath Studio and create a
   new project. For example, **Slack daily stock prices**. Since we want to
   receive daily messages, the first activity used in this workflow is a **Time
   Trigger**.
2. Next, when you drag a Polygon
   activity to the canvas, you are prompted to connect to Polygon.io with your
   account.
3. Once a connection is established,
   configure the Polygon activity to retrieve information on Apple stocks (AAPL).
   You can hard code the stock you are interested in, but you must format the date
   to be the runtime date.
4. Next, add a Slack [Send Message to Channel](https://docs.uipath.com/activities/other/latest/integration-service/uipath-salesforce-slack-send-message) activity to
   send this info to a channel. If you want to send the information to yourself,
   use [Send Message to User](https://docs.uipath.com/activities/other/latest/integration-service/uipath-salesforce-slack-send-message-to-user).

:::note
Polygon’s API only takes in one stock at a time but you can
configure Studio to do multiple calls through the connector and also notify on
UiPath’s daily stock opening price (PATH).
:::
