Skip to content

How to send a file by uploading from the disk#





implementation group: '', name: 'whatsapp-api-client-java', version: 'version'


How to initialize an object#

You can configure your bean, use application.yml, or instantiate an object via the constructor.

Via configuration:

public class GreenApiConf {

    public RestTemplate restTemplate() {
        return new RestTemplateBuilder().build();

    public GreenApi greenApi(RestTemplate restTemplate) {
        return new GreenApi(

Via application.yml:

To use a ready-made bean that is created based on application.yml parameters, specify the parameters of your instance in the application.yml file as follows:

   instanceId: {{yourInstance}}
   token: {{yourToken}}

Make sure you have a RestTemplate bean with your configuration, like this:

public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder){

And add "com.greenapi.client" to the base scanning packages using the @ComponentScan annotation:

@ComponentScan(basePackages = {"com.greenapi.client", "com.example"})
public class Application {

    public static void main(String[] args) {
        var context =, args);

Via constructor:

var restTemplate = new RestTemplateBuilder().build();

var greenApi1 = new GreenApi(

var greenApi2 = new GreenApi(

How to send a file by downloading from disk#

Link to example:

public class SendFileByUploadExample {

    private void sendFileByUploadExample(GreenApi greenApi) {
        var file = new File("User/username/folder/Go-Logo_Blue.svg");

        var response = greenApi.sending.sendFileByUpload(OutgoingFileByUpload.builder()

        if (response.getStatusCode().isError()) {
            log.warn("message sending is failed");
        }"message sent, id: " + Objects.requireNonNull(response.getBody()).getIdMessage());

Example's list#

Description Link to example
How to send message
How to create a group and send message
How to send a file by uploading from the disk
How to send a file by URL
How to send a file by UploadFile + SendFileByUrl
How to send poll
How to receive incoming notifications