# Get JWT Auth Token

# Request

  • Method: POST

  • Url: /jwt-api-token-auth/

  • Headers:

    • Content-Type: application/json
  • Body:

Parameter name Required Type Description
username Y String
password Y String
{
    "username": "username",
    "password": "password"
}

# Response

  • Data type: application/json
Field name Type Description
token String
{
    "token": "eyJhbG......abrCU"
}

# Get General Auth Token

# Request

  • Method: POST

  • Url: /api-token-auth/

  • Headers:

    • Content-Type: application/json
  • Body:

Parameter name Required Type Description
username Y String
password Y String
{
    "username": "username",
    "password": "password"
}

# Response

  • Data type: application/json
Field name Type Description
token String
{
    "token": "gP4K......biHUoy"
}

# Python example

import json
import requests


url = "http://zkeco.xmzkteco.com:8097/jwt-api-token-auth/"
headers = {
    "Content-Type": "application/json",
}
data = {
    "username": "admin",
    "password": "admin"
}

response = requests.post(url, data=json.dumps(data), headers=headers)
print(response.text)

# Postman example

postman1 postman2

# Java example

public static String doPost(String httpUrl, String param) {

    HttpURLConnection connection = null;
    InputStream is = null;
    OutputStream os = null;
    BufferedReader br = null;
    String result = null;
    try {
        URL url = new URL(httpUrl);
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setConnectTimeout(15000);
        connection.setReadTimeout(60000);

        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestProperty("Content-Type", "application/json");da3efcbf-0845-4fe3-8aba-ee040be542c0
        os = connection.getOutputStream();
        os.write(param.getBytes());
        if (connection.getResponseCode() == 200) {

            is = connection.getInputStream();
            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));

            StringBuffer sbf = new StringBuffer();
            String temp = null;
            while ((temp = br.readLine()) != null) {
                sbf.append(temp);
                sbf.append("\r\n");
            }
            result = sbf.toString();
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (null != br) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (null != os) {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (null != is) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        connection.disconnect();
    }
    return result;
}

public static String buildParams(String username, String password){
    String tmp = "{\"username\": \"" + username + "\"," +
        " \"password\": \""+ password + "\"}";
    return tmp;
}

public static void main(String[] args){
    // final String url = "http://zkeco.xmzkteco.com:8097/jwt-api-token-auth/";
    final String url = "http://zkeco.xmzkteco.com:8097/api-token-auth/";
    String param = buildParams("admin", "admin");
    String result = doPost(url, param);
}