Skip to content

CreateInstance#

Beta version

The functionality is in beta. Features may change and may also work unstably.

The method is used to create an instance on a partner account.

After creating an instance without settings, the default settings will be disabled.

Request#

To create an account instance on behalf of the partner, you have to execute a POST request at:

POST
{{partnerApiUrl}}/partner/createInstance/{{partnerToken}}

The partnerApiUrl parameter can be seen in the console.

The partnerToken request parameter is obtained via GREEN-API technical support by requesting a partnership API key.

Request parameters#

The parameters may be specified selectively. At least one parameter has to be specified.

Parameter Type Mandatory Description
name string No The name of the instance specified in the console
webhookUrl string No The URL to send webhooks to
webhookUrlToken string No The token for the connection to your webhook server
delaySendMessagesMilliseconds integer No The delay between sending outgoing messages in milliseconds, 500 ms by default.
The minimum value: 500 ms (0.5 seconds)
The maximum value: 60000 ms (1 minute).
A value outside these bounds is brought to the nearest one.
markIncomingMessagesReaded string No Mark incoming messages as read (yes, no), no by default, the parameter is ignored if markIncomingMessagesReadedOnReply has the yes value
markIncomingMessagesReadedOnReply string No Mark incoming messages as read (yes, no) when sending a message to the chat, no by default (incoming messages are not marked as read)
outgoingWebhook string No Receive notifications about the statuses of sent messages, the possible values are: yes, no. no by default
outgoingMessageWebhook string No Receive notifications about messages sent not via the API, the possible values are: yes, no. no by default
outgoingAPIMessageWebhook string No Receive notifications about messages sent via the API, the possible values are: yes, no. no by default
stateWebhook string No Receive notifications about the instance authorization state change, the possible values are: yes, no. no by default
incomingWebhook string No Receive notifications about incoming messages, the possible values are: yes, no. no by default
incomingMessageStatusWebhook string No Receive notifications about incoming messages being read, the possible values are: yes, no. no by default

Request body example#

{
    "name": "My instance",
    "webhookUrl": "https://mysite.com/webhook/green-api/",
    "webhookUrlToken": "f93537eb3e8fed66847b5bd",
    "delaySendMessagesMilliseconds": 1000,
    "markIncomingMessagesReaded": "no",
    "markIncomingMessagesReadedOnReply": "no",
    "outgoingAPIMessageWebhook": "yes",
    "outgoingWebhook": "yes",
    "outgoingMessageWebhook": "yes",
    "incomingWebhook": "yes",
    "incomingMessageStatusWebhook": "no",
    "stateWebhook": "no"
}

Response#

Response parameters#

Field Type Description
apiTokenInstance string The API token of the account instance
apiUrl string The API host link
idInstance integer The identifier of the account instance.
A uint64 value, 10 digits
mediaUrl string The API host link for sending files
typeInstance string The messenger type for the account instance, takes the value instagram for Instagram

Response body example#

In case of success, a JSON string of the following form is returned in response to the request with the HTTP status 200:

{
    "apiTokenInstance": "c1b0474542144e0ead529eb4861ca5f583c346eb00564f64a7",
    "apiUrl": "https://5100.api.green-api.com/",
    "idInstance": 5100000000,
    "mediaUrl": "https://5100.api.green-api.com/",
    "typeInstance": "instagram"
}

In case of failure, a response with the HTTP status 200 is returned, and the response body contains a JSON string with the code and the description of the error:

{
    "code": 401,
    "description": "Unauthorized"
}

CreateInstance errors#

For a list of errors common to all methods, refer to the Common errors section

Request examples#

import requests

url = "https://api.green-api.com/partner/createInstance/{{partnerToken}}"

payload = {
 "name": "first instance",
 "webhookUrl": "",
 "webhookUrlToken": "",
 "delaySendMessagesMilliseconds": 3000,
 "markIncomingMessagesReaded": "no",
 "markIncomingMessagesReadedOnReply": "no",
 "outgoingWebhook": "yes",
 "outgoingMessageWebhook": "yes",
 "outgoingAPIMessageWebhook": "yes",
 "incomingWebhook": "yes",
 "incomingMessageStatusWebhook": "no",
 "stateWebhook": "yes"
}
headers = {
    'Content-Type': 'application/json'
}

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

print(response.text.encode('utf8'))
    curl --location --globoff 'https://api.green-api.com/partner/createInstance/{{partnerToken}}' \
    --header 'Content-Type: application/json' \
    --data '{
   "name":"first instance", 
    "webhookUrl": "", 
   "webhookUrlToken": "",
   "delaySendMessagesMilliseconds": 3000,
   "markIncomingMessagesReaded": "no",
   "markIncomingMessagesReadedOnReply": "no",
   "outgoingWebhook": "yes",
   "outgoingMessageWebhook": "yes",
   "outgoingAPIMessageWebhook": "yes",
   "incomingWebhook": "yes",
   "incomingMessageStatusWebhook": "no",
   "stateWebhook": "yes"
}'
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://api.green-api.com/partner/createInstance/{{partnerToken}}")
  .header("Content-Type", "application/json")
  .body("""
      {
          "name": "first instance",
          "webhookUrl": "",
          "webhookUrlToken": "",
          "delaySendMessagesMilliseconds": 3000,
          "markIncomingMessagesReaded": "no",
          "markIncomingMessagesReadedOnReply": "no",
          "outgoingWebhook": "yes",
          "outgoingMessageWebhook": "yes",
          "outgoingAPIMessageWebhook": "yes",
          "incomingWebhook": "yes",
          "incomingMessageStatusWebhook": "no",
          "stateWebhook": "yes"
      }
      """)
  .asString();