Zum Hauptinhalt springen

Create a new ApiToken

POST/v2/users/self/api-tokens
API-Version
v2
Request-Methode
POST
Operation-ID
user-create-api-token

Request​

Responses​

Format
application/json
Beschreibung

ApiToken was added.

  • tokenstringrequired

    The ApiToken.

Content-Type: application/json

{
"token": "00000000-0000-4000-0000-000000000000:foobar:mittwald_a"
}
{
"properties": {
"token": {
"description": "The `ApiToken`.",
"example": "00000000-0000-4000-0000-000000000000:foobar:mittwald_a",
"type": "string"
}
},
"required": [
"token"
],
"type": "object"
}

Nutzungsbeispiele​

$ curl \
--fail \
--location \
-X POST \
-d '{"description":"Api Token - read","expiresAt":"1985-10-26T01:21:00.000Z","roles":["api_read"]}' \
-H "Authorization: Bearer $MITTWALD_API_TOKEN" \
-H 'Content-Type: application/json' \
https://api.mittwald.de/v2/users/self/api-tokens
import { MittwaldAPIV2Client } from "@mittwald/api-client";
import { assertStatus } from "@mittwald/api-client-commons";

const client = MittwaldAPIClient.newWithToken(process.env.MITTWALD_API_TOKEN);
const response = await client.user.createApiToken({
"data": {
"description": "Api Token - read",
"expiresAt": "1985-10-26T01:21:00.000Z",
"roles": [
"api_read"
]
}
});

assertStatus(response, 201);

use \Mittwald\ApiClient\Generated\V2\Clients\User\CreateApiToken\CreateApiTokenRequest;
use \Mittwald\ApiClient\Generated\V2\Clients\User\CreateApiToken\CreateApiTokenRequestBody;

$client = MittwaldAPIClient::newWithToken(getenv('MITTWALD_API_TOKEN'));

// TODO: Please consult the properties and constructor signature of
// CreateApiTokenRequestBody to learn how to construct a valid instance
$body = new CreateApiTokenRequestBody(/* TODO: ... */);

$request = (new CreateApiTokenRequest(
body: $body
));
$response = $client->user()->createApiToken($request);

var_dump($response->getBody();

Auf dieser Seite