API Authentication
|
API authentication tutorial and examples with source code
Learn how to use API authentication in your software in a tutorial with examples with source code
|
API authentication is required to use the services provided by any Application Program Interface to interconnect systems.
|
Learn how to authenticate with API.
|
API in Headers
API Key in headers
You can also pass the API key in the headers of your request.
This is a more secure way to authenticate your requests.
The API key must be included in the X-API-Key header of the request.
Headers:
X-API-Key (string): Your API key for authentication.
This header is required for accessing the endpoint.
Request Example:
shell :
curl https://tecni.com/tech/api/api-integration.json --header "x-api-key: YOUR_API_KEY"
|
Auth in javascript
const options = {
method: 'POST',
headers: {
accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({grant_type: 'client_credentials'})
};
fetch('https://tecni.com/tech/api-person-search.php', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
|
Authentication
Authentication example
post https://tecni.com/tech/api-person-search.php
Use your api_id and api_key as your username and password to get your access token.
Log in to see full request history
time status user agent
Make a request to see history.
Use this request you to obtain an access token and use it to access to the verification process scope.
❗️ Username and Password Use api_id as your username, and api_key as your password.
Both the api_id and api_key are available through your dashboard under "Integration".
The following is an example call that hashes your api_id and api_key in the authorization header
|
Shell
($(echo -en ':' | base64)).
curl
--location
--request POST 'https://tecni.com/tech/api-person-search.php' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H "Authorization: Basic \
$(echo -en ':' | base64)" \
-d 'grant_type=client_credentials'
|
JAVASCRIPT
const options = {
method: 'POST',
headers: {
accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({grant_type: 'client_credentials'})
};
fetch('https://tecni.com/tech/api-person-search.php', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
|
JSON
{
"grant_type": "client_credentials"
}
|
SHELL
curl --request POST \
--url https://tecni.com/tech/api-person-search.php \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'accept: application/json' \
--data grant_type=client_credentials
|
PYTHON
import requests
url = "https://tecni.com/tech/api-person-search.php"
payload = { "grant_type": "client_credentials" }
headers = {
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
}
response = requests.post(url, data=payload, headers=headers)
print(response.text)
|
NODE.JS
import mati from '@api/mati';
mati.authentication({grant_type: 'client_credentials'})
.then(({ data }) => console.log(data))
.catch(err => console.error(err));
|
PHP
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://tecni.com/tech/api-person-search.php', [
'form_params' => [
'grant_type' => 'client_credentials'
],
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
'accept' => 'application/json',
],
]);
echo $response->getBody();
|
C#
using RestSharp;
var options = new RestClientOptions("https://tecni.com/tech/api-person-search.php");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("accept", "application/json");
request.AddParameter("grant_type", "client_credentials");
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
|
C++
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, stdout);
curl_easy_setopt(hnd, CURLOPT_URL, "https://tecni.com/tech/api-person-search.php");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
CURLcode ret = curl_easy_perform(hnd);
|
RUBY
require 'uri'
require 'net/http'
url = URI("https://tecni.com/tech/api-person-search.php")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["accept"] = 'application/json'
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "grant_type=client_credentials"
response = http.request(request)
puts response.read_body
|