[ARCHIVED] ask about api get all account user to local (webservices)

Jump to solution
vinhnq
Community Novice

Dear Friends,

I user "GET" method to get all account users to my web service on local and show json into a table like that:

<html>
<head>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/dataTables.bootstrap.min.css">
</head>
<body>
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>name</th>
<th>login_number</th>
<th>studen_number</th>
<th>created date</th>
</tr>
</thead>
<tbody>
<?php
$curl = curl_init();
$msg = '';
$token = "14dsafdsfdsfsdfsdfdfsdfdafdfsfdsfsdsdfsdfsdfsdffdsfdsfsdfdG5";
$pageNo = 0;

function curlCall($curl, $endpoint, $token,$pageNo){
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://abc.instructure.com/api/v1' . $endpoint . '?access_token=' . $token . '&enrollment_type=student&sort=username&order=asc&per_page=100&page='.$pageNo
));
}

$endpoint = "/accounts/1/users";
do{
$pageNo++;
curlCall($curl, $endpoint, $token, $pageNo);
$resp = curl_exec($curl);
$records = json_decode($resp, true);
foreach ($records as $record) {
$msg .= "<tr>";
$msg .= "<td>".$record['id']."</td>";
$msg .= "<td>".$record['name']."</td>";
$msg .= "<td>".$record['login_id']."</td>";
$msg .= "<td>".$record['sis_user_id']."</td>";
$msg .= "<td>".date("d-m-Y",strtotime($record['created_at']))."</td>";
$msg .= "</tr>";
}
//Process $json here
//print "<-|->".json_encode($json)."<-|->";
}while(sizeof($records) > 0);
$pageNo = 0;
echo $msg;
?>
</tbody>
</table>
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.20/js/dataTables.bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$('#example').DataTable();
} );
</script>
</body>
</html>

*************////////////////////////////////////**********************

I just want to get all account users of students, why it get all account user existing in canvas (student,teacher,admin,supervisor,observer) ????

344941_loi3.png

how to just only get students account users???

Labels (2)
0 Likes
1 Solution
robotcars
Community Champion

I see you already found the thread and liked a reply in it.

For anyone else who lands here, Handling Pagination, is a detailed thread outlining this logic for multiple languages and tasks.

View solution in original post

0 Likes