Login#
Beta version
The functionality is in beta. Features may change and may also work unstably.
The method authorizes an instance with the login and password of an Instagram account.
An alternative way of authorization is through a browser session.
The method uses the limits on the number of requests per second.
Request#
To authorize an instance, you have to execute a request at:
{{apiUrl}}/waInstance{{idInstance}}/login/{{apiTokenInstance}}
For apiUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.
Request parameters#
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
login | string | Yes | The username, phone number or email of the Instagram account: - the username - with or without @, for example @green_api_eng,- the phone number - with the country code, for example 79001234567. Only digits are taken into account when the number is processed,- the email - for example example@mail.com.The maximum length of the value is 320 characters. |
password | string | Yes | The password of the Instagram account. The maximum length is 200 characters. |
verificationType | string | No | The login confirmation way, if Instagram requests one. If the parameter is not passed, Instagram chooses the way. Takes the values: |
- confirm_from_device - tap "Yes" on a device where the account is already open. | |||
- phone_number - enter the code sent to the phone number linked to the account (SMS). | |||
- email - enter the code sent to the email linked to the account. | |||
- otp - enter the code from an authenticator app. |
If the method has returned
twoFactorRequired, the login is completed by the SendAuthorizationCode method: a confirmation code is passed to it - what Instagram expects is said inmessage.
If a way that Instagram has not offered for this login is passed, the response is type = error, and the available ways are listed in message. The login is not switched to another way: repeat the request with a way from this list.
Request body example#
A request without a confirmation way:#
{
"login": "@green_api_eng",
"password": "secret"
}
A request with the confirmation way selected:#
{
"login": "@green_api_eng",
"password": "secret",
"verificationType": "email"
}
Response#
Response parameters#
| Field | Type | Description |
|---|---|---|
type | string | The login result. Takes the values: |
- authorized - the login is done: the instance is in the authorized state and is ready to work. | ||
- alreadyLogged - the instance is already authorized with the same account. | ||
- confirmFromDevice - confirm the login in the Instagram app: tap "Yes" on a device where the account is already open, and repeat the login request with the same data.If Instagram offers to enter a code and the message field ends with Or submit a code with sendAuthorizationCode., pass the received code with the SendAuthorizationCode method. | ||
- twoFactorRequired - send the confirmation code by the SendAuthorizationCode method.The type of the required confirmation code is given in the message field. | ||
- passkeyRequired - a login with a passkey is required - a fingerprint, Face ID or a hardware key instead of the password. Such a login cannot be performed through the API: neither a code nor repeating the password helps. Turn the passkey off in the Instagram security settings or authorize the instance through a browser session | ||
- timeout - Instagram did not answer within the set time. The request could still have been received and processed. Wait a few minutes before trying to authorize again, because frequent requests can lead to the account being blocked. | ||
- rejected - Instagram rejected the login.Wrong password - a wrong password;Login rejected by user in the Instagram app - the login has been rejected ("No") on a device where the account is already open;Login rejected by Instagram - Instagram itself has refused the login, for example the account is deactivated. | ||
- error - Instagram rejected the login: an unavailable confirmation way and other reasons. The details are in the message field. | ||
message | string | The details of the result |
Response body example#
The login is done:#
{
"type": "authorized"
}
The instance is already authorized:#
{
"type": "alreadyLogged"
}
A confirmation on a device is required:#
{
"type": "confirmFromDevice",
"message": "Approve the login on the trusted device, then call login again. Or submit a code with sendAuthorizationCode."
}
A code is required:#
{
"type": "twoFactorRequired",
"message": "Instagram sent code to n****@g****.com (email)."
}
A code from an authenticator app is required:#
{
"type": "twoFactorRequired",
"message": "Instagram is waiting for the code from the authentication app (otp)"
}
The requested confirmation way is not available:#
{
"type": "error",
"message": "verificationType phone_number is not available. Available: email (e*******e@gmail.com), confirm_from_device"
}
Login errors#
For a list of errors common to all methods, refer to the Common errors section
| HTTP code | Error ID | Description |
|---|---|---|
| 400 | Bad Request Validation failed | Validation error |
| 400 | Validation failed. Details: 'login' is required | The login is not passed |
| 400 | Validation failed. Details: 'password' is required | The password is not passed |
| 400 | Validation failed. Details: 'login' is not allowed to be empty | An empty login is passed |
| 400 | Validation failed. Details: 'password' is not allowed to be empty | An empty password is passed |
| 400 | Validation failed. Details: 'login' length must be less than or equal to 320 characters long | The login is longer than 320 characters |
| 400 | Validation failed. Details: 'login' must be an Instagram username (with or without '@'), an email or a phone number | The login looks neither like a nickname, nor like an email, nor like a phone number |
| 400 | Validation failed. Details: 'password' length must be less than or equal to 200 characters long | The password is longer than 200 characters |
| 400 | Validation failed. Details: 'verificationType' must be one of [confirm_from_device, email, phone_number, otp] | An unknown confirmation way |
Request examples#
import requests
url = "{{apiUrl}}/waInstance{{idInstance}}/login/{{apiTokenInstance}}"
payload = {
"login": "@green_api_eng",
"password": "secret",
"verificationType": "email"
}
headers = {
'Content-Type': 'application/json'
}
response = requests.post(url, json=payload, headers=headers)
print(response.text.encode('utf8'))
<?php
$url = '{{apiUrl}}/waInstance{{idInstance}}/login/{{apiTokenInstance}}';
$data = array(
'login' => '@green_api_eng',
'password' => 'secret',
'verificationType' => 'email'
);
$options = array(
'http' => array(
'header' => "Content-Type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data)
)
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
echo $response;
?>
curl --location '{{apiUrl}}/waInstance{{idInstance}}/login/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"login": "@green_api_eng",
"password": "secret",
"verificationType": "email"
}'
var requestUrl = new StringBuilder();
requestUrl
.append({{apiUrl}})
.append("/waInstance").append({{idInstance}})
.append("/login/")
.append({{apiTokenInstance}});
var response = Unirest.post(requestUrl.toString())
.header("Content-Type", "application/json")
.body("""
{
"login": "@green_api_eng",
"password": "secret",
"verificationType": "email"
}
""")
.asString();
System.out.println(response);