Skip to content

GetAuthorizationCode#

Test Postman Apidog

The method is intended to authorize an instance by phone number. The method is used as an alternative to the QR method.

Authorization process:

  1. The official WhatsApp or WhatsApp Business application must be installed on your phone.
  2. You need to register in your console and create an instance.
  3. In the WhatsApp application, select the menu item "Linked devices" -> "Link a device" -> "Link with phone number instead".
  4. Call the GetAuthorizationCode method from console or through Postman collection by indicating your phone number in the body of the request (the phoneNumber field). In response to calling the GetAuthorizationCode method, you will receive 2 fields: status and code.

    The code for authorization by phone number is valid for approximately 2.5 minutes.

  5. Enter the received code in the WhatsApp application, authorization is successful.

To receive the code, the instance must be in an unauthorized state. If the instance is authorized, then you first need to log out the instance using the Logout method.

The authorization procedure is described in more detail in the section Before you start.

After successfully entering the code and authorizing the instance, an incoming notification of the form Instance Status is generated.

Request#

To retrieve the code, you need to execute a query at:

POST
{{apiUrl}}/waInstance{{idInstance}}/getAuthorizationCode/{{apiTokenInstance}}

Refer to Before-Start for the apiUrl, idInstance and apiTokenInstance request parameters.

Request parameters#

Parameter Type Mandatory Description
phoneNumber integer Yes Phone number in international format without + or 00

Request body example#

{
    "phoneNumber": 441234567890
}

Response#

Response parameters#

Field Type Description
status boolean Status of code receipt, possible values are true, false.
true - Code received successfully
false - Code not received. Possible reasons:
1. Instance is already authorized
2. An error occurred while receiving the code (try to receive the code again)
code string Authorization code

Response body example#

{
    "status": true,
    "code":"GAPI2018"
}

It may take up to 30 seconds to receive the code

Errors#

For a list of errors common to all methods, see Common errors

HTTP code Error identifier Description
200 "status": false 1. Instance is already authorized
2. An error occurred while receiving the code (try to receive the code again)
400 Bad Request
Validation failed
Validation error
400 Validation failed.
Details: Wrong format. 'phoneNumber' must contain only digits
The number must contain only numbers.

Code Examples#

import requests
import json

url = "{{apiUrl}}/waInstance{{idInstance}}/getAuthorizationCode/{{apiTokenInstance}}"

payload = json.dumps({
  "phoneNumber": 441234567890
})
headers= {}

response = requests.post(url, json=payload)

print(response.text.encode('utf8'))
  curl --location 'http://localhost:6001/waInstance9903789715/getAuthorizationCode/f4fc69110b364ecfbc75cdd800d0516e4933b4d4e9574ea688' \
  --header 'Content-Type: application/json' \
  --data '{
      "phoneNumber": 441234567890
  }'
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/getAuthorizationCode/")
    .append({{apiTokenInstance}});

var response = Unirest.post(requestUrl.toString())
    .header("Content-Type", "application/json")
    .body("{\n    \"phoneNumber\": 441234567890,\n}")
    .asString();
System.out.println(response);
Sub GetAuthorizationCode()
    Dim url As String
    Dim RequestBody As String
    Dim http As Object
    Dim response As String

    ' The apiUrl, idInstance and apiTokenInstance values are available in console, double brackets must be removed
    url = "{{apiUrl}}/waInstance{{idInstance}}/getAuthorizationCode/{{apiTokenInstance}}"

    ' phoneNumber - Phone number in international format without + and 00
    RequestBody = "{""phoneNumber"":79123456780}"

    Set http = CreateObject("MSXML2.XMLHTTP")

    With http
        .Open "POST", url, False
        .setRequestHeader "Content-Type", "application/json"
        .send RequestBody
    End With

    response = http.responseText

    Debug.Print response

    ' Outputting the answer to the desired cell
    Range("A1").Value = response

    Set http = Nothing
End Sub