Skip to content

CreateInstance#

Test

The method is used to creating a messenger account instance on the partner's part.

After creating an instance with no settings, settings will be turned off by default.

Request#

To create an account instance on the partner's part you have to execute a POST request at:

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

For partnerApiUrl request parameter, you can find it in your console.

For partnerTokenrequest parameter please contact GREEN-API support@green-api.com with a request to get a partnership API-token.

Request parameters#

Selective specification of parameters is allowed. At least one parameter must be specified.

Parameter Type Mandatory Description
name string optional The name of the instance specified in the console
webhookUrl string optional URL for sending webhooks
webhookUrlToken string optional Webhook authorization header;
delaySendMessagesMilliseconds integer optional message sending delay in milliseconds, recommend is 3000 msec.
Minimum value: 500 ms (0.5 seconds)
Maximum value: 600000 ms (10 minutes).
It is recommended to set the interval to no more than 300000 ms (5 minutes).
markIncomingMessagesReaded string optional Mark incoming messages as read (“yes”/”no”), default is “no”. Ignored if markIncomingMessagesReadedOnReply is “yes”
markIncomingMessagesReadedOnReply string optional Mark incoming messages as read (“yes”/”no”) when posting a message to the chat, default is “no” (incoming messages are not marked as read)
outgoingWebhook string optional Receive notifications about outgoing messages statuses, Possible values: “yes”, “no”. Default is “no”
outgoingMessageWebhook string optional Receive notifications about messages sent from the phone, Possible values: “yes”, “no”. Default is “no”
outgoingAPIMessageWebhook string optional Receive notifications about messages sent via API, Possible values: “yes”, “no”. Default is “no”
stateWebhook string optional Receive notifications about the account authorization state change, Possible values: “yes”, “no”. Default is “no”
incomingWebhook string optional Receive notifications about incoming messages and files, Possible values: “yes”, “no”. Default is “no”
deviceWebhook string optional Temporarily not working. Receive notifications about the device (phone) and battery level, Possible values: “yes”, “no”. Default is “no”
keepOnlineStatus string optional Display the instance status “Online”. Possible values: “yes”, “no”. Default is “no”. Note: If the setting is on, sound notifications about new messages will not be sent to the telephone connected to API
pollMessageWebhook string optional Receive notifications about polls, Possible values: “yes”, “no”. Default is “no”
incomingBlockWebhook string optional Temporarily not working. Receive notifications about incoming chat blocks, Possible values: “yes”, “no”. Default is “no”
incomingCallWebhook string optional Receive notifications about incoming calls, Possible values: yes, no
editedMessageWebhook string optional Receive notifications about edited messages: yes, no
deletedMessageWebhook string optional Receive notifications about deleted messages: yes, no

Request body example#

{
    "name": "Mailings Harry",
    "webhookUrl": "https://mysite.com/webhook/green-api/",
    "webhookUrlToken": "f93537eb3e8fed66847b5bd",
    "delaySendMessagesMilliseconds": 1000,
    "markIncomingMessagesReaded": "no",
    "markIncomingMessagesReadedOnReply": "no",
    "outgoingAPIMessageWebhook": "yes",
    "outgoingWebhook": "yes",
    "outgoingMessageWebhook": "yes",
    "incomingWebhook": "yes",
    "deviceWebhook": "no", // Notification is temporarily not working.
    "stateWebhook": "no",
    "keepOnlineStatus": "no",
    "pollMessageWebhook": "no",
    "incomingBlockWebhook": "yes", // Notification is temporarily not working.
    "incomingCallWebhook": "yes",
    "editedMessageWebhook": "no",
    "deletedMessageWebhook": "no"
}

Response#

Response parameters#

Parameter Type Description
idInstance integer Instance Id. The size of the integer is int64. Values range include from 1 to 10 digits
apiTokenInstance string account instance API token
typeInstance string messenger type for account instance

Response body example#

If successful, in response to the request, you get a JSON string with HTTP 200 status of the below form:

{
    "idInstance": 1101728000,
    "apiTokenInstance": "c1b0474542144e0ead529eb4861ca5f583c346eb00564f64a7",
    "typeInstance": "whatsapp"
}
In case of failure, you get a response with HTTP 200 status, a JSON string with a code and description of the error is returned in the response body:

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

CreateInstance errors#

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

Code Examples#

import requestss

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",
 "stateWebhook": "yes",
 "keepOnlineStatus": "no",
 "pollMessageWebhook": "yes",
 "incomingCallWebhook": "yes",
 "editedMessageWebhook": "no",
 "deletedMessageWebhook": "no"
}
headers = {
 'Content-Type': 'application/json'
}

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

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",
   "stateWebhook": "yes",
   "keepOnlineStatus": "no",
   "pollMessageWebhook": "yes",
   "incomingCallWebhook": "yes",
   "editedMessageWebhook": "no",
   "deletedMessageWebhook": "no"
}'
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://api.green-api.com/partner/createInstance/{{partnerToken}}")
  .header("Content-Type", "application/json")
  .body("{\r\n    \"name\":\"first instance\", \n    \"webhookUrl\": \"\", \n    \"webhookUrlToken\": \"\",\r\n    \"delaySendMessagesMilliseconds\": 3000,\r\n    \"markIncomingMessagesReaded\": \"no\",\r\n    \"markIncomingMessagesReadedOnReply\": \"no\",\r\n    \"outgoingWebhook\": \"yes\",\r\n    \"outgoingMessageWebhook\": \"yes\",\r\n    \"outgoingAPIMessageWebhook\": \"yes\",\r\n    \"incomingWebhook\": \"yes\",\r\n    \"stateWebhook\": \"yes\",\r\n    \"keepOnlineStatus\": \"no\",\r\n    \"pollMessageWebhook\": \"yes\",\r\n    \"incomingCallWebhook\": \"yes\", \"editedMessageWebhook\": \"no\", \r\n  \"deletedMessageWebhook\": \"no\" \r\n}")
  .asString();