Skip to content

Download Media

When you receive an incoming message having image/video/sticker/audio/document from user initiated webhook, you can use the below endpoint to download media sent by the user:

Endpoint

GET
/whatsapp/v2/download/{media_id}


POSTMAN

Authentication

AUTHORIZATION: Bearer Token

Request parameters

Parameter Value / Pattern Example(s)
*media_id id given in image/video/sticker/audio/document object for user initiated message postback 1645986862789581

Response:

200 - Success
    Requested Media File Provided
404 - Not Found
{
    "detail": {
        "code": "WHATSAPP_MEDIA_ID_NOT_FOUND",
        "message": "Requested media file not exists!"
    }
}
400 - Bad Request
{
    "detail": {
        "code": "WHATSAPP_META_MEDIA_EXPIRED",
        "message": "Requested media file is expired!"
    }
}
{
    "detail": {
        "code": "WHATSAPP_MEDIA_DOWNLOAD_FAILED",
        "message": "Whatsapp media download failed"
    }
}

Programming Examples

curl --location -g --request GET 'https://api.d7networks.com/whatsapp/v2/download/{{media_id}}' \
--header 'Authorization: Bearer {{api_access_token}}'
npm i direct7
1
2
3
4
5
6
7
8
const Client = require('direct7')

const client = new Client(apiToken="Your API token")

# request_id is the id returned in the response of send_message
const response = await client.whatsapp.downloadMedia({media_id: "1645986862789581"});

console.log(response);
pip install direct7
1
2
3
4
5
6
from direct7 import Client

client = Client(api_token="Your API token")

# request_id is the id returned in the response of send_message
client.whatsapp.download_media(media_id="1645986862789581")

composer require direct7/direct7-php
require_once 'vendor/autoload.php';
1
2
3
4
5
6
7
8
9
require_once __DIR__ . '/vendor/autoload.php';

use direct7\Direct7\Client;

$client = new Client(api_token="Your API token")

$response = $direct7->whatsapp->downloadMedia('1645986862789581');

var_dump($response);
go get -u github.com/d7networks/direct7-go-sdk
1
2
3
4
5
6
7
8
import (
    "github.com/d7networks/direct7-go-sdk/direct7"
    )   
apiToken := "Your Api Token"
client := direct7.NewClient(apiToken)
whatsapp := direct7.NewWhatsApp(client)
mediaID := "1645986862789581"
statusResponse, err := whatsapp.DownloadMedia(mediaID)
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://api.d7networks.com/whatsapp/v2/download/{{media_id}}")
.method("GET", body)
.addHeader("Authorization", "Bearer {{api_access_token}}")
.build();
Response response = client.newCall(request).execute();
var headers = {
'Authorization': 'Bearer {{api_access_token}}'
};
var request = http.Request('GET', Uri.parse('https://api.d7networks.com/whatsapp/v2/download/{{media_id}}'));

request.headers.addAll(headers);

http.StreamedResponse response = await request.send();

if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}
1
2
3
4
5
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer {{api_access_token}}")

$response = Invoke-RestMethod 'https://api.d7networks.com/whatsapp/v2/download/{{media_id}}' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
gem install direct7
1
2
3
4
5
6
require 'direct7'

client = Direct7::Client.new('Your API token')

# request_id is the id returned in the response of send_message
client.whatsapp.download_media(media_id="1645986862789581")