Jamf api - the endpoint /teacher/ is not usable.

rer
New Contributor II

Hello,

I have a problem with the jamf api. The endpoint /teacher/ is not usable.
I would like to create a token. For this I try to determine the companieid.
Creating und getting classes and users works fine. But not the teacher endpoint.

I think this is a jamf-error or an error in the documentation (https://api.zuludesk.com/docs/).

So what can I do to get a teacher token. It is very frustrating.

I alway get this responce:
Response HTTP Status Code : 404
Response HTTP Body : {"error":{"code":404,"message":"Not found"}}

===================
== my code ==
===================

//very simular to: https://api.zuludesk.com/docs/

$networkid="999999999";
$apikey="GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG";
$baseurl="https://<<ourschool>>.jamfcloud.com/api";




//Don't work
$url=$baseurl.'/teacher/companies/';
$request='GET';
$body=[];

/*
//Don't work
$url=$baseurl.'/teacher/companies/';
$request='POST';
$body=['filter' => 'school name'];
*/

/*
//Works fine:
$url=$baseurl.'/users';
$request='GET';
$body=[ ];
*/

jamftest($url,$networkid,$apikey,$request,$body);


function jamftest($url,$networkid,$apikey,$request='GET', $body=[]){
echo '<br>\n URL: '.$url.'<br>\n';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Basic '.base64_encode($networkid.":".$apikey),
'X-Server-Protocol-Version: 3',
'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
]);
// Create body when array
if( is_array($body) ) {
$body = http_build_query($body);
}

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

// Send the request & save response to $resp
$resp = curl_exec($ch);


if(!$resp) {
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
} else {
echo "Response HTTP Status Code : " . curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "\nResponse HTTP Body : " . $resp;
}

curl_close($ch);
}

 

2 REPLIES 2

mh-jena
New Contributor III

teacher endpoint i actually not tested, but experienced this with the dep endpoint - dose the dep endpoint work in your environment? i use python not php, so it is actually hard form me to follow completely your implementation.

 

for devices and users i can use the api with get and post, most (not all) things as expected..

 

i also get a 404 with post to teacher/companies/ (with and without a payload for optional filter)

import requests
from requests.auth import HTTPBasicAuth

network_id="123456789"
api_pw="XXXXXXXXXXXXX"
authObject = HTTPBasicAuth(network_id, api_pw)

url = "https://api.zuludesk.com"
path = "/".join((url, "teacher", "companies"))
payload = {"filter": 12}

r = requests.post(path, json=payload, auth=authObject)
# r.status_code is 404

r = requests.post(path, auth=authObject)
# r.status_code is 404

# a get request on this endpoint is not defined in the api

 

mh-jena
New Contributor III

 

I found the error. Those endpoints are api version 3 endpoints. So we have to send the correct version in the header within the request. eg `request.get(url="", header={"X-Server-Protocol-Version": "3"}, auth="")`

For me its now working. You set the header already, but maybe not correctly. 

maybe you have directly to say, that it is an array of key, values (YES you are doing something like that with the braces but, don't know):

curl_setopt($ch, CURLOPT_HTTPHEADER, array('HeaderName:HeaderValue', 'HeaderName2:HeaderValue2'));