# Agent Login

This routine is intended to be used when you wish to have the system create and issue a new API Token, API User ID and API Account ID. This routine authenticates first that the agent is an active agent in your system (based on the expiry date of their account).

## zapiAgentLogin

<mark style="color:green;">`POST`</mark> `https://{yourdomainname}.zaui.net/zapi/`

#### Request Body

| Name                                           | Type   | Description                        |
| ---------------------------------------------- | ------ | ---------------------------------- |
| zapiUsername<mark style="color:red;">\*</mark> | string | Username set in the agent profile. |
| zapiPassword<mark style="color:red;">\*</mark> | string | Password set in the agent profile. |
| methodName<mark style="color:red;">\*</mark>   | string | The method being called.           |

{% tabs %}
{% tab title="200: OK " %}

```xml
<?xml version="1.0" encoding="utf-8"?>
<response>
    <zapiVersion>2.1</zapiVersion>
    <error>0</error>
    <message>OK</message>
    <methodResponse>
        <methodName>zapiAgentLogin</methodName>
        <methodErrorCode>0</methodErrorCode>
        <methodErrorMessage>Login Successful</methodErrorMessage>
        <zapiUsername>joesmith</zapiUsername>
        <zapiAccountId>398</zapiAccountId>
        <zapiUserId>1227</zapiUserId>
        <firstName>Joe</firstName>
        <lastName>Smith</lastName>
        <zapiApiToken>58ac1371783bc1091e5248f6c4ef8ff5cb0e4f1a</zapiApiToken>
        <cartId>b17d62046cde010f18c10285f3f85c82</cartId>
    </methodResponse>
</response>
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Request" %}

```xml
<request>
	<zapiUsername></zapiUsername>
	<zapiPassword></zapiPassword>
	<zapiMethod>
		<methodName>zapiAgentLogin</methodName>
	</zapiMethod>
</request>
```

{% endtab %}

{% tab title="Response" %}

```xml
<?xml version="1.0" encoding="utf-8"?>
<response>
	<zapiVersion>2.1</zapiVersion>
	<error>0</error>
	<message>OK</message>
	<methodResponse>
		<methodName>zapiMobileLogin</methodName>
		<methodErrorCode></methodErrorCode>
		<methodErrorMessage></methodErrorMessage >
		<zapiUsername></zapiUsername>
		<zapiAccountId></zapiAccountId>
		<zapiUserId></zapiUserId>
		<firstName></firstName>
		<lastName></lastName>
		<zapiApiToken/>
		<cartId></cartId>
	</methodResponse>
</response> 
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zaui.com/zapi/zapi-calls/agent-calls/agent-login.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
