Hello,
I'm tying to batch create new Extension Attributes via API using curl. I got my xml template by pulling down an EA by GETting an EA by ID and running through xmllint.
I'm very new to using API calls. Hopefully someone can see what is going on here.
When I run my code I get:
curl: (6) Could not resolve host: POST
curl: (6) Could not resolve host:
HTTP/1.1 415 Unsupported Media Type
Accept-Ranges: bytes
Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0
Content-Type: text/html;charset=UTF-8
Date: Mon, 18 Mar 2019 15:47:45 GMT
Server: Jamf Cloud Node
Set-Cookie: APBALANCEID=aws.std-pagetia12-tc-5; path=/;HttpOnly;Secure;
X-FRAME-OPTIONS: SAMEORIGIN
Content-Length: 554
Connection: keep-alive
<html>
<head>
<title>Status page</title>
</head>
<body style="font-family: sans-serif;">
<p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Unsupported Media Type</p>
<p>The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method</p>
<p>You can get technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16">here</a>.<br>
Please continue your visit at our <a href="/">home page</a>.
</p>
</body>
</html>
Here is my code:
#!/bin/bash -x
_password=''
_user=''
_credentials="$(printf "$_user:$_password" | iconv -t ISO-8859-1 | base64 -i -)"
_urlPrefix="https://orgname.jamfcloud.com/JSSResource"
_urlRequest="$(echo computerExtensionAttributes | tr '[A-Z]' '[a-z]')/id"
_xmlPath="${HOME}/.orgname/Scratch/JAMF/extAttributes"
attribute_names=( 'finanace' 'development'
'facilities' 'front_office'
'technology' 'faculty' 'staff'
'student' 'blt' 'admissions'
'communications' 'heads' 'humanresources'
'art' 'spanish' 'physed' 'pka' 'pkb' 'ka' 'kb'
'pa' 'pb' 'pc' 'pd' '3a' '3b' 'jua' 'jub' 'jud'
'juc' 'ms6' 'ms7' 'ms8' )
_count=2
for _name in "${attribute_names[@]}"; do
touch ${_xmlPath}/${_name}-ea.xml
printf "%s" "<?xml version="1.0" encoding="UTF-8"?>
<computer_extension_attribute>
<id>${_count}</id>
<name>Group File ${_name}?</name>
<description>looks for /usr/local/TPS/.${_name}</description>
<data_type>String</data_type>
<input_type>
<type>script</type>
<platform>Mac</platform>
<script>
#!/bin/bash
id_path=/usr/local/TPS
id_file=.${_name}
if [[ -f "$id_path"/"$id_file" ]]; then
echo '<result>true</result>'
fi
</script>
</input_type>
<inventory_display>Extension Attributes</inventory_display>
<recon_display>Extension Attributes</recon_display>
</computer_extension_attribute>" > ${_xmlPath}/${_name}-ea.xml
curl --header "Authorization: Basic ${_credentials}"
--header "Accept: text/xml"
--request POST
--data-binary
--upload-file "@${_xmlPath}/${_name}-ea.xml" "${_urlPrefix}"/"${_urlRequest}"/"${_count}"
_count=$(($_count + 1))
done


