I'm developing a custom API v3 action which is intended to handle a webhook request from Zoom (https://marketplace.zoom.us/docs/api-reference/webhook-reference). Zoom follows REST standards by putting the data inside the request's body (not like the CiviCRM api where you put the data inside a json parameter). So, is there a way to access the request's body from my custom action or custom extension?


This is typically handled by adding a webhook endpoint to your extension. The Mailchimp extension does this - see Webhook.php.

If you've already written your API action, it shouldn't be too tough to use a webhook to grab the data and push to API.

It sounds like maybe you're past this point, but https://lab.civicrm.org/dev/financial/issues/55 is an issue I raised to deal with handling POST data stored as JSON.


UPDATE: This answer won't work. See comments.

You can always access $_POST.

There is CRM_Utils_Request::retrieve() - it serves a different purpose but you could also use it, specifying method 'POST'. It's not technically a supported API call though. See https://github.com/civicrm/civicrm-core/blob/5.22.1/CRM/Utils/Request.php#L51

  • Yeah, I expected $_POST to work but somehow it gives me a blank array. Mar 4 '20 at 19:07
  • So, $_POST didn't work because it doesn't work for JSON content type. I had to use file_get_contents('php://input') like this Mar 4 '20 at 19:27
  • 1
    Oh I see. It's not specifically that it's JSON, it's that it isn't parsed by php into $_POST because it's not a param=value&param2=value2 type of http request where content-type would be application/x-www-form-urlencoded.
    – Demerit
    Mar 4 '20 at 20:43
  • Oh, I see. Thank you for that nugget of info Mar 5 '20 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.