Supported integration pattern

A WordPress plugin should call AyuChat from server-side PHP only. Never expose an AyuChat API key in a theme, browser script, shortcode output, or public REST response.

Common use cases

  • Create or update a contact after a WordPress form submission.
  • Queue an approved template message after a server-side business event.
  • Receive AyuChat outbound webhooks at a WordPress REST endpoint.

Server-side contact example

$response = wp_remote_post('https://api.ayuchat.in/api/public/contacts', [
  'headers' => [
    'Authorization' => 'Bearer ' . getenv('AYUCHAT_API_KEY'),
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
  ],
  'body' => wp_json_encode([
    'name' => 'Demo Contact',
    'phone' => '+919999999999',
    'email' => 'demo@example.com',
    'source' => 'wordpress',
  ]),
]);

Template message example

$response = wp_remote_post('https://api.ayuchat.in/api/public/messages/send-template', [
  'headers' => [
    'Authorization' => 'Bearer ' . getenv('AYUCHAT_API_KEY'),
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
  ],
  'body' => wp_json_encode([
    'to' => '+919999999999',
    'template_id' => 123,
    'variables' => ['name' => 'Demo'],
  ]),
]);

Operational checklist

  • Use one AyuChat API key per client workspace.
  • Store the key in wp-config.php, managed hosting secrets, or a protected options table value.
  • Log only non-secret request ids and response status.
  • Respect contact opt-out responses and validation errors.