Skip to content

Generate token

In case you have already created the authentication token from the D7 Control Panel, you can skip this page.

For generation of auth token call /auth/v1/login/application with client_id and client_secret as body parameters and this will return the auth token in response. For messaging and verify endpoints you have to use this token.

Request parameters

When calling Generate Token API endpoint, the below parameters must be passed as form data in body and the api will return the access token and type on success.

Parameter Value / Pattern Example(s)
*client_id Application client id JC5NjTIVY2JasdfavdadrdfgadfvxemUGKOJ
*client_secret Application client secret wcyRoYD1wOfIZRjasdfasdfjfikmgkfmoVl4OLUmYLZu1rC2T7Nd

Example

1
2
3
curl --location --request POST 'https://api.d7networks.com/auth/v1/login/application' \
--form 'client_id="{{client_id}}"' \
--form 'client_secret="{{client_secret}}"'
var axios = require('axios');
var FormData = require('form-data');
var data = new FormData();
data.append('client_id', '{{client_id}}');
data.append('client_secret', '{{client_secret}}');

var config = {
  method: 'post',
  url: 'https://api.d7networks.com/auth/v1/login/application',
  headers: { 
    ...data.getHeaders()
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});
import requests

url = "https://api.d7networks.com/auth/v1/login/application"

payload={'client_id': '{{client_id}}',
'client_secret': '{{client_secret}}'}
files=[

]
headers = {}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.d7networks.com/auth/v1/login/application',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('client_id' => '{{client_id}}','client_secret' => '{{client_secret}}'),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
package main

import (
  "fmt"
  "bytes"
  "mime/multipart"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.d7networks.com/auth/v1/login/application"
  method := "POST"

  payload := &bytes.Buffer{}
  writer := multipart.NewWriter(payload)
  _ = writer.WriteField("client_id", "{{client_id}}")
  _ = writer.WriteField("client_secret", "{{client_secret}}")
  err := writer.Close()
  if err != nil {
    fmt.Println(err)
    return
  }


  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Set("Content-Type", writer.FormDataContentType())
  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
  .addFormDataPart("client_id","{{client_id}}")
  .addFormDataPart("client_secret","{{client_secret}}")
  .build();
Request request = new Request.Builder()
  .url("https://api.d7networks.com/auth/v1/login/application")
  .method("POST", body)
  .build();
Response response = client.newCall(request).execute();
    ```
=== "Dart"

    ``` dart linenums="1" 
var request = http.MultipartRequest('POST', Uri.parse('https://api.d7networks.com/auth/v1/login/application'));
request.fields.addAll({
  'client_id': '{{client_id}}',
  'client_secret': '{{client_secret}}'
});


http.StreamedResponse response = await request.send();

if (response.statusCode == 200) {
  print(await response.stream.bytesToString());
}
else {
  print(response.reasonPhrase);
}
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "client_id"
$stringContent = [System.Net.Http.StringContent]::new("{{client_id}}")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "client_secret"
$stringContent = [System.Net.Http.StringContent]::new("{{client_secret}}")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$body = $multipartContent

$response = Invoke-RestMethod 'https://api.d7networks.com/auth/v1/login/application' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
require "uri"
require "net/http"

url = URI("https://api.d7networks.com/auth/v1/login/application")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
form_data = [['client_id', '{{client_id}}'],['client_secret', '{{client_secret}}']]
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body

Response

200 - Success
{
  "access_token": "eyJhbGciOiJIjojodfklskdf0.WnQ1cBrMWShYlsdrQHUcu_Y_clgg5uc6c_u6TGk1qX0",
  "token_type": "bearer"
}
404 - Not Found
{
  "detail": {
    "code": "APPLICATION_NOT_EXISTS",
    "message": "Application not exists"
  }
}
401 - Unauthorized
{
  "detail": {
    "code": "ACCESS_TOKEN_EXPIRED",
    "message": "Access token signature has expired"
  }
}

Response Parameters

Parameter Value / Pattern
access_token Authentication token that allow the application to access D7 API
token_type Access token type. To send a request with the Bearer Token authorization header, you need to make an HTTP request and provide your Bearer Token in the "Authorization: Bearer {access_token}" HTTP header