# Testing Hiro RPCs via API Client

**URL:** https://heroiclabs.com/docs/hiro/guides/server-framework/api-calls/
**Keywords:** testing hiro rpcs via api client, api calls
**Categories:** hiro, api-calls, server-framework

---


# Testing Hiro RPCs via API Client

{{< note "important" >}}
This guide was written using the Bruno API Client, but any other API Client can be used as long as it supports importing collections with OpenAPI format.
{{< /note >}}

When testing your Hiro RPC functions, using an API Client can be a good alternative to using the game client, enabling a faster and more efficient way to test your functions.

You can find the collection of RPCs that have been registered by Hiro from your **Nakama Console** in the **Runtime Modules** -> **Registered RPC Functions** page. These RPCs are open to be called via the API Client.

## Prerequisites

* Install [Bruno](https://www.usebruno.com/downloads)
* Install [Nakama](/docs/nakama/getting-started/install/docker/) and [Hiro](/docs/hiro/concepts/getting-started/install/) and have them running
* Download Hiro's [OpenAPI Collection](https://github.com/heroiclabs/hiro/blob/main/hiro-openapi.yml)

## Importing the OpenAPI Collection

Import the OpenAPI Collection in Bruno by following these steps:

1. Navigate to **Import Collection** -> **OpenAPI V3 Spec**
2. Select the **hiroOpenAPI.yml** file
3. Choose a location to save the collection
4. Click **Import**

## Setting Authentication

All the requests need to have a `Bearer Token`, otherwise the server will return an error saying `"Auth token or HTTP key required"`.

{{< note "important" >}}
Every time the token expires, all the steps in this subsection need to be redone.
{{< /note >}}

### Creating a Bearer Token

We can create a new user via the Command Line to receive a `Bearer Token`:

```bash
curl --location 'http://127.0.0.1:7350/v2/account/authenticate/custom?create=true&username=<username>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic ZGVmYXVsdGtleTo=' \
--data '{"id":"uniqueidentifier"}'
```

The response should look like this:

```bash
{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aWQiOiI2OTE3MTI0MS1jZmY1LTQ2ZjAtOTU1MC04MmQ5Yzc3YjFkNmQiLCJ1aWQiOiJmYjVjNTRiNy0xMmU5LTQyM2YtOWE0OC04YTBlMjNmNTM3YmMiLCJ1c24iOiJQbGF5ZXI1NzgwMTQwNyIsImV4cCI6MTcyMTI5NDczOX0.lSOoEB0vmESYWsfKhnOrn8EapOK7OdCT-ZM2otqvYwA","refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0aWQiOiI2OTE3MTI0MS1jZmY1LTQ2ZjAtOTU1MC04MmQ5Yzc3YjFkNmQiLCJ1aWQiOiJmYjVjNTRiNy0xMmU5LTQyM2YtOWE0OC04YTBlMjNmNTM3YmMiLCJ1c24iOiJQbGF5ZXI1NzgwMTQwNyIsImV4cCI6MTcyMTgxMzEzOX0.1o9q9O4eXMU0eL0DahAQ_3Q1q_lRsJfSrw-1icoT_Xk"}
```

The first argument (`token`) is the `Bearer Token` that we want. We do not need the `refresh_token` for purposes of this guide.

### Setting the Bearer Token

Now in Bruno, set the `Bearer Token` as a global setting: 

1. Click the **...** menu on the **Hiro RPC API Collection**
2. Select **Settings** -> **Auth**
3. Click **No Auth** and select **Bearer Token** -> **Set the token field**

When making a request, set the Auth mode to `Inherit` by going to the **Auth** tab, clicking **No Auth** and selecting **Inherit**. 

![Bruno after making a Post request on a Hiro RPC Function]({{< fingerprint_image "/images/pages/hiro/guides/api-calls/bruno-set-auth-inherit.png" >}})

## Testing an RPC Call

To make an RPC call, select the `POST` request related to the RPC call that you want to test. In this case we will test `RPC_ID_ECONOMY_STORE_GET`.

Next set the body of the request by going to the `Body` tab and setting the `storeType` field. In this case we set it to `ECONOMY_STORE_TYPE_GOOGLE_PLAY`.

After making the request, Bruno should look like this:

![Bruno after making a Post request on a Hiro RPC Function]({{< fingerprint_image "/images/pages/hiro/guides/api-calls/bruno-after-request.png" >}})