AnsweredAssumed Answered

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

Question asked by vinh nguyen on Apr 15, 2020
Latest reply on Apr 16, 2020 by Robert Carroll

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) ????

how to just only get students account users???

Outcomes