Create a token

API Tokens are a great way to authenticate to our API while being separate from your username and password. We strongly recommend you to use them. You'll find here how to manage your API tokens. You can create a token with our API or on our platform.

POST

/token

Body Parameters

name
required
The token name
ttl The TTL in seconds. Default no expiration
allowed_ips Manage allowed ips to make request with this token (IPv4, IPv6, and cidr are compatible)

Examples


POST /token HTTP/1.1
Host: api.smsfactor.com
Authorization: Bearer your.token
Accept: application/json

{
  "token":{
    "name": "Best token ever",
    "ttl": 2678400,
    "allowed_ips": [
        "2a01:cb1d:2b9:ef02:2521:4ed1:109a:8fae",
        "192.168.2.0/24",
        "192.168.2.2"
    ]
  }
}
          
        

POST /token HTTP/1.1
Host: api.smsfactor.com
Authorization: Bearer your.token
Accept: application/xml

<?xml version="1.0" encoding="UTF-8" ?>
<token>
  <name>Best token ever</name>
  <ttl>2678400</ttl>
</token>
        
      

$response = \SMSFactor\Token::create([
    'token' => [
      'name' => 'Best token ever',
      "ttl" => 2678400,
      "allowed_ips": [
        "2a01:cb1d:2b9:ef02:2521:4ed1:109a:8fae",
        "192.168.2.0/24",
        "192.168.2.2"
        ]
    ]
]);
$token = $response->token;
$token_id = $response->token_id;
        
      

Result Format


{
  "status": 1,
  "message": "OK",
  "token": "yJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMTY1NiIsImlhdCI6MTUxOTEyMDg2NX0.ZnGgbDC0OI3hPm2UXyl4rxU9JlpMTMBcTJT8RVgJbtQ",
  "token_id": "2",
  "allowed_ips": [
    "2a01:cb1d:2b9:ef02:2521:4ed1:109a:8fae",
    "192.168.2.0/24",
    "192.168.2.2"
    ]
}
          
        

<?xml version="1.0" encoding="UTF-8"?>
<response>
    <status>1</status>
    <message>OK</message>
    <token>yJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMTY1NiIsImlhdCI6MTUxOTEyMDg2NX0.ZnGgbDC0OI3hPm2UXyl4rxU9JlpMTMBcTJT8RVgJbtQ</token>
    <token_id>2</token_id>
</response>