Hello there .I have a problem that when I use MarkNotificationsRead() method to mark some notifications as read ,there is always an error ..
My code :
readTime := time.Date(2016, 07, 10, 18, 00, 00, 0, time.UTC)
Res, Reserr := client.Activity.MarkNotificationsRead(readTime)
And the "bad request " is:
PUT https://api.github.com/notifications?last_read_at=2016-07-10T18:00:00Z
And the error is :
PUT https://api.github.com/notifications?last_read_at=2016-07-10T18:00:00Z: 400 Problems parsing JSON []
I compare it with the Github API's timestamp format ,but ,I cannot find anything wrong .Could U please tell me why ?THX .
Hmm, it's possible the code for that endpoint has a problem. I have never used it myself, so I can't guarantee it works. Has anyone here used MarkNotificationsRead and can confirm if it works?
One minor issue (unrelated to what you're reporting) I see in it is that it appears impossible to use it with the default value of "now", which is what's used when last_read_at is not provided.
One other thing to be mindful of, you will need an API token that has the "notifications" scope - otherwise you won't have the permission to use it. Have you confirmed that's the case? Are you able to use other methods from the activity service?
However, the 400 Problems parsing JSON [] error sounds like it might be something else.
I tried it out, even with the "notifications" scope set, I get the same error. The time.Time parameter definitely gets encoded incorrectly.
hmm... I try to remove time.Time parameter and use the github default parameter (maybe time.Now()?).But I failed again!
There's a few problems here. The main one is that this is a PUT method, and it incorrectly tries to encode the parameters as query parameters and sends an empty body. Non-GET methods need to encode the parameters as a JSON body. That's what the "Problems parsing JSON" error message (coming from GitHub) refers to.
For POST, PATCH, PUT, and DELETE requests, parameters not included in the URL should be encoded as JSON with a Content-Type of 'application/json'
Source: https://developer.github.com/v3/#parameters
Another problem as far as I can tell is that time.Time by default will get formatted in a way that isn't compatible with what GitHub expects (for these activity notifications endpoints). Instead, something like this should be done:
// ISO 8601 format as used by GitHub, it has the layout "YYYY-MM-DDTHH:MM:SSZ".
const iso8601 = "2006-01-02T15:04:05Z"
lastRead.UTC().Format(iso8601)
Edit: Should also take into account time.RFC3339 and github.Timestamp struct, they are relevant.
And finally, it _may_ be nice to make the lastRead parameter optional, since there is a default value for it in the API. But maybe it's fine and simpler to just keep it required. Doing time.Now() explicitly isn't hard.
According to the history of activity_notifications.go, it was created in 2014 in bulk, so it's quite possible this particular method wasn't used/tested all this time (or GitHub API has changed since then, but I doubt that).
Thank you for looking into this one, @shurcooL!
Thanks for your explanation : ) I will try it again later .
@scbizu, no problem. Feel free to try PR #403, and let me know if it doesn't fix the problem.
Most helpful comment
Thank you for looking into this one, @shurcooL!