Authentication
This endpoint provides an authentication token to get access to private resources in Testpress.

HTTP Request

Name
Type
Description
username
string
Username of the user
password
string
Password of the user
cURL
Ruby
Python
C#
PHP
Java
NodeJS
GO
To authorize, use this code:
1
# With shell, you can just pass the user credentials to get the auth token
2
curl --request POST \
3
--url https://demo.testpress.in/api/v2.2/auth-token/ \
4
--header 'cache-control: no-cache' \
5
--header 'content-type: application/json' \
6
--data '{"username": "testpress", "password": "demo"}'
Copied!
Make sure to replace testpress and demo with your credentials. The above command returns JSON structured like this:
1
{"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RwcmVzcyIsInVzZXJfaWQiOjE3LCJlbWFpbCI6InRlc3RwcmVzcy5pbkBnbWFpbC5jb20iLCJleHAiOjE0NDc4MzMyMjl9.Ik_yi4lHbNbrRGhqmRpsW82Nls_O9lgXakk_syV-vSw"}
Copied!
To authorize, use this code:
1
re 'uri'
2
require 'net/http'
3
4
url = URI("https://demo.testpress.in/api/v2.2/auth-token/")
5
6
http = Net::HTTP.new(url.host, url.port)
7
http.use_ssl = true
8
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
9
10
request = Net::HTTP::Post.new(url)
11
request["content-type"] = 'application/json'
12
request["cache-control"] = 'no-cache'
13
request.body = "{\n \"username\": \"testpress\",\n \"password\": \"demo\"\n}"
14
15
response = http.request(request)
16
puts response.read_body
Copied!
Make sure to replace testpress and demo with your credentials. The above command returns JSON structured like this:
1
{"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RwcmVzcyIsInVzZXJfaWQiOjE3LCJlbWFpbCI6InRlc3RwcmVzcy5pbkBnbWFpbC5jb20iLCJleHAiOjE0NDc4MzMyMjl9.Ik_yi4lHbNbrRGhqmRpsW82Nls_O9lgXakk_syV-vSw"}
Copied!
To authorize, use this code:
1
import requests
2
3
url = "https://demo.testpress.in/api/v2.2/auth-token/"
4
5
payload = "{\n \"username\": \"testpress\",\n \"password\": \"demo\"\n}"
6
headers = {
7
'content-type': "application/json",
8
'cache-control': "no-cache",
9
}
10
11
response = requests.request("POST", url, data=payload, headers=headers)
12
13
print(response.text)
Copied!
Make sure to replace testpress and demo with your credentials. The above command returns JSON structured like this:
1
{"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RwcmVzcyIsInVzZXJfaWQiOjE3LCJlbWFpbCI6InRlc3RwcmVzcy5pbkBnbWFpbC5jb20iLCJleHAiOjE0NDc4MzMyMjl9.Ik_yi4lHbNbrRGhqmRpsW82Nls_O9lgXakk_syV-vSw"}
Copied!

To authorize, use this code:

1
var client = new RestClient("https://demo.testpress.in/api/v2.2/auth-token/");
2
var request = new RestRequest(Method.POST);
3
request.AddHeader("cache-control", "no-cache");
4
request.AddHeader("content-type", "application/json");
5
request.AddParameter("application/json", "{\n \"username\": \"admin\",\n \"password\": \"demo\"\n}", ParameterType.RequestBody);
6
IRestResponse response = client.Execute(request);
Copied!
Make sure to replace testpress and demo with your credentials. The above command returns JSON structured like this:
1
{"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RwcmVzcyIsInVzZXJfaWQiOjE3LCJlbWFpbCI6InRlc3RwcmVzcy5pbkBnbWFpbC5jb20iLCJleHAiOjE0NDc4MzMyMjl9.Ik_yi4lHbNbrRGhqmRpsW82Nls_O9lgXakk_syV-vSw"}
Copied!
To authorize, use this code:
Make sure to replace testpress and demo with your credentials. The above command returns JSON structured like this:
1
<?php
2
3
$curl = curl_init();
4
5
curl_setopt_array($curl, array(
6
CURLOPT_URL => 'https://demo.testpress.in/api/v2/3/auth-token/',
7
CURLOPT_CUSTOMREQUEST => 'POST',
8
CURLOPT_POSTFIELDS =>'{
9
"username": "<type_your_username_here>",
10
"password": "<type_your_password_here>"
11
}',
12
CURLOPT_HTTPHEADER => array(
13
'Content-Type: application/json'
14
),
15
));
16
17
$response = curl_exec($curl);
18
19
curl_close($curl);
20
echo $response;
Copied!
1
{"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RwcmVzcyIsInVzZXJfaWQiOjE3LCJlbWFpbCI6InRlc3RwcmVzcy5pbkBnbWFpbC5jb20iLCJleHAiOjE0NDc4MzMyMjl9.Ik_yi4lHbNbrRGhqmRpsW82Nls_O9lgXakk_syV-vSw"}
Copied!
1
OkHttpClient client = new OkHttpClient();
2
3
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001");
4
RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\nadmin\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\ndemo\r\n-----011000010111000001101001--");
5
Request request = new Request.Builder()
6
.url("http://demo.testpress.in/api/v2.2/auth-token/")
7
.post(body)
8
.addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
9
.addHeader("authorization", "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6MTM5NTYsInVzZXJfaWQiOjEzOTU2LCJlbWFpbCI6ImRlcy5wcm8ubWFkaGFuQGhvdG1haWwuY29tIiwiZXhwIjoxNDY0MzQwMzg1fQ.TElNLpQE8KERVe7Q-vjNk9aU-9prOfzBb43srB9WmC0")
10
.addHeader("cache-control", "no-cache")
11
.addHeader("postman-token", "987488b1-1b5f-dd8b-95fc-fea8d276b2ae")
12
.build();
13
14
Response response = client.newCall(request).execute();
Copied!
1
{"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RwcmVzcyIsInVzZXJfaWQiOjE3LCJlbWFpbCI6InRlc3RwcmVzcy5pbkBnbWFpbC5jb20iLCJleHAiOjE0NDc4MzMyMjl9.Ik_yi4lHbNbrRGhqmRpsW82Nls_O9lgXakk_syV-vSw"}
Copied!
1
{"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RwcmVzcyIsInVzZXJfaWQiOjE3LCJlbWFpbCI6InRlc3RwcmVzcy5pbkBnbWFpbC5jb20iLCJleHAiOjE0NDc4MzMyMjl9.Ik_yi4lHbNbrRGhqmRpsW82Nls_O9lgXakk_syV-vSw"}
Copied!
1
{"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RwcmVzcyIsInVzZXJfaWQiOjE3LCJlbWFpbCI6InRlc3RwcmVzcy5pbkBnbWFpbC5jb20iLCJleHAiOjE0NDc4MzMyMjl9.Ik_yi4lHbNbrRGhqmRpsW82Nls_O9lgXakk_syV-vSw"}
Copied!
Replace demo with your institute subdomain hereafter everywhere.

Response

The response will return an token which should be prefixed with JWT and included in all API requests to the server in a header that looks like the following:
Authorization: JWT auth-token-string
You must replace auth-token-string with the token you got from the response.
Last modified 1mo ago
Copy link