Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

REQUEST

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

The structure of API as below:

POST/auth/as_agent

HEADER

The request requires you given the Admin Token in headers. If you don't give the Token in headers or wrong Token, the return "error_message" is "Authentication Error" and the request is failed. To get the Token, please refer Authenticate User for more details.

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

BODY

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

Code Block
{
	"agent_id": ID of the Agent
}

JSON RESPONSE

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

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

Code Block
{
 	"success": true/false,
  	"payload": { Related Information of the Agent }
 	"token":"Agent Token",
   	"cdr_api_token": "cdr_api_token"
}

 

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

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

 

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

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

 

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

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

 

EXAMPLE

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

Request

I will call API to authenticate as Agent:

Code Block
curl \
-X POST -d "{ \"agent_id\": \"34\"}" \
"http://88.99.175.131:8000/v1/auth/as_agent"
 

Response

Code Block
{
	"success": true,
   	"payload":    {
      	"cdr_api_token_expiration": "186544678",
      	"user":       {
         	"login_ip": "183.182.110.28",
         	"first_name": "Ha",
         	"fullname": "Ha Tran",
         	"create_time": "2017-09-08T22:00:00+00:00",
         	"passwd": "$2a$12$.vfsbhghghjfgfghdfdghhh7iyoz/euRq6r6",
         	"report_count": "1 Hour",
         	"is_online": 1,
         	"last_name": "Tran",
         	"role_name": "Agent",
         	"client_id": null,
         	"cdr_api_token": "eHC0hakjsdhjhjqeweqweq32njkasdjSSt",
         	"user_id": 1,
         	"all_termination": true,
         	"show_carrier_trunk_drop_only": true,
         	"default_mod": "0",
         	"user_type": "agent",
         	"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": "agent",
       	"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"
   }
}

...