REQUEST

This API is used to authenticate the client by using admin credentials. In Portal, after logging in as Admin then go to see Client details, you can see login as client button. This API uses the admin token to log in as the client.

The structure of API as below:

POST/auth/as_client

HEADER

The request requires you given the Admin Token in headers. To get the Token, please refer Authenticate User for more details.

{
	"accept": "application/json",
	"X-Auth-Token": "Admin Token"
}

 

If you call API without header, the system will return the message as below:

{
  	"error_type": "unauthenticated_error",
   	"success": false,
   	"error":    {
      	"message": "No header X-Auth-Token present",
      	"code": 110,
      	"reason": "auth_token_not_provided"
   	}
}

BODY

You have to put the ID of the Client that you want to authenticate into body as below:

{
	"client_id": ID of the Client
}

JSON RESPONSE

There is message return as JSON format. It will return the result of API and the related information as well.

If successful, server will return code 200 with message as below:

{
 	"success": true,
  	"payload": { Related Information of the Client }
 	"token":"Client Token",
   	"cdr_api_token": "cdr_api_token"
}

 

If missing body or missing any fields, It will return code 400 and message as below:

{
   "error_type": "validation_error",
   "success": false,
   "errors": [   {
      "field_name": ["Missing data for required field."]
   }]
}

 

If the Token wrong, it will return code 401 with message as below:

{
 	"error_type": "unauthenticated_error",
  	"success": false,
  	"error": {
    	"message": "No header X-Auth-Token present",
    	"code": 110,
    	"reason": "auth_token_not_provided"
  	}
}

 

If you provide wrong client_id, server will return code 404 with message as below:

{
  "error_type": "Object not found error",
  "success": false
}

On this page:

EXAMPLE

We will know more about the API through the example below:

Request

I will call API to authenticate as client:

curl \
-H "X-Auth-Token: eyaskjksadkasd9.9123kjsadhkj123jhasdjajsjsdhKS.IH5uHASSJsadnbads980asTHo9dhljM" \
-X POST -d "{ \"client_id\": \"41\"}" \
"http://88.99.175.131:8000/v1/auth/as_client"
 

Response

{
	"success": true,
   	"payload":    {
      	"cdr_api_token_expiration": "186544678",
      	"user":       {
         	"login_ip": "183.182.110.28",
         	"first_name": "DN",
         	"fullname": "DN Nguyen",
         	"create_time": "2017-09-08T22:00:00+00:00",
         	"passwd": "$2a$12$.vfsbhghghjfgfghdfdghhh7iyoz/euRq6r6",
         	"report_count": "1 Hour",
         	"is_online": 1,
         	"last_name": "nguyen",
         	"role_name": "Client",
         	"client_id": null,
         	"cdr_api_token": "eHC0hakjsdhjhjqeweqweq32njkasdjSSt",
         	"user_id": 1,
         	"all_termination": true,
         	"show_carrier_trunk_drop_only": true,
         	"default_mod": "0",
         	"user_type": "client",
         	"client_limits":          [
            	{"client_id": 2916},
            	{"client_id": 2917}
         		],
       	"role_id": 0,
      	"last_login_time": "2018-02-24T21:05:36.094423+00:00",
      	"reseller_id": 0,
       	"cdr_expire": "2018-02-25T14:11:53+00:00",
      	"outbound_report": true,
       	"email": "[email protected]",
       	"carrier_name": null,
       	"default_mod2": "0",
       	"active": true,
       	"landing_page": "/routing/rate_table",
       	"create_user_id": null,
       	"card_id": 0,
       	"name": "admin",
       	"client": null,
       	"report_group": true,
       	"last_seen": "2018-02-24T22:11:18.724125+00:00",
       	"report_fields": "111",
       	"is_preload": true,
       	"default_billing_decimal": 0,
       	"avatar_id": 1366,
       	"auth_ip": [],
       	"agent": null
      	},
 	"token": "eyaskjksadkasd9.9123kjsadhkj123jhasdjajsjsdhKS.IH5uHASSJsadnbads980asTHo9dhljM",
  	"cdr_api_token": "eHC0hakjsdhjhjqeweqweq32njkasdjSSt"
   }
}