# Accounts API

Jump to:

* [DELETE /users/me/client-keys/{id}](#delete-users-me-client-keys-id)
* [GET /users/me](#get-users-me)
* [GET /users/me/client-keys](#get-users-me-client-keys)
* [GET /users/me/events](#get-users-me-events)
* [POST /auth](#post-auth)
* [POST /auth/token](#post-auth-token)
* [POST /users/me/client-keys](#post-users-me-client-keys)
* [PUT /users/{userId}/token/{token}](#put-users-userid-token-token)
* [PUT /users/me/password](#put-users-me-password)

## PUT /users/{userId}/token/{token}

This resource verifies a new created user by User Id and verification token.

### Parameters

| Name   | In   | Type   | Required | Description                       |
| ------ | ---- | ------ | -------- | --------------------------------- |
| userId | path | string | true     | none                              |
| token  | path | string | true     | verification token sent via email |

### Responses

| Status | Meaning                                                 | Description          |
| ------ | ------------------------------------------------------- | -------------------- |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | Successful operation |

### Code sample

```shell
curl -X PUT https://accounts.bloq.cloud/users/user-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/token/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
```

## GET /users/me

This resource fetches the user profile information.

### Responses

| Status | Meaning                                                 | Description          | Schema |
| ------ | ------------------------------------------------------- | -------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | Successful operation | Inline |

### Example responses

> 200 Response

```json
{
  "displayName": "Example User",
  "entityType": "individual",
  "verifiedAt": "2020-04-24T20:01:55.634Z",
  "updatedAt": "2020-04-24T20:01:55.634Z",
  "billingAddress": {
    "country": "US",
    "zipCode": "12345",
    "address": "123 Abc Street",
    "state": "CA"
  },
  "createdAt": "2020-04-24T19:57:48.878Z",
  "email": "email@example.com",
  "id": "user-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
```

### Code sample

```shell
curl -X GET https://accounts.bloq.cloud/users/me \
  -H 'Authorization: Bearer <AUTH_TOKEN>'
```

## PUT /users/me/password

This resource updates a user password.

> Body parameter

```json
{
  "oldPassword": "Old Password...",
  "newPassword": "New Password..."
}
```

### Parameters

| Name          | Type   | In   | Required | Description |
| ------------- | ------ | ---- | -------- | ----------- |
| body          | object | body | true     | none        |
| » oldPassword | string | body | true     | none        |
| » newPassword | string | body | true     | none        |

### Responses

| Status | Meaning                                                 | Description          | Schema |
| ------ | ------------------------------------------------------- | -------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | Successful operation | Inline |

### Code sample

```shell
curl -X PUT https://accounts.bloq.cloud/users/me/password \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <AUTH_TOKEN>' \
  -d '{
 "oldPassword": "Old Password...",
 "newPassword": "New Password..."
}'
```

## POST /auth

Using HTTP Basic Authentication to provide username (ID or email) and password, this resource retrieves an `Account Access Token` to be passed to other Accounts API functions, for their authentication. The token expires after 12 hours and a new token may be generated at any time.

### Responses

| Status | Meaning                                                 | Description          | Schema |
| ------ | ------------------------------------------------------- | -------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | Successful operation | Inline |

### Example responses

> 200 Response

```json
{
  "accessToken": "xxxxxx.xxxxxxxxxx.xxxxxx"
}
```

### Code sample

```shell
# Using user email
curl -u email@example.com:password -X POST https://accounts.bloq.cloud/auth
```

```shell
# Using user ID
curl -u user-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:password -X POST https://accounts.bloq.cloud/auth
```

## POST /auth/token

This endpoint provides a `Client Access Token` and a `Client Refresh Token`, these tokens are used to interact with cloud services like Nodes.

The Client Access Token expires after one hour and the Client Refresh Token expires after one year. The refresh access token is used to create new client access tokens.

> Body parameter to create an Access and Refresh token using `clientCredentials` as grant type

```json
{
  "grantType": "clientCredentials",
  "clientId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "clientSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
```

> Body parameter to create an access token using refreshToken as grant type

```json
{
  "grantType": "refreshToken",
  "refreshToken": "xxxxxx.xxxxxxxxxx.xxxxxx"
}
```

### Responses

| Status | Meaning                                                 | Description          | Schema |
| ------ | ------------------------------------------------------- | -------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | Successful operation | Inline |

### Example Responses

> 200 Response

```json
{
  "accessToken": "xxxxxx.xxxxxxxxxx.xxxxxx",
  "refreshToken": "xxxxxx.xxxxxxxxxx.xxxxxx"
}
```

### Code sample

```shell
# Using Client Credentials Grant Type
curl -X POST https://accounts.bloq.cloud/auth/token \
  -H 'Content-Type: application/json' \
  -d '{
 "grantType": "clientCredentials",
 "clientId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
 "clientSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}'
```

```shell
# Using Refresh Token Grant Type
curl -X POST https://accounts.bloq.cloud/auth/token \
  -H 'Content-Type: application/json' \
  -d '{
 "grantType": "refreshToken",
 "refreshToken": "xxxxxx.xxxxxxxxxx.xxxxxx"
}'
```

## POST /users/me/client-keys

This resource creates a new client key pair. The key pair is used to generate a `Client Access Token`, these access token are used to interact with cloud services like Nodes API. To access this endpoint an `Account Access Token` must be provided as Bearer token in the authorization header.

### Responses

| Status | Meaning                                                 | Description          | Schema |
| ------ | ------------------------------------------------------- | -------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | Successful operation | Inline |

### Example responses

> 200 Response

```json
{
  "clientId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "clientSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "createdAt": "2020-04-24T20:35:22.808Z"
}
```

### Code sample

```shell
curl -X POST https://accounts.bloq.cloud/users/me/client-keys \
  -H 'Authorization: Bearer <AUTH_TOKEN>'
```

## GET /users/me/client-keys

This resource fetches Client Keys

### Responses

| Status | Meaning                                                 | Description          | Schema |
| ------ | ------------------------------------------------------- | -------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | Successful operation | Inline |

### Example responses

> 200 Response

```json
[
  {
    "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "createdAt": "2019-03-11T13:58:53.151Z"
  },
  {
    "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "createdAt": "2019-03-08T19:28:00.538Z"
  }
]
```

### Code sample

```shell
curl -X GET https://accounts.bloq.cloud/users/me/client-keys \
  -H 'Authorization: Bearer <AUTH_TOKEN>'
```

## DELETE /users/me/client-keys/{id}

This resource removes a Client Key by ID

### Parameters

| Name | In   | Type   | Required | Description |
| ---- | ---- | ------ | -------- | ----------- |
| id   | path | string | true     | Key ID      |

### Responses

| Status | Meaning                                                         | Description          | Schema |
| ------ | --------------------------------------------------------------- | -------------------- | ------ |
| 204    | [No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5) | Successful operation | Inline |

### Code sample

```shell
curl -X DELETE https://accounts.bloq.cloud/users/me/client-keys/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
  -H 'Authorization: Bearer <AUTH_TOKEN>'
```

## GET /users/me/events

This resource fetches the user events

### Responses

| Status | Meaning                                                 | Description          | Schema |
| ------ | ------------------------------------------------------- | -------------------- | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | Successful operation | Inline |

### Example Responses

> 200 Response

```json
[
  {
    "service": "cloud-accounts",
    "output": {
      "startTime": "2020-04-24T19:57:48.988Z",
      "endTime": "2020-04-24T19:57:49.065Z",
      "httpStatusCode": 200,
      "bytesOut": 385
    },
    "serviceData": {},
    "user": "user-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "input": {},
    "createdAt": "2020-04-24T19:57:49.093Z",
    "id": "event-bfe91423-8b6b-44d1-a264-483aab8a7f0d"
  },
  {
    "service": "cloud-accounts",
    "output": {
      "startTime": "2020-04-24T20:00:34.581Z",
      "endTime": "2020-04-24T20:00:35.057Z",
      "httpStatusCode": 401,
      "bytesOut": 0
    }
  }
]
```

### Code sample

```shell
curl -X GET https://accounts.bloq.cloud/users/me/events \
  -H 'Authorization: Bearer <AUTH_TOKEN>'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bloq.com/advanced-documentation/technical-reference/accounts-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
