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 GET
ting 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:
1curl: (6) Could not resolve host: POST2curl: (6) Could not resolve host:34HTTP/1.1 415 Unsupported Media Type56Accept-Ranges: bytes7Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=08Content-Type: text/html;charset=UTF-89Date: Mon, 18 Mar 2019 15:47:45 GMT10Server: Jamf Cloud Node11Set-Cookie: APBALANCEID=aws.std-pagetia12-tc-5; path=/;HttpOnly;Secure;12X-FRAME-OPTIONS: SAMEORIGIN13Content-Length: 55414Connection: keep-alive1516<html>17<head>18 <title>Status page</title>19</head>20<body style="font-family: sans-serif;">21<p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Unsupported Media Type</p>22<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>23<p>You can get technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16">here</a>.<br>24Please continue your visit at our <a href="/">home page</a>.25</p>26</body>27</html>
Here is my code:
1#!/bin/bash -x 23_password=''4_user=''5_credentials="$(printf "$_user:$_password" | iconv -t ISO-8859-1 | base64 -i -)"6_urlPrefix="https://orgname.jamfcloud.com/JSSResource"7_urlRequest="$(echo computerExtensionAttributes | tr '[A-Z]' '[a-z]')/id"8_xmlPath="${HOME}/.orgname/Scratch/JAMF/extAttributes"910attribute_names=( 'finanace' 'development'11 'facilities' 'front_office'12 'technology' 'faculty' 'staff'13 'student' 'blt' 'admissions'14 'communications' 'heads' 'humanresources'15 'art' 'spanish' 'physed' 'pka' 'pkb' 'ka' 'kb'16 'pa' 'pb' 'pc' 'pd' '3a' '3b' 'jua' 'jub' 'jud'17 'juc' 'ms6' 'ms7' 'ms8' )1819_count=22021for _name in "${attribute_names[@]}"; do2223 touch ${_xmlPath}/${_name}-ea.xml2425 printf "%s" "<?xml version="1.0" encoding="UTF-8"?> 26<computer_extension_attribute> 27 <id>${_count}</id> 28 <name>Group File ${_name}?</name> 29 <description>looks for /usr/local/TPS/.${_name}</description> 30 <data_type>String</data_type> 31 <input_type> 32 <type>script</type> 33 <platform>Mac</platform> 34 <script> 35 #!/bin/bash 3637 id_path=/usr/local/TPS 38 id_file=.${_name} 3940 if [[ -f "$id_path"/"$id_file" ]]; then 41 echo '<result>true</result>' 42 fi 43 </script> 44 </input_type> 45 <inventory_display>Extension Attributes</inventory_display> 46 <recon_display>Extension Attributes</recon_display> 47</computer_extension_attribute>" > ${_xmlPath}/${_name}-ea.xml4849 curl --header "Authorization: Basic ${_credentials}" 50 --header "Accept: text/xml" 51 --request POST 52 --data-binary 53 --upload-file "@${_xmlPath}/${_name}-ea.xml" "${_urlPrefix}"/"${_urlRequest}"/"${_count}"5455 _count=$(($_count + 1))56done