# Bruno API Client

MailSlurp API's work well with Bruno API client. You can use MailSlurp email and SMS APIs in Bruno REST client by calling the API endpoints directly at `https://api.mailslurp.com`.

- [REST API Documentation](/docs/api/)
- [Github Bruno Collections](https://github.com/mailslurp/examples/tree/master/bruno-api-client)

## Authorization
Pass the `x-api-key` request header set to the value of your [MailSlurp API Key](https://app.mailslurp.com) with each request.

## Tutorial

## Parse responses and set variables
When you call an API endpoint, you can parse the response and set variables for use in subsequent requests.

```text
script:post-response {
  const data = res.getBody();
  bru.setVar('emailAddress', data.emailAddress);
  bru.setVar('inboxId', data.id);
}
```

## Running collection
You can store your collection in a file and run it using the Bruno CLI.

For instance this collection creates an inbox and sets the `emailAddress` and `inboxId` variables for use in subsequent requests.

```text
meta {
  name: Create an inbox
  type: http
  seq: 2
}

post {
  url: https://api.mailslurp.com/inboxes/withDefaults
  body: none
  auth: apikey
}

auth:apikey {
  key: x-api-key
  value: {{apiKey}}
  placement: header
}

script:post-response {
  const data = res.getBody();
  bru.setVar('emailAddress', data.emailAddress);
  bru.setVar('inboxId', data.id);
}
```

We can run it with

```shell
cd my-collection
npx @usebruno/cli run
```
