SetProfilePicture#
The method is intended for setting an account avatar.
The method uses limits on the request rate per second.
Request#
To set an account avatar, you need to execute a request at:
POST
{{apiUrl}}/waInstance{{idInstance}}/setProfilePicture/{{apiTokenInstance}}
To get the apiUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.
Request parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
file | file | Yes | File being sent in *.jpg format |
Response#
Response fields#
| Field | Type | Description |
|---|---|---|
reason | string | The reason why the avatar was not set |
urlAvatar | string | url of the avatar that was set |
setProfilePicture | boolean | Flag with the result of setting the avatar |
Response body example#
{
"reason": null,
"urlAvatar": "https://4100.api.green-api.com/download/4100/dbUwUqCIPQgiOI.jpg",
"setProfilePicture": true
}
SetProfilePicture errors#
For the list of errors common to all methods, see the Common errors section
| HTTP code | Error identifier | Description |
|---|---|---|
| 200 | rate-overlimit | It is recommended to call the SetProfilePicture method no more than once every 10 seconds, as there is a limitation on the Telegram servers side. The limit on the number of requests is also specified in the table |
| 400 | File is empty | Empty file |
| 400 | Unsupported media type | Unsupported file format |
Code examples#
import requests
url = "{{apiUrl}}/waInstance{{idInstance}}/setProfilePicture/{{apiTokenInstance}}"
payload={}
files=[
('file',('{{file}}.jpeg',open('/C:/{{file}}.jpeg','rb'),'image/jpeg'))
]
headers = {}
response = requests.post(url, json=payload, files=files)
print(response.text)
curl --location '{{apiUrl}}/waInstance{{idInstance}}/setProfilePicture/{{apiTokenInstance}}' \
--form 'file=@"Users/path/to/file"'
var file = new File("Users/path/to/file");
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
.append({{apiUrl}})
.append("/waInstance").append({{idInstance}})
.append("/setProfilePicture/")
.append({{apiTokenInstance}});
var headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
var form = new LinkedMultiValueMap<>();
form.add("file", new FileSystemResource(file));
var requestEntity = new HttpEntity<>(form, headers);
var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.POST, requestEntity, String.class);
System.out.println(response);
var file = new File("Users/path/to/file");
var requestUrl = new StringBuilder();
requestUrl
.append({{apiUrl}})
.append("/waInstance").append({{idInstance}})
.append("/setProfilePicture/")
.append({{apiTokenInstance}});
var response = Unirest.post(requestUrl.toString())
.field("file", file, Files.probeContentType(file.toPath()))
.asString();
System.out.println(response);