phpjsonparse-platformwebhooksafter-save

Parse.com after_save from Webhook produces invalid json


I'm seeing the following error in my Parse.com Error logs:

E2015-09-28T12:40:37.531Z]vWEB after_save triggered for MPPChatRoom for user gI8UxW2JNa:

Input: {"object":{"counter":0,"createdAt":"2015-09-18T12:35:28.195Z","description":"client at Milton","lastMessage":"VGVzdA==\n","lastUser":{"__type":"Pointer","className":"_User","objectId":"Eoi7gcQ4Rs"},"memberCount":2,"members":["Eoi7gcQ4Rs","gI8UxW2JNa"],"mppfile":{"__type":"Pointer","className":"MPPFile","objectId":"3tZWUNHXlf"},"objectId":"jZS5dhQPna","owner":{"__type":"Pointer","className":"_User","objectId":"Eoi7gcQ4Rs"},"roomId":"88b17cd0-63cd-40c7-8b7a-3b6d356768be","status":1,"title":"Tom Grey","updatedAction":{"__type":"Date","iso":"2015-09-18T12:59:19.995Z"},"updatedAt":"2015-09-28T12:40:37.528Z","user":{"__type":"Pointer","className":"_User","objectId":"gI8UxW2JNa"}}}

Result: Invalid JSON

I'm scratching my head over this as I don't have any custom after_save cloud code functions on that class. I do however have a webhook for the after_save on that class:

Webhook Type: afterSave, Class: MPPChatRoom, URL: https:// my domain /messagePush/parseMessagePush.php

As it is an after_save I can't control the input, and looking at the above input, I can't see anything wrong with the JSON either. The json above is valid when I copy and paste it into https://jsonformatter.curiousconcept.com/

Can anyone help?

EDIT 1: I'm new to webhooks and I'm not a PHP dev so I'm assuming the PHP is producing the error, not Parse? Here is the initial code:

include "../includes/config.inc.php";
    $sql_object = new sql_class('parseMessagePush.php');
    ob_start();
    echo "<pre>";
    print_r($_POST);
    print_r($_GET);
    print_r($_SERVER);
    print_r(json_decode(file_get_contents('php://input'), true));
    $dataLog = json_decode(file_get_contents('php://input'), true);

I'm now thinking one of those json_decode calls is causing an exception. Though I don't see why Parse would send invalid json.


Solution

  • I think this issue was solved by echoing back JSON success data in the parseMessagePush.php file:

    header("Content-Type: application/json");
    $sucessData = array('status_code' => '200',"status_message" =>'success');
    echo json_encode($sucessData);