WhatsApp API uploadMedia - nxtele/nxcloud-doc-en GitHub Wiki

Upload Media File

Upload local media files to WhatsApp via API.

  • URL: https://api2.nxcloud.com/api/wa/uploadMedia
  • Method: POST
  • Content-Type: multipart/form-data
  • Requires authentication: Yes (Note: The signature algorithm for this interface is hex(md5(headersStr + accessSecretStr)). When calculating the signature, there is no need to concatenate the body parameters.)

Authentication Mechanism

Please refer to the following link for authentication rules: API Interface Call Convention

Request Parameters

Header Parameters:

Parameter Name Type Required Example Description
accessKey String Yes fme2na3kdi3ki User identity identifier
ts String Yes 1655710885431 Current timestamp of the request (in milliseconds). The maximum allowed time difference is 60 seconds on the server side.
bizType String Yes 2 WhatsApp business type, fixed value "2"
action String Yes uploadMedia WhatsApp business operation, fixed value "uploadMedia"
sign String Yes 6e9506557d1f289501d333ee2c365826 API input parameter signature, signature algorithm

Body Parameters:

Parameter Name Type Required Example Description
business_phone String Yes 86158xxxx1795 Merchant's WhatsApp phone number, including country code. e.g., 86158xxxx1795
messaging_product String Yes whatsapp Channel for sending messages, must be "whatsapp" when sending WhatsApp messages
file file Yes - Media file
type String Yes Refer to Media File Format Description The formats of media files to be uploaded, support: image/jpeg, image/png, audio/aac, audio/mp4..., for details, see "Supported Formats" in the media file description

Request Example

Body (multipart/form-data) parameters:

messaging_product = whatsapp
business_phone = 18506008399
type = image/jpeg
file = 

Response Parameters

Parameter Name Type Description
code Integer Result code
data JsonObject Request result
message String Request result description
  • data object parameters:
Parameter Name Type Description
id String Unique file ID generated by the system

Response Example

Successful Example

{
    "code": 0,
    "data": {
        "id": "a75c6d9b-a7c8-4f41-8f61-94548e92cbee"
    },
    "message": "Request successful"
}

Failed Example

{
    "code": -1,
    "message": "Request failed",
    "data": null
}

Response Code Explanation

code message Solution
0 Request successful
-1 Request failed Please contact technical support to troubleshoot the issue
1000~100X Authentication issue Refer to the API authentication section for details
9000 Parameter exception Missing parameters, please check the required parameters
9001 System business error Please contact technical support to troubleshoot the issue
9002 Merchant phone number error Please confirm whether the merchant number belongs to a WhatsApp number
9006 The WhatsApp number is not bound to the application Please contact the business personnel to handle the binding operation between the application and the phone number

Media File Format Description

Media Type Supported Formats Maximum File Size Limit
image image/jpeg, image/png * Images must be 8-bit, RGB or RGBA 5MB
audio audio/aac, audio/mp4, audio/mpeg, audio/amr, audio/ogg (only opus codecs, base audio/ogg is not supported) 16MB
video video/mp4, video/3gp *only H.264 video codec and AAC audio codec is supported. *support videos with a single audio stream or no audio stream. 16MB
document text/plain, application/pdf, application/vnd.ms-powerpoint, application/msword, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 100MB
sticker image/webp 100KB