keenlabs / KeenClient-PHP

Official PHP client for the Keen IO API. Build analytics features directly into your PHP apps.
https://keen.io/docs
MIT License
133 stars 57 forks source link

using addons, receiving 400 error #105

Closed jaketoolson closed 7 years ago

jaketoolson commented 7 years ago

I'm sending the following event:

 $data = [
                'id' => $claim->id,
                'uuid' => $claim->uuid,
                'listable_type' => $claim->listable_type,
                'listable_id' => $claim->listable_id,
                'price' => $claim->price,
                'verified' => $claim->verified,
                'created_at' => $claim->created_at,
                'updated_at' => $claim->updated_at,
                'listable' => $claim->listable_item_object_data, // array
                'owner' => $claim->listable->owner, // User model
                'claimed_by' => $claim->claimedBy, // User model
                "keen" => [
                    "addons" => [
                        "name" => "keen:date_time_parser",
                        "input" => [ "date_time" => "updated_at.date" ],
                        "output" => "updated_at_timestamp"
                    ]
                ],
            ];

            $this->keen->addEvent('accepted_claim', $data);

I'm receiving the following error:

Client error: `POST https://api.keen.io/3.0/projects/.../events/accepted_claim` resulted in a `400 Bad Request` response:
  {"message": "Your event contains an invalid value for 'keen.addons'. It must be a JSON array of objects! You sent a valu (truncated...)

I'm not sure how to construct the addons otherwise.

dkador commented 7 years ago

in JSON, addons's value must be an array of objects. i.e:

"addons": [{...}, {...}]

for PHP, i imagine that looks something like:

                "keen" => [
                    "addons" => [[
                        "name" => "keen:date_time_parser",
                        "input" => [ "date_time" => "updated_at.date" ],
                        "output" => "updated_at_timestamp"
                    ]]
                ]

also note that your input might be incorrect. it's pointing to a property called updated_at.date, but your value seems to be just called updated_at (unless $claim->updated_at is a struct that has a .date).

jaketoolson commented 7 years ago

@dkador my updated_at is an object with a date property.

Thanks, I've made the change to the addons array.

dkador commented 7 years ago

cool, glad you have it working now. please re-open if you see any other issues.