# Portal

Currently, our 'portal' is just an API, but a UI to show your customers' queries, time to response, most popular routes, and more is coming. Checkout nlapi.io to see the latest.

> **Note:** In order to interact with the portal (aside from logging in and signing up) you will need to be properly authenticated. For more information on authentication, please refer to our [Authentication Documentation](https://the-nlapi.gitbook.io/the-nlapi-docs/authentication).

For now the portal is used strictly to create new applications (tenants) and api-keys. Once you have your api-key, you can start using the NLAPI!

## Getting Started

### 1. Login / Signup

To create a new developer account, use the `/portal/signup` post route.\
To login with an account that already exists use the `/portal/login` post route (Payload and response is the same as the signup route)\
Example Payload:

```json
{
  "name": "Dwigt Shrute", // Optional if absent, your email will be used as your name
  "email": "dwight@dundermifflin.com",
  "password": "you'vebeenmeatballed"
}
```

Example Response:

```json
{
  "message": "string",
  "access_token": "string",
  "refresh_token": "string"
}
```

Make sure to save the access token as you'll use it for authentication throughout the use of the portal.

> **Please note:** The access token is for use with the portal and is NOT the same as your nlapi-key, which you'll use to authenticate yourself with the [NLAPI routes](https://api.nlapi.io/docs#/NLAPI).

### 2. Create New Application

Now that you have a developer account, you need to create an application so you can save your schema (Or in the case you are using a Devii account you need to tell us what tenants you are using)

To create an application, make a post request to: `/portal/applications`

Example Headers:

```json
{
  "Authorization" : "Bearer [your-access-token]"
}
```

Example Payload for OpenAPI Users:

```json
{
    "name" : "My Awesome App!",
    "api_url" : "https://api.your-api-url.com",
    "api_type" : "openapi",
    "developer_id" : 1234 // Your developer Id {returned from login/signup}
}
```

Example Payload for Devii Users:

```json
{
    "name" : "My Awesome Devii App!",
    "api_url" : "https://api.your-api-url.com",  // Optional: Defaults to https://api.devii.io
    "tenant_id" : 1234, // Needs to be the same as your Devii tenantid
    "api_type" : "devii",
    "developer_id" : 1234 // Your developer Id {returned from login/signup}
}
```

Example Success (200) Response:

```json
{
  "id": 59, // Save this
  "api_url": "https://example.com/",
  "name": "string",
  "project_description": null,
  "approved": null,
  "created_at": null,
  "updated_at": null,
  "tier": 1,
  "api_type": "openapi",
  "api_keys_collection": null,
  "tenant_id": "d2c4cc25-c560-4709-ab85-89a7ce1cf57c", // generated uuid or devii tenant id
  "schemas_collection": null
}
```

### 3. Create New API-Key

Creating an api key will allow you to send requests to the `/nlapi` endpoint. You will add this key to the `nlapi-key` header in all your requests. Eventually we will add usage tracking so you can track what api key is sending the most requests.

To create a new api key, send a post request to `/portal/api-keys` where `application_id` is the id of the application for which you would like to create an api key. You will need to pass your access token via the Authorization Header. `{ 'Authorization': 'Bearer [your-access-token]'}` Payload:

```json
{
  "application_id" : id
}
```

Example 200 Response:

```json
{
  "api_key": "String"
}
```

### Next Steps

For more information on authentication, please refer to our [Authentication Documentation](https://the-nlapi.gitbook.io/the-nlapi-docs/authentication).

It's time to implement! Visit our [Documentation](https://the-nlapi.gitbook.io/the-nlapi-docs/documentation) to get started.

If you've implemented, Check out our Training Documentation to get the best performance. [Training NLAPI](https://the-nlapi.gitbook.io/the-nlapi-docs/training_nlapi)

## Additional Documentation

Addtional documentation for the portal is available at <https://api.nlapi.io/docs>.
