Sorry, no results found for "".

Show examples in:
Javascript HTTP
Endpoint info
Available examples

Content Management API > Session

Create a new session

Body parameters

type string Required

Must be exactly "email_credentials".

attributes.email string Required

Email

Example: "foo@bar.com"
attributes.password string Required

Password

Example: "changeme"
attributes.otp_code string Optional

Two-factor authentication one-time password

Example: "123512"

Returns

Returns a resource object of type session.

Examples

POST https://site-api.datocms.com/sessions HTTP/1.1
Authorization: Bearer YOUR-API-TOKEN
Accept: application/json
X-Api-Version: 3
Content-Type: application/vnd.api+json
{
"data": {
"type": "email_credentials",
"attributes": {
"email": "foo@bar.com",
"password": "changeme"
}
}
}
Terminal window
curl -g 'https://site-api.datocms.com/sessions' \
-X POST \
-H "Authorization: Bearer YOUR-API-TOKEN" \
-H "Accept: application/json" \
-H "X-Api-Version: 3" \
-H "Content-Type: application/vnd.api+json" \
--data-binary '{"data":{"type":"email_credentials","attributes":{"email":"foo@bar.com","password":"changeme"}}}'
await fetch("https://site-api.datocms.com/sessions", {
method: "POST",
headers: {
Authorization: "Bearer YOUR-API-TOKEN",
Accept: "application/json",
"X-Api-Version": "3",
"Content-Type": "application/vnd.api+json",
},
body: JSON.stringify({
data: {
type: "email_credentials",
attributes: { email: "foo@bar.com", password: "changeme" },
},
}),
});
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: cache-control: max-age=0, private, must-revalidate
X-RateLimit-Limit: 30
X-RateLimit-Remaining: 28
{
"data": {
"type": "session",
"id": "eyJCJhbGci.eyJhaWwuY29tIn0.32wQOMci",
"relationships": {
"user": {
"data": {
"type": "user",
"id": "312"
}
}
}
},
"included": [
{
"type": "user",
"id": "312",
"relationships": {
"role": {
"data": {
"type": "role",
"id": "34"
}
}
},
"attributes": {
"email": "mark.smith@example.com",
"is_2fa_active": true,
"full_name": "Mark Smith",
"is_active": true
}
}
]
}