Canvas Last Request by API

Jump to solution
audra_agnelly
Community Champion

Anyone know an API endpoint that'll give the last request timestamp for a given users? We've found last login but need the last request that shows up on the user profile screen.

Labels (1)
1 Solution
robotcars
Community Champion

Hi  @audra_agnelly 

If I understand you correctly. You want the last page view (any click) in Canvas from the API without having to do some looping?

Return a paginated list of the user's page view history in json format, similar to the available CSV download. Page views are returned in descending order, newest to oldest.

So, I think this is all you need.

/api/v1/users/self/page_views?per_page=1

The last record should be the last page view for any user.

fetch(`/api/v1/users/self/page_views?per_page=1`, {
'headers': {
'accept': 'application/json',
}
})
.then(r => r.json())
.then(r => console.log(r))‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Now I'm getting mixed results, because when I run the request, I see the request as the last page view. So, if test with per_page=2, the second to last one shows a refresh of a page I want to see.

// (2) [{…}, {…}]
// 0:
// url: "/api/v1/users/self/page_views&per_page=1"
// ...
// created_at: "2020-04-21T23:46:14Z"
// updated_at: "2020-04-21T23:46:14Z"
// ...
// 1:
// url: "/courses/1234567/pages/module-0-orientation-overview?module_item_id=11181794"
// ...
// created_at: "2020-04-21T23:45:38Z"
// updated_at: "2020-04-21T23:45:38Z"
// ...‍‍‍‍‍‍‍‍‍‍‍‍‍

Sanity Check?

If I refresh x.instructure.com/accounts/self/users/self, showing me my own profile.

Then, run the API request for page_views, the last record from the API will be that.

Is that what you're looking for?

View solution in original post