This page will help you get started with Awesome New API.
API Description: This API is used to authenticate users and generate an auth token that can be used to access protected resources on the server.
<?php
$mobile = "1234";
$password = "password";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://pg.nippy.co.in/api/authtoken/',
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 => json_encode(array(
"mobile" => $mobile,
"password" => $password
)),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
),
));
$response = curl_exec($curl);
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($http_status == 200) {
$response_data = json_decode($response, true);
$auth_token = $response_data['authToken'];
echo "Auth Token: " . $auth_token . "\n";
} else {
$error_data = json_decode($response, true);
echo "Error Message: " . $error_data['message'] . "\n";
echo "Error Code: " . $error_data['code'] . "\n";
}
API Endpoint:
Request Method:
POST
Request Body:
Field | Type | Description |
---|---|---|
mobile | string* | The user's mobile number |
password | string* | The user's password |
Response:
Field | Type | Description |
---|---|---|
authToken | string | The auth token generated for the user. |
Example Request:
{
"mobile": "1234",
"password": "password"
}
Example Response:
{
"authToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtb2JpbGUiOiIxMjM0NTY3ODkwIiwicGFzc3dvcmQiOiJwYXNzd29yZCJ9.5RMpSoybEmJm8x-SO-bhKdyd6U5GT5pr-8JQdhAaYyk"
}
Error Responses:
- 401 Unauthorized: If the user's credentials are incorrect or invalid.
Example Error Response:
{
"message": "Invalid mobile or password",
"code": 401
}