Crea token

I token API sono un ottimo modo per autenticarsi sul nostro API mantenendo separati i tuoi username e password. Ti raccomandiamo caldamente di usarli. Qui imparerai come gestire i tuoi token. Potrai creare un token sulla nostra API oppure su La nostra piattaforma.

POST

/token

Parametri del body

name
richiesto
Il nome del token
ttl The TTL in seconds (default unlimited)
allowed_ips Manage allowed ips to make request with this token (IPv4, IPv6, and cidr are compatible)

Esempi


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;
        
      

Formato della risposta


{
  "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>
        
      

Crea token per un sotto-account

POST

/token/account/:accountID

Parametri query

accountID
richiesto
L’id dell’account per il quale vuoi creare un token

Parametri del body

name
richiesto
Il nome del token
ttl The TTL in seconds (default unlimited)

Esempi


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

{
  "token":{
    "name": "Best token ever"
  }
}
          
        

POST /token/account/12542 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>
</token>
        
      

Formato della risposta


{
  "status": 1,
  "message": "OK",
  "token": "yJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMTY1NiIsImlhdCI6MTUxOTEyMDg2NX0.ZnGgbDC0OI3hPm2UXyl4rxU9JlpMTMBcTJT8RVgJbtQ",
  "token_id": "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>