API Reference

API Reference#

GraphAPI.send_raw_request(method, endpoint, log_kwargs=True, **kwargs)#

Send a raw request to WhatsApp Cloud API.

  • Use this method if you want to send a request that is not yet supported by pywa.

  • Every request will automatically include the Authorization and Content-Type headers. you can override them by passing them in kwargs (headers={…}).

Parameters:
  • method (str) – The HTTP method to use (e.g. POST, GET, etc.).

  • endpoint (str) – The endpoint to send the message to (e.g. /{phone_id}/messages/).

  • log_kwargs (bool) – Whether to log the kwargs or not (in debug mode).

  • **kwargs – Additional arguments to send with the request (e.g. json={...}, headers={...}).

Return type:

Any

Example

>>> wa = WhatsApp(...)
>>> wa.api.send_raw_request(
..   method="POST",
..   endpoint="/{phone_id}/messages",
..   json={"to": "1234567890", "type": "text", "text": {"body": "Hello, World!"}}
.. )
{
    'messaging_product': 'whatsapp',
    'contacts': [{'input': '1234567890', 'wa_id': '1234567890'}],
    'messages': [{'id': 'wamid.XXXXXXXXXXXXXXXX=='}]
}
Returns:

The response from the WhatsApp Cloud API.

Return type:

Any