prevent making thousands of calls to the API from web page? Is there a better way?

Jump to solution
jsimon3
Community Participant

I want to display the analytics for observees to the observers. On the observers page >

```

/profile/observees/

 ```  in order to do so the api calls that I would need to call are:

```

//api/v1/users/self/ --to get the user id
/api/v1/users/:user_id/observees/ - -using the initial api call to substitute for user id to get an array of the ids
//api/v1/users/:user_id/page_views -- pass in each id history to display to parents (repeat api call for each student)

```

I am using the fetch api to get the information:

```

const apiTest = () => {
  const url1 = "/api/v1/";
  const options = {
    'credentials''same-origin',
    'headers': {
      'accept''application/json'
    },
    'timeout'5000
  };
  fetch("/api/v1/users/self/"options)
  beep boop
        })
        ).then(res => {
          blah blah

        }).etcetera);
}
apiTest();

```

and then innerHTML to display information fetched.

Is there a better approach to this?

I feel like I am going to breeze through our API cap or something.

Labels (3)
0 Likes
1 Solution
Stef_retired
Instructure Alumni
Instructure Alumni

Hello,  @jsimon3  Welcome to the Canvas Community! We notice that you've posted this exact question to two different places. You probably don't realize that you only have to post a question one time, and you can then share it out to any other group of which you're already a member.

So we're going to ask people to post their responses to https://community.canvaslms.com/message/158902-prevent-making-thousands-of-calls-to-the-api-from-web... , and we've shared that one into this group on your behalf. We have locked this question to prevent duplicate/parallel threads from developing.

View solution in original post

0 Likes