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))
}
var form = new FormData();
form.append("client_id", "{{client_id}}");
form.append("client_secret", "{{client_secret}}");

var settings = {
  "url": "https://api.d7networks.com/auth/v1/login/application",
  "method": "POST",
  "timeout": 0,
  "processData": false,
  "mimeType": "multipart/form-data",
  "contentType": false,
  "data": form
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
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

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