# Initial Configuration

### Prerequisites

* [Install Spyctl](https://docs.spyderbat.com/installation/spyctl)
* [Generate a key to access the Spyderbat API](https://docs.spyderbat.com/tutorials/integrations/how-to-set-up-your-spyderbat-api-key-and-use-the-spyderbat-api)

### Initial Configuration

In this section you will learn how to configure Spyctl to enable data retrieval from across your entire organization. To do so, you must first create an APISecret and then use that APISecret to set a Context. An APISecret encapsulates your Spyderbat API credentials; the Context specifies where Spyctl should look for data when interacting with the Spyderbat API (e.g., organization, cluster, machine, service, or container image).

#### Create an APISecret

An APISecret encapsulates your Spyderbat API credentials. You must create at least one APISecret in order for Spyctl to access your data via theSpyderbat API.

To create an APISecret, use an [API key generated from the Spyderbat Console](https://docs.spyderbat.com/tutorials/integrations/how-to-set-up-your-spyderbat-api-key-and-use-the-spyderbat-api).

| Region             | API URL                              |
| ------------------ | ------------------------------------ |
| United States      | <https://api.spyderbat.com>          |
| Mumbai, India      | <https://api.mum.prod.spyderbat.com> |
| Frankfurt, Germany | <https://api.deu.prod.spyderbat.com> |

{% hint style="info" %}
For most users, the API URL will be the one in the United States. If you are unsure which one applies to you, contact <support@spyderbat.com>.
{% endhint %}

Copy a generated API key and region-specific API URL into the following command:

```
spyctl config set-apisecret -k <apikey> -u <apiurl> NAME
```

For example:

```
$ spyctl config set-apisecret -k ZXlKaGJHY2lPaUpJVXpJMU5pSXNJbXRwWkNJNkluTm\
lJaXdpZEhsd0lqb2lTbGRVSW4wLmV5SmxlSEFpT2pFM01EUTVPVGM1TWpBc0ltbGhkQ0k2TVRZM\
016UTJNVGt4T1N3aWFYTnpJam9pYTJGdVoyRnliMjlpWVhRdWJtVjBJaXdpYzNWaUlqb2ljSGhX\
YjBwMlVFeElXakJIY1VJd2RXMTNTMEVpZlEuZGpxWkRCOTNuUnB4RUF0UU4yQ0ZrOU5zblQ5Z2Q\
tN0tYT081TEZBZC1GSQ== -u "https://api.spyderbat.com" my_secret

Set new apisecret 'my_secret' in '/home/demouser/.spyctl/.secrets/secrets'
```

{% hint style="info" %}
Spyctl saves APISecrets in *$HOME/.spyctl/.secrets/secrets*
{% endhint %}

#### Set a Context

Contexts will let Spyctl know where to look for data. The broadest possible Context is organization-wide. This means that when you run Spyctl commands, the Spyderbat API will return results relevant to your entire organization.

{% hint style="info" %}
For the `--org` field in the following command you may supply the name of your organization which can be found in the top right of the Spyderbat Console or the organization UID which can be found in your web browser's url when logged into the [Spyderbat Console](https://app.spyderbat.com): `https://app.spyderbat.com/app/org/UID/dashboard`.
{% endhint %}

```
spyctl config set-context --org <ORG NAME or UID> --secret <SECRET NAME> NAME
```

For example:

```
$ spyctl config set-context --org "John's Org" --secret my_secret my_context
Set new context 'my_context' in configuration file '/home/demouser/.spyctl/config'.
```

You can view your configuration by issuing the following command:

```
spyctl config view
```

You should see something like this:

```
apiVersion: spyderbat/v1
kind: Config
contexts:
- name: my_context
  secret: my_secret
  context:
    organization: John's Org
current-context: my_context
```

{% hint style="info" %}
The global configuration file is located at *$HOME/.spyctl/config*
{% endhint %}

{% hint style="info" %}
It is possible to create more specific contexts, such as a group of machines or a specific container image. You can think of the fields in your context as filters to limit your scope. Follow this link to learn more about contexts: Contexts
{% endhint %}

At this point you should now be able to run spyctl commands that utilize the Spyderbat API.
