Create API key for 2FA

This method allows you to generate an API key for your account.

In order to use the 2FA client side methods, you need to be authorized over API key.

API key documentation

Learn more about API key and advanced API key options here.

Create a new API key for client side methods with the permissions group TFA. This will limit usage of this API key to a required set of methods for sending and verifying PIN.

Create new API key request example:

POST https://api.infobip.com/settings/1/accounts/_/api-keys
POST settings/1/accounts/_/api-keys HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json
Accept: application/json

{
    "name": "My two factor authorization API key",
    "permissions": [
      "TFA"
    ]
}
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.infobip.com/2fa/1/api-key",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Response:

{
    "name": "My two factor authorization API key",
    "key": "C6DFA0B215B2CF24EF04794F718A3FC8",
    "publicApiKey": "7bd7d59cfe90e4d32b1d2f20d39c86df-fbaa8670-1008-ac7a-398a-3c11ac797c77",
    "accountKey": "EF04794F718A3FC8C6DFA0B215B2CF24",
    "permissions": [
      "TFA"
    ],
    "enabled": true
}	
  

If successful, the response header HTTP status code will be 200 OK.

Use the created publicApiKey for authorization in the request header like in the following example:

Authorization: App 003026bbc133714df1834b8628bb496e-8f4b3d9a-e921-478d-a994-28a725159ab9