2020-01-01 22:37:59 +01:00
---
2022-11-20 07:34:38 +01:00
title: apps API methods
2020-01-01 22:37:59 +01:00
description: Register client applications that can be used to obtain OAuth tokens.
menu:
docs:
weight: 10
2022-11-20 07:34:38 +01:00
name: apps
2020-01-01 22:37:59 +01:00
parent: methods
identifier: methods-apps
2022-11-20 07:34:38 +01:00
aliases: [
"/methods/apps",
"/api/methods/apps",
]
2020-01-01 22:37:59 +01:00
---
2022-11-20 07:34:38 +01:00
< style >
#TableOfContents ul ul ul {display: none}
< / style >
## Create an application {#create}
```http
2022-12-14 22:55:30 +01:00
POST /api/v1/apps HTTP/1.1
2022-11-20 07:34:38 +01:00
```
2020-01-01 22:37:59 +01:00
Create a new application to obtain OAuth2 credentials.
2022-11-20 07:34:38 +01:00
**Returns:** [Application ]({{< relref "entities/Application" >}} )\
2020-01-01 22:37:59 +01:00
**OAuth:** Public\
2020-12-27 07:03:55 +01:00
**Version history:**\
0.0.0 - added\
2.7.2 - now returns `vapid_key`
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
#### Request
##### Form data parameters
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
client_name
: {{< required > }} String. A name for your application
redirect_uris
: {{< required > }} String. Where the user should be redirected after authorization. To display the authorization code to the user instead of redirecting to a web page, use `urn:ietf:wg:oauth:2.0:oob` in this parameter.
scopes
: String. Space separated list of scopes. If none is provided, defaults to `read` . See [OAuth Scopes ]({{< relref "api/oauth-scopes" >}} ) for a list of possible scopes.
website
: String. A URL to the homepage of your app
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
#### Response
##### 200: OK
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
Store the `client_id` and `client_secret` in your cache, as these will be used to obtain OAuth tokens.
```json
2020-01-01 22:37:59 +01:00
{
"id": "563419",
"name": "test app",
"website": null,
"redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
"client_id": "TWhM-tNSuncnqN7DBJmoyeLnk6K3iJJ71KKXxgL1hPM",
"client_secret": "ZEaFUFmF0umgBX1qKJDjaU99Q31lDkOU8NutzTOoliw",
"vapid_key": "BCk-QqERU0q-CfYZjcuB6lnyyOYfJ2AifKqfeGIm7Z-HiTU5T9eTG5GxVA0_OH5mMlI4UkkDTpaZwozy0TzdZ2M="
}
```
2022-11-20 07:34:38 +01:00
##### 422: Unprocessable entity
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
If a required parameter is missing or improperly formatted, the request will fail.
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
```json
2020-01-01 22:37:59 +01:00
{
"error": "Validation failed: Redirect URI must be an absolute URI."
}
```
2022-11-20 07:34:38 +01:00
---
## Verify your app works {#verify_credentials}
```http
2022-12-14 22:55:30 +01:00
GET /api/v1/apps/verify_credentials HTTP/1.1
2022-11-20 07:34:38 +01:00
```
2020-01-01 22:37:59 +01:00
Confirm that the app's OAuth2 credentials work.
2022-11-20 07:34:38 +01:00
**Returns:** [Application ]({{< relref "entities/application" >}} ), but without `client_id` or `client_secret` \
2020-01-01 22:37:59 +01:00
**OAuth level:** App token\
2020-12-27 07:03:55 +01:00
**Version history:**\
2.0.0 - added\
2.7.2 - now returns `vapid_key`
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
#### Request
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
##### Headers
Authorization
: {{< required > }} Provide this header with `Bearer <user token>` to gain authorized access to this API method.
#### Response
##### 200: OK
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
If the Authorization header was provided with a valid token, you should see your app returned as an Application entity.
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
```json
2020-01-01 22:37:59 +01:00
{
"name": "test app",
"website": null,
"vapid_key": "BCk-QqERU0q-CfYZjcuB6lnyyOYfJ2AifKqfeGIm7Z-HiTU5T9eTG5GxVA0_OH5mMlI4UkkDTpaZwozy0TzdZ2M="
}
```
2022-11-20 07:34:38 +01:00
##### 401: Unauthorized
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
If the Authorization header contains an invalid token, is malformed, or is not present, an error will be returned indicating an authorization failure.
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
```json
2020-01-01 22:37:59 +01:00
{
"error": "The access token is invalid"
}
```
2022-11-20 07:34:38 +01:00
---
## See also
{{< caption-link url = "https://github.com/mastodon/mastodon/blob/main/app/controllers/api/v1/apps_controller.rb" caption = "app/controllers/api/v1/apps_controller.rb" > }}
2020-01-01 22:37:59 +01:00
2022-11-20 07:34:38 +01:00
{{< caption-link url = "https://github.com/mastodon/mastodon/blob/main/app/controllers/api/v1/apps/credentials_controller.rb" caption = "app/controllers/api/v1/apps/credentials_controller.rb" > }}