API Login User

Estimated reading: 3 minutes

Description :

Use this API to log in a user from various platforms like web browsers, native applications in Android, or iOS.

URL :

Endpoint :

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

				
			
Method : POST
URL Parameters Required
Content type format: JSON or form-data
Yes

Form Data Parameters:

KeyValue
client_idAlphanumeric value identifying the client.
client_secretAlphanumeric value identifying the client's secret.
environmentSpecifies the environment. Valid values are localhost, development:sandbox, or production.

Example Request :

				
					{
  "client_id": "cOaWg1cFuBK7ytOOdnSjxf536R1ANIA3",
  "client_secret": "gGQlhpSl5Rpanz0m",
  "environment": "localhost"
}

				
			
PHP code :
				
					<?php
$url = "http://<server-ip-address>/custom_api/external_login";
$data = array(
  "client_id" => "cOaWg1cFuBK7ytOOdnSjxf536R1ANIA3",
  "client_secret" => "gGQlhpSl5Rpanz0m",
  "environment" => "localhost"
);

$options = array(
  "http" => array(
    "header" => "Content-type: application/json",
    "method" => "POST",
    "content" => json_encode($data)
  )
);

$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
?>

				
			
Javascript code :
				
					var xhr = new XMLHttpRequest();
var url = "http://<server-ip-address>/custom_api/external_login";
var data = JSON.stringify({
  "client_id": "cOaWg1cFuBK7ytOOdnSjxf536R1ANIA3",
  "client_secret": "gGQlhpSl5Rpanz0m",
  "environment": "localhost"
});

xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data)

				
			
cURL code :
				
					curl -X POST "http://<server-ip-address>/custom_api/external_login" \
     -H "Content-Type: application/json" \
     -d '{
           "client_id": "cOaWg1cFuBK7ytOOdnSjxf536R1ANIA3",
           "client_secret": "gGQlhpSl5Rpanz0m",
           "environment": "localhost"
         }'

				
			
Success Response:

Code : 200

Content :

The token to be used for authenticated requests.

Error Response :

Code: 401 BAD REQUEST

Content :

Various error messages depending on whether the client_id, client_secret, or both are missing or blank.

Note :

Error Responses:

Invalid client_id or client_secret:

Code:

401 BAD REQUEST

Content :

				
						{
    "code": 401,
    "message": "fail",
    "data": {
        "error": "Invalid client_id or client_secret"
    }
}

				
			

1- Missing client_id :

Code : 401 BAD REQUEST

Content :

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

				
			

2- Missing client_secret and client_id:

Code : 401 BAD REQUEST

Content :

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

				
			

3- Missing client_secret:

Code : 401 BAD REQUEST

Content :

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

				
			

4- Blank client_secret :

Code : 401 BAD REQUEST

Content :

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

				
			

5- Blank client_secret and client_id :

Code : 401 BAD REQUEST

Content :

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

				
			

These error responses cover various cases of missing or blank client ID and client secret, thereby providing clear feedback on what might have gone wrong with the request. The error messages are designed to assist the developer in quickly identifying and correcting any mistakes in the request.

Share this Doc

API Login User

Or copy link

CONTENTS