Login user
curl --request POST \
--url {protocol}://{host}/wp-json/cocart/v2/login \
--header 'Content-Type: application/json' \
--data '
{
"username": "<string>",
"password": "<string>"
}
'import requests
url = "{protocol}://{host}/wp-json/cocart/v2/login"
payload = {
"username": "<string>",
"password": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({username: '<string>', password: '<string>'})
};
fetch('{protocol}://{host}/wp-json/cocart/v2/login', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "{protocol}://{host}/wp-json/cocart/v2/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'username' => '<string>',
'password' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "{protocol}://{host}/wp-json/cocart/v2/login"
payload := strings.NewReader("{\n \"username\": \"<string>\",\n \"password\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("{protocol}://{host}/wp-json/cocart/v2/login")
.header("Content-Type", "application/json")
.body("{\n \"username\": \"<string>\",\n \"password\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("{protocol}://{host}/wp-json/cocart/v2/login")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"username\": \"<string>\",\n \"password\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"user_id": "42",
"first_name": "John",
"last_name": "Doe",
"display_name": "John Doe",
"role": "Customer",
"avatar_urls": {
"24": "https://secure.gravatar.com/avatar/example?s=24&d=mm&r=g",
"48": "https://secure.gravatar.com/avatar/example?s=48&d=mm&r=g",
"96": "https://secure.gravatar.com/avatar/example?s=96&d=mm&r=g"
},
"email": "john.doe@example.com",
"extras": {},
"dev_note": "Don't forget to store the users login information in order to authenticate all other routes with CoCart."
}{
"code": "cocart_invalid_credentials",
"message": "Invalid username or password.",
"data": {
"status": 400
}
}{
"code": "cocart_authentication_failed",
"message": "Authentication failed. Please check your credentials.",
"data": {
"status": 403
}
}Login User
Logs in a user and creates a session.
POST
/
login
Login user
curl --request POST \
--url {protocol}://{host}/wp-json/cocart/v2/login \
--header 'Content-Type: application/json' \
--data '
{
"username": "<string>",
"password": "<string>"
}
'import requests
url = "{protocol}://{host}/wp-json/cocart/v2/login"
payload = {
"username": "<string>",
"password": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({username: '<string>', password: '<string>'})
};
fetch('{protocol}://{host}/wp-json/cocart/v2/login', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "{protocol}://{host}/wp-json/cocart/v2/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'username' => '<string>',
'password' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "{protocol}://{host}/wp-json/cocart/v2/login"
payload := strings.NewReader("{\n \"username\": \"<string>\",\n \"password\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("{protocol}://{host}/wp-json/cocart/v2/login")
.header("Content-Type", "application/json")
.body("{\n \"username\": \"<string>\",\n \"password\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("{protocol}://{host}/wp-json/cocart/v2/login")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"username\": \"<string>\",\n \"password\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"user_id": "42",
"first_name": "John",
"last_name": "Doe",
"display_name": "John Doe",
"role": "Customer",
"avatar_urls": {
"24": "https://secure.gravatar.com/avatar/example?s=24&d=mm&r=g",
"48": "https://secure.gravatar.com/avatar/example?s=48&d=mm&r=g",
"96": "https://secure.gravatar.com/avatar/example?s=96&d=mm&r=g"
},
"email": "john.doe@example.com",
"extras": {},
"dev_note": "Don't forget to store the users login information in order to authenticate all other routes with CoCart."
}{
"code": "cocart_invalid_credentials",
"message": "Invalid username or password.",
"data": {
"status": 400
}
}{
"code": "cocart_authentication_failed",
"message": "Authentication failed. Please check your credentials.",
"data": {
"status": 403
}
}Body
application/json
Response
User logged in successfully.
Unique ID of the user on the site.
The first name of the user (if any).
The last name of the user (if any).
The display name of the user (if any).
The role type assigned to the user.
The avatar URLs of the user for each avatar size registered.
Show child attributes
Show child attributes
The email address of the user.
Extra details added via the filter.
A message to developers.