Skip to main content
POST
/
v1
/
m2m
/
clients
C#
// POST /v1/m2m/clients
const stytch = require('stytch');

const client = new stytch.B2BClient({
  project_id: '${projectId}',
  secret: '${secret}',
});

const params = {
  scopes: ["read:users", "write:users"],
  client_name: "My Sample Client",
  client_description: "My sample client for testing out M2M authentication.",
};

client.M2M.Clients.Create(params)
  .then(resp => { console.log(resp) })
  .catch(err => { console.log(err) });
{
  "request_id": "<string>",
  "m2m_client": {
    "client_id": "<string>",
    "client_secret": "<string>",
    "client_name": "<string>",
    "client_description": "<string>",
    "status": "<string>",
    "scopes": [
      "<string>"
    ],
    "client_secret_last_four": "<string>",
    "trusted_metadata": {},
    "next_client_secret_last_four": "<string>"
  },
  "status_code": 123
}
On initial client creation, you may pass in a custom client_id or client_secret to import an existing M2M client. If you do not pass in a custom client_id or client_secret, one will be generated automatically. The client_id must be unique among all clients in your project.
This is the only time you will be able to view the generated client_secret in the API response. Stytch stores a hash of the client_secret and cannot recover the value if lost. Be sure to persist the client_secret in a secure location. If the client_secret is lost, you will need to trigger a secret rotation flow to receive another one.

Authorizations

Authorization
string
header
required

Basic authentication header of the form Basic <encoded-value>, where <encoded-value> is the base64-encoded string username:password.

Body

application/json

Request type

scopes
string[]
required

An array of scopes assigned to the client.

client_id
string

If provided, the ID of the client to create. If not provided, Stytch will generate this value for you. The client_id must be unique within your project.

client_secret
string

If provided, the stored secret of the client to create. If not provided, Stytch will generate this value for you. If provided, the client_secret must be at least 8 characters long and pass entropy requirements.

client_name
string

A human-readable name for the client.

client_description
string

A human-readable description for the client.

trusted_metadata
object

The trusted_metadata field contains an arbitrary JSON object of application-specific data. See the Metadata reference for complete field behavior details.

Response

Successful response

request_id
string
required

Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.

m2m_client
object
required

The M2M Client created by this API call.

status_code
integer<int32>
required

The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.