User Management – Login User

Estimated reading: 2 minutes

Description :

Use this API to login a user from anywhere (Web Browser, Native application in Android, iOS).

URL :

				
					http://<server-ip-address>/custom_api/login

				
			
Method : POST
URL Parameters Required
JSON or form-data
Yes
optional
parent_id

Form Data Parameters:

KeyValue
Email[string]
password[alphanumeric]
parent_id[integer]

Example :

				
					{
	"email": "satim@almiranta.com",
	"password": "comples@&*@#",
	"parent_id": 50511
}

				
			

Success Response :

Code : 200

Content :

				
					{
    "code": 200,
    "message": "success",
    "data": {
        "token": "b9e223b8c1d2917a28f6cf774c3ef720356cef7a6f37189db66ef41e3d468587e11b157e872c99d82935e5292f2f31944e48017a930e9a128c494e63"
    }
}

				
			
Error Response :

There are several potential error responses:

1- Invalid e-mail or password :

Code : 401 BAD REQUEST

Content :

				
					{
    "code": 401,
    "message": "fail",
    "data": {
        "error": "Invalid e-mail or password"
    }
}

				
			
2- E-mail field is missing :

Code : 401 BAD REQUEST

Content :

				
					{
    "code": 401,
    "message": "fail",
    "data": {
        "[email]": [
            "This field is missing."
        ]
    }
}

				
			

3- Password and e-mail fields are missing :

Code : 401 BAD REQUEST

Content :

				
					{
    "code": 401,
    "message": "fail",
    "data": {
        "[password]": [
            "This field is missing."
        ],
        "[email]": [
            "This field is missing."
        ]
    }
}

				
			

4- Password field is missing:

Code : 401 BAD REQUEST

Content :

				
					{
    "code": 401,
    "message": "fail",
    "data": {
        "[password]": [
            "This field is missing."
        ]
    }
}
				
			

5- Password field should not be blank :

Code : 401 BAD REQUEST

Content :

				
					{
    "code": 401,
    "message": "fail",
    "data": {
        "[password]": [
            "This value should not be blank."
        ]
    }
}

				
			
6- Password and email fields should not be blank :

Code : 401 BAD REQUEST

Content :

				
					{
    "code": 401,
    "message": "fail",
    "data": {
        "[password]": [
            "This value should not be blank."
        ],
        "[email]": [
            "This value should not be blank."
        ]
    }
}

				
			

These are the detailed error responses that could be returned by the API based on the provided request parameters. It covers every scenario where the request might be incorrect or incomplete.

PHP Code :
				
					<?php

$url = "http://<server-ip-address>/custom_api/login";
$data = array(
    "email" => "satim@almiranta.com",
    "password" => "comples@&*@#",
    "parent_id" => 50511
);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

$response = curl_exec($ch);

if ($response === false) {
    echo 'Error: ' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);

?>

				
			
Javascript Code :
				
					const url = "http://<server-ip-address>/custom_api/login";
const headers = {
    "Content-Type": "application/json"
};

const data = {
    "email": "satim@almiranta.com",
    "password": "comples@&*@#",
    "parent_id": 50511
};

fetch(url, {
    method: 'POST',
    headers: headers,
    body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

				
			

Replace <server-ip-address> with your actual server IP address. The provided examples demonstrate how to make a POST request to this endpoint using PHP and JavaScript, including all required parameters and handling potential error responses.

Share this Doc

User Management – Login User

Or copy link

CONTENTS