API tokens

API tokens

A person’s own login for scripts.

An SDK signs every request with your key: Authentication. To sign one yourself, see Calling the API without an SDK.

On this page
  1. The API token object
  2. tokens.list
  3. tokens.create
  4. tokens.revoke

The API token object

A person’s own login for scripts: its name and when it was used.

Attributes

  • idstring

    The token’s id: what tokens revoke takes.

  • namestring

    The name it was given.

  • createdAtnumber

    When it was made, in ms since the epoch.

  • lastSeenAtnumber

    When it last made a call, in ms since the epoch.

  • expiresAtnumber

    When it stops working, in ms since the epoch.

Answered by

tokens.list

The API token object
{
  "id": "out_3f9a1c0e7b2d",
  "name": "Acme API",
  "createdAt": 1796048940000,
  "lastSeenAt": 1796048940000,
  "expiresAt": 1796048940000
}

tokens.list

List your API tokens.

POST/v1/tokens.list

API token

Parameters

It takes no input: send an empty object.

Returns

data is a list of API token objects.

In the CLIErrors

import { Mailset } from 'mailset';

// Reads MAILSET_TOKEN from the environment.
const mailset = new Mailset();

const answer = await mailset.tokens.list();
console.log(answer);
from mailset import Mailset

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset()

answer = mailset.tokens.list()
print(answer)
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	answer, err := client.Tokens.List(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.tokens.list
p answer
<?php

require 'vendor/autoload.php';

// Reads MAILSET_TOKEN from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->tokens->list();
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.Token;
import java.util.List;

// Reads MAILSET_TOKEN from the environment.
Mailset mailset = Mailset.fromEnv();

List<Token> answer = mailset.tokens().list();
System.out.println(answer);
// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset.tokens().list().await?;
println!("{answer:?}");
curl https://mailset.app/v1/tokens.list \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{}}'

curl can’t sign a request. $TOKEN is your credential’s token, and $MS_TIME and $MS_PROOF sign this exact body: Calling the API without an SDK shows how.

mailset tokens list
Response
{
  "ok": true,
  "data": [
    {
      "id": "out_3f9a1c0e7b2d",
      "name": "Acme API",
      "createdAt": 1796048940000,
      "lastSeenAt": 1796048940000,
      "expiresAt": 1796048940000
    }
  ]
}

tokens.create

Create an API token. It is shown once.

POST/v1/tokens.create

API tokenPasskey

Parameters

  • namestringrequired

    A name to tell it by, up to 64 characters.

    At most 64 characters.

Beside input

  • approvalstringoptional

    An approval’s id, once someone approved it with their passkey. Without one, the answer is step_up_required and names what to approve.

Returns

data is an object with:

  • idstring

    The token’s id: what tokens revoke takes.

  • namestring

    The name it was given.

  • tokenstring

    The token itself, shown this once. It starts with mst_.

  • expiresAtnumber

    When it stops working, in ms since the epoch: a year from now.

In the CLIErrors

import { Mailset } from 'mailset';

// Reads MAILSET_TOKEN from the environment.
const mailset = new Mailset();

const answer = await mailset.tokens.create({
	name: "Deploy script",
});
console.log(answer);
from mailset import Mailset

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset()

answer = mailset.tokens.create({"name": "Deploy script"})
print(answer)
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	params := &mailset.TokensCreateParams{
		Name: "Deploy script",
	}
	answer, err := client.Tokens.Create(ctx, params)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.tokens.create(name: 'Deploy script')
p answer
<?php

require 'vendor/autoload.php';

// Reads MAILSET_TOKEN from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->tokens->create([
    'name' => 'Deploy script',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.TokensCreateParams;
import app.mailset.model.TokensCreateResult;

// Reads MAILSET_TOKEN from the environment.
Mailset mailset = Mailset.fromEnv();

var params = TokensCreateParams.builder()
        .name("Deploy script")
        .build();
TokensCreateResult answer =
        mailset.tokens().create(params);
System.out.println(answer);
use mailset::types::TokensCreateParams;

// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset
    .tokens()
    .create(TokensCreateParams {
        name: "Deploy script".into(),
    })
    .await?;
println!("{answer:?}");
curl https://mailset.app/v1/tokens.create \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"name":"Deploy script"}}'

curl can’t sign a request. $TOKEN is your credential’s token, and $MS_TIME and $MS_PROOF sign this exact body: Calling the API without an SDK shows how.

mailset tokens create "Deploy script"
Response
{
  "ok": true,
  "data": {
    "id": "out_3f9a1c0e7b2d",
    "name": "Acme API",
    "token": "text",
    "expiresAt": 1796048940000
  }
}

tokens.revoke

Revoke an API token.

POST/v1/tokens.revoke

API token

Parameters

  • idstringrequired

    The token’s id, from tokens list.

Returns

data is an object with:

  • revokedboolean

    True when the token was there to revoke.

In the CLIErrors

import { Mailset } from 'mailset';

// Reads MAILSET_TOKEN from the environment.
const mailset = new Mailset();

const answer = await mailset.tokens.revoke({
	id: "d_4b8e2a6c9f1d3057b3e8a2c6",
});
console.log(answer);
from mailset import Mailset

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset()

answer = mailset.tokens.revoke(
    {"id": "d_4b8e2a6c9f1d3057b3e8a2c6"}
)
print(answer)
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	params := &mailset.TokensRevokeParams{
		ID: "d_4b8e2a6c9f1d3057b3e8a2c6",
	}
	answer, err := client.Tokens.Revoke(ctx, params)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.tokens.revoke(
  id: 'd_4b8e2a6c9f1d3057b3e8a2c6'
)
p answer
<?php

require 'vendor/autoload.php';

// Reads MAILSET_TOKEN from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->tokens->revoke([
    'id' => 'd_4b8e2a6c9f1d3057b3e8a2c6',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.TokensRevokeParams;
import app.mailset.model.TokensRevokeResult;

// Reads MAILSET_TOKEN from the environment.
Mailset mailset = Mailset.fromEnv();

var params = TokensRevokeParams.builder()
        .id("d_4b8e2a6c9f1d3057b3e8a2c6")
        .build();
TokensRevokeResult answer =
        mailset.tokens().revoke(params);
System.out.println(answer);
use mailset::types::TokensRevokeParams;

// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset
    .tokens()
    .revoke(TokensRevokeParams {
        id: "d_4b8e2a6c9f1d3057b3e8a2c6".into(),
    })
    .await?;
println!("{answer:?}");
curl https://mailset.app/v1/tokens.revoke \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"id":"d_4b8e2a6c9f1d3057b3e8a2c6"}}'

curl can’t sign a request. $TOKEN is your credential’s token, and $MS_TIME and $MS_PROOF sign this exact body: Calling the API without an SDK shows how.

mailset tokens revoke d_4b8e2a6c9f1d3057b3e8a2c6
Response
{
  "ok": true,
  "data": {
    "revoked": true
  }
}