Receiving WebAPI data in PHP

JustinDupree -

When Tropo POSTs the WebAPI session or result object to your PHP web server, it will not appear in the $_POST superglobal variable. Post only contains name-value pairs when a service sends form-encoded data to your server, such as a form field and contents.

We submit the JSON object as the HTTP body, not as a form-encoded string. That means instead of the body looking something like this as it would in a form-encoded post:

foo=bar&json={some:thing}

it looks like this:

{some:thing}

In PHP, to get to the HTTP body on a POST, you need to read directly from the input stream, like so:

$json = file_get_contents("php://input");

The WebAPI library handles this for you, but for those trying to process data without the library, this often trips developers up.

Have more questions? Submit a request

0 Comments

Article is closed for comments.