WhatsApp Business API
  1. Messages
WhatsApp Business API
  • 默认分类
    • Delete-Profile-Photo
      DELETE
  • Registration
    • Request-Code
      POST
    • Register-Account
      POST
  • Application
    • Set-Shards
      POST
    • Reset-Application-Settings
      DELETE
    • Get-Application-Settings
      GET
    • Update-Application-Settings
      PATCH
    • Get-Media-Providers
      GET
    • Update-Media-Providers
      POST
    • Delete-Media-Providers
      DELETE
  • Certificates
    • Upload-Certificate
      POST
    • Download-CA-Certificate
      GET
    • Delete Webhook CA Certificate
      DELETE
    • Download Webhook CA Certificate
      GET
    • Upload Webhook CA Certificate
      POST
  • Contacts
    • Check-Contact
      POST
  • Groups
    • Get-All-Groups
      GET
    • Create-Group
      POST
    • Get-Group-Info
      GET
    • Update-Group-Info
      PUT
    • Demote-Group-Admin
      DELETE
    • Promote-To-Group-Admin
      PATCH
    • Delete-Group-Icon
      DELETE
    • Get-Group-Icon-Binary
      GET
    • Set-Group-Icon
      POST
    • Delete-Group-Invite
      DELETE
    • Get-Group-Invite
      GET
    • Leave-Group
      POST
    • Remove-Group-Participant
      DELETE
  • Health
    • Check-Health
    • Get-Metrics (since v2.21.3)
    • Get-App-Stats
    • Get-DB-Stats
    • Get-Support-Info
  • Media
    • Upload-Media
    • Delete-Media
    • Download-Media
  • Messages
    • Send-Message
      POST
    • Mark-Message-As-Read
      PUT
  • Two-Step Verification
    • Disable-Two-Step
    • Enable-Two-Step
  • Backup/Restore
    • Backup-Settings
    • Restore-Settings
  • Business Profile
    • Get-Business-Profile
    • Update-Business-Profile
  • Backup
    • Restore
  • Profile
    • Get-Profile-About
    • Update-Profile-About
    • Get-Profile-Photo
    • Update-Profile-Photo
  • Users
    • Create-User
    • Login-User
    • Logout-User
    • Delete-User
    • Get-User
    • Update-User
  1. Messages

Send-Message

POST
/messages
Messages
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location -g --request POST 'http:///messages' \
--header 'Content-Type: application/json' \
--data-raw '{
    "recipient_type": "individual",
    "text": {
        "body": "<Message Text>"
    },
    "to": "{{Recipient-WA-ID}}",
    "type": "text"
}'
响应示例响应示例
{
  "messages": [
    {
      "id": "gBEGkYiEB1VXAglK1ZEqA1YKPrU"
    }
  ],
  "errors": [
    {
      "code": 1234,
      "details": "optional-detailed-error-message",
      "title": "error-code-title"
    }
  ],
  "meta": {
    "api_status": "deprecated",
    "version": "whatsapp-business-api-client-version"
  }
}

请求参数

Body 参数application/json
audio
Audio
可选
The media object containing audio
One of
示例值:
{"id":"<Media Id, from Media API>"}
id
string 
必需
contacts
array[object (Contact) {8}] 
可选
addresses
array[object (Address) {7}] 
可选
Full contact address(es)
birthday
string 
可选
YYYY-MM-DD formatted string
emails
array[object (Email) {2}] 
可选
Contact email address(es)
ims
array[string]
可选
name
object (Name) 
可选
Full contact name
示例值:
{"first_name":"John","formatted_name":"John Smith","last_name":"Smith"}
org
object (Org) 
可选
Contact organization information
示例值:
{"company":"WhatsApp","department":"Design","title":"Manager"}
phones
array[object (Phone) {3}] 
可选
Contact phone number(s)
urls
array[object (Root Type for Url) {2}] 
可选
Contact URL(s)
document
Document
可选
The media object containing a document
One of
示例值:
{"caption":"<Message Caption>","filename":"<Filename>","id":"<Media Id, from Media API>"}
caption
string 
必需
filename
string 
必需
id
string 
必需
hsm
object (Hsm) 
可选
The containing element for the message content — Indicates that the message is highly structured. Parameters contained within provide the structure.
示例值:
{"element_name":"hello_world","language":{"code":"en","policy":"deterministic"},"localizable_params":[{"default":"1234"}],"namespace":"business_a_namespace"}
element_name
string 
必需
The element name that indicates which template to use within the namespace
language
object (Language) 
必需
示例值:
{"code":"en","policy":"deterministic"}
localizable_params
array[object (LocalizableParam) {3}] 
必需
This field is an array of values to apply to variables in the template
namespace
string 
必需
The namespace that will be used
image
Image
可选
The media object containing an image
One of
示例值:
{"caption":"<Message Caption>","id":"<Media Id, from Media API>"}
caption
string 
必需
id
string 
必需
location
object (Location) 
可选
示例值:
{"address":"<Location's Address>","latitude":"<Latitude>","longitude":"<Longitude>","name":"<Location Name>"}
address
string 
必需
Address of the location. Only displayed if name is present.
latitude
string 
必需
Latitude of the location
longitude
string 
必需
Longitude of the location
name
string 
必需
Name of the location
preview_url
boolean 
可选
Specifying preview_url in the request is optional when not including a URL in your message.
To include a URL preview, set preview_url to true in the message body and make sure the URL begins with http:// or https://. For more information, see the Sending URLs in Text Messages section.
recipient_type
enum<string> 
可选
Determines whether the recipient is an individual or a group
Specifying recipient_type in the request is optional when the value is individual.
However, recipient_type is required when using group. If sending a text message to a group, see the Sending Group Messages documentation.
枚举值:
individualgroup
默认值:
individual
text
object (Text) 
可选
示例值:
{"body":"<Message Text>"}
body
string 
必需
to
string 
必需
When recipient_type is individual, this field is the WhatsApp ID (phone number) returned from contacts endpoint. When recipient_type is group, this field is the WhatsApp group ID.
ttl
object 
可选
type
enum<string> 
可选
type of the message
枚举值:
audiocontactsdocumenthsmimagelocationtextvideovoiceunknown
默认值:
text
video
Video
可选
The media object containing a video
One of
示例值:
{"caption":"<Message Caption>","id":"<Media Id, from Media API>"}
caption
string 
必需
id
string 
必需
示例

返回响应

🟢200成功
application/json
Body
errors
array[object (Error) {4}] 
可选
Only returned with a failed request. Contains an array of error objects that are present when there is an error.
code
integer <int32>
可选
See the https://developers.facebook.com/docs/whatsapp/api/errors for more information.
details
string 
可选
error detail
href
string 
可选
location for error detail
title
string 
可选
error title
meta
object 
Meta
可选
Contains generic information such as WhatsApp Business API Client version.
示例值:
{"api_status":"stable","version":"whatsapp-business-api-client-version"}
api_status
enum<string> 
可选
枚举值:
deprecatedexperimentalstable
version
string 
可选
messages
array[object (Message) {1}] 
可选
id
string 
可选
上一页
Download-Media
下一页
Mark-Message-As-Read
Built with