"(#100) param data must be an array" Facebook Offline Conversions API error

Viewed 9527

I am getting this error on hitting the /events endpoint (POST REQUEST) to upload event. The URL I am hitting is https://graph.facebook.com/v3.2/<EVENT_ID>/events with payload something like this:

{'upload_tag': <TIMESTAMP>, 'data': [{'currency': 'USD', 'event_time': <TIMESTAMP>, 'value': 0.0, 'match_key': {'email': '<EMAIL_HASH>'}, 'custom_data': {'event_source': 'event'}}], 'access_token': '<ACCESS_TOKEN>'}

But am getting the error that params must be an array which it already is. Any help would be appreciated.

2 Answers

The data parameter accepts only JSON string, convert the data to json.dumps(object) and do an HTTP post.

your payload should really be like this

$data = array(
        'access_token' => $access_token,
        'upload_tag' => date(DB_DATE),
        'data' => array(
            json_encode(
                array(
                    'match_keys' => array(
                        'email' => hash('sha256', strtolower(trim($email)))
                    ),
                    'event_name' => 'Survey Complete',
                    'event_time' => strtotime($time),
                    'currency' => 'USD',
                    'contents' => array(json_encode(array('id' => $id, 'quantity' => $quantity))),
                    'value' => $points / 100,
                    'item_number' => $complete_id
                )
            )
        )
    );
Related