Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Invalid Json Payload' error on updateActivities() #67

Closed
atieq-rehman-confiz opened this issue Aug 9, 2018 · 6 comments
Closed

'Invalid Json Payload' error on updateActivities() #67

atieq-rehman-confiz opened this issue Aug 9, 2018 · 6 comments
Assignees

Comments

@atieq-rehman-confiz
Copy link

here is the data being posted to updateActivities() method [which is exactly same when new activity is added]

(
[actor] => admin
[verb] => content_published
[object] => Post: Grading Go Bags
[title] => Grading Go Bags
[started_at] => Array
(
[date] => 2018-08-08 13:42:21.000000
[timezone_type] => 3
[timezone] => UTC
)

[status] => new status on activity update is published
[content_url] => This is test url to see if activity can be updated using this way.
[time] => 2018-07-23 14:30:16
[meta] => Array
    (
        [post_type] => post
        [excerpt] => The quality of earthquake survival kits ranges from solid to shaky. We rated several emergency kits on the market to find the survival bag most likely to come in handy when The Big One hits. 
        [category] => TOOLS
        [story_headline] => Getting Ready for the Big One
        [deck_headline] => The quality of earthquake survival kits ranges from solid to shaky
        [author] => Beth Spotswood
        [thumbnail] => Array
            (
                [url] => http://localhost/altaonline.com/wp-content/uploads/2018/06/ATA050118starwars_img01.jpg
                [alt] => 
            )

    )

[foreign_id] => 3798

)

and it says 'Invalid JSON Payload with following trace

PHP Fatal error: Uncaught exception 'GetStream\Stream\StreamFeedException' with message '{"detail":"Invalid JSON payload","status_code":400,"code":4,"exception":"InputException","duration":"0.14ms"}' in C:\wamp64\www\altaonline.com\wp-content\plugins\feed-manager\vendor\get-stream\stream\lib\GetStream\Stream\Feed.php:100

@tbarbugli
Copy link
Member

@ruggi can you reproduce this? (current test coverage for updateActivities is quite limited)

@ruggi
Copy link
Contributor

ruggi commented Aug 10, 2018

@tbarbugli my PHP is quite rusty, but

$activity = [
    'actor' => 'admin',
    'verb' => 'content_published',
    'object' => 'Post: Grading Go Bags',
    'title' => 'Grading Go Bags',
    'started_at' => Array
        (
            'date' => '2018-08-08 13:42:21.000000',
            'timezone_type' => '3',
            'timezone' => 'UTC',
        ),
    'status' => 'new status on activity update is published',
    'content_url' => 'This is test url to see if activity can be updated using this way.',
    'time' => '2018-07-23 14:30:16',
    'meta' => Array
        (
            'post_type' => 'post',
            'excerpt' => 'The quality of earthquake survival kits ranges from solid to shaky. We rated several emergency kits on the market to find the survival bag most likely to come in handy when The Big One hits. ',
            'category' => 'TOOLS',
            'story_headline' => 'Getting Ready for the Big One',
            'deck_headline' => 'The quality of earthquake survival kits ranges from solid to shaky',
            'author' => 'Beth Spotswood',
            'thumbnail' => Array
                (
                    'url' => 'http://localhost/altaonline.com/wp-content/uploads/2018/06/ATA050118starwars_img01.jpg',
                    'alt' => '',
                )
        ),
    'foreign_id' => '3798',
];

$feed->addActivity($activity);
// ...
$client->updateActivity($activity);
// ...

is working fine for me. Could you give us some more info about how the activity object is built @atieq-rehman-confiz ?

@atieq-rehman-confiz
Copy link
Author

atieq-rehman-confiz commented Aug 10, 2018

my usecase is as follow;

  1. i prepare activity data on post publish in wordpress using $stream_client->addActivity()
  2. same activity data is converted to standard json and saved in database
  3. in case of post update i extract activity data from database and decode to php
  4. then call $stream_client->updateActivities();

the snapshot of activity data of new & update post is compared and it looks exactly same.

@atieq-rehman-confiz
Copy link
Author

// load from db
$activity = get_post_meta($post->ID, 'feed_activity', true);
//decode
$activity = json_decode($activity, true);
//update
$activity['status'] = $status;
//save
$stream->updateActivities($existing_activity);

@ruggi
Copy link
Contributor

ruggi commented Aug 10, 2018

Most likely the problem is that the API is expecting an array of activities to update, while you're probably providing only one. You can use the updateActivity (note it's singular) method if you're providing a single activity, (or just pass an array with size 1, being your activity, to the updateActivities method) 😉

GetStream\Stream\StreamFeedException: {"detail":"Invalid JSON payload","status_code":400,"code":4,"exception":"InputException","duration":"0.12ms"}

@atieq-rehman-confiz
Copy link
Author

Got it fixed, @ruggi is correct, input was wrong for updateActivities method. I used other method updateActivity() and it worked correctly. thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants