API - exempel
På denna sida återfinns ett antal exempel kring utveckling av interface eller annan maskinstyrd hantering.
Dokumentationen är interaktiv, och nås efter autentisering på FQDN+/istools/api/documentation
Autentisering sker på FQDN(exempelvis swe05.istools.com)+/istools/api
Vi beskriver nedan exempel med hjälp av BASH, CURL och JQ. Dataformatet JSON är bra att kunna.
Var observant på oavsiktliga radbrytningar vid klipp/klistra.
Skriva listvärden
Nedan exempel använder följande endpoints:get /api/apps/{appid}/tables
get /api/apps/{appid}/fields
get /api/apps/{appid}/fieldgroups/{fieldId}
put /api/apps/{appid}/tables/{tableId}/records/{recordId}

BASH, CURL och JQ
- Börja med att hämta tabellen med listan:
_baseurl=https://<environment name>.istools.com/istools/api # the IS Tools environment API base URL _aname=<service account name> _akey=<service account key> _appid=<IS Tools application ID> _tempfile=$(mktemp) _httpstatus=$(curl -s -H "Accept:application/json" -o "${_tempfile}" -w "%{http_code}" -X GET -u "${_aname}:${_akey}" "${_baseurl}/apps/${_appid}/tables") # -s for silent, -H to force JSON response, -o to specify output file, -w to write-out variable http code, -X GET to use get request, -u for credentials echo "http status code: ${_httpstatus}" echo "response:"; jq '.' < "${_tempfile}" rm "${_tempfile}"
- Hämta sedan tabellens fält med hjälp av tabellens id från första anropet
_tableid=<table id from above, returned as value> _tempfile=$(mktemp) _httpstatus=$(curl -s -H "Accept:application/json" -o "${_tempfile}" -w "%{http_code}" -X GET -u "${_aname}:${_akey}" "${_baseurl}/apps/${_appid}/fields/?links=true&table=${_tableid}") # -s for silent, -H to force JSON response, -o to specify output file, -w to write-out variable http code, -X GET to use get request, -u for credentials echo "http status code: ${_httpstatus}" echo "response:"; jq '.' < "${_tempfile}" rm "${_tempfile}"
- Spara fältets id, och använd därefter extrainformationen för fältet för att hämta listvärden
_listid=<list id from above, returned as extra.target.value> _tempfile=$(mktemp) _httpstatus=$(curl -s -H "Accept:application/json" -o "${_tempfile}" -w "%{http_code}" -X GET -u "${_aname}:${_akey}" "${_baseurl}/apps/${_appid}/fieldgroups/${_listid}") # -s for silent, -H to force JSON response, -o to specify output file, -w to write-out variable http code, -X GET to use get request, -u for credentials echo "http status code: ${_httpstatus}" echo "response:"; jq '.' < "${_tempfile}" rm "${_tempfile}"
- För att spara ett av listans värde används listvärdets egenskaper från ovan samt fältets id
_fieldid=<field id from second step above, returned as value> _listitemuri=<list item uri, from above returned in members as uri> _listitemvalue=<list item value, from above returned in members as value> _recorduri=<record uri of record to update> # fetch using get /api/apps/{appid}/tables/{tableId}/records _tempfile=$(mktemp) _recorddata="{ \"uri\" : \"${_recorduri}\", \"fieldData\" : { \"${_fieldid}\" : {\"uri\" : \"${_listitemuri}\", \"value\" : ${_listitemvalue} } } }" _httpstatus=$(curl -s -H "Content-Type:application/json" -H "Accept:*/*" -o "${_tempfile}" -w "%{http_code}" -X PUT -u "${_aname}:${_akey}" -d "${_recorddata}" "${_baseurl}/${_recorduri#/}") # -s for silent, -H to specify content type and accept all replies, -o to specify output file, -w to write-out variable http code, -X PUT to use put request, -d to inlude data echo "http status code: ${_httpstatus}" echo "response:"; cat "${_tempfile}" rm "${_tempfile}"
Köa en rapportmall, och hämta rapporten
Nedan exempel baseras på en rollbaserad rapport, och använder följande endpoints:get /api/apps/{appid}/reports/rolebased
post /api/apps/{appid}/reports/queue/{reportId}
get /api/apps/{appid}/reports/queue/{qid}/status
get /api/apps/{appid}/reports/queue/{qid}

BASH, CURL och JQ
- Börja med att hämta listan på rollbaserade rapporter:
_baseurl=https://<environment name>.istools.com/istools/api # the IS Tools environment API base URL _aname=<service account name> _akey=<service account key> _appid=<IS Tools application ID> _tempfile=$(mktemp) _httpstatus=$(curl -s -H "Accept:application/json" -o "${_tempfile}" -w "%{http_code}" -X GET -u "${_aname}:${_akey}" "${_baseurl}/apps/${_appid}/reports/rolebased") # -s for silent, -H to force JSON response, -o to specify output file, -w to write-out variable http code, -X GET to use get request, -u for credentials echo "http status code: ${_httpstatus}" echo "response:"; cat "${_tempfile}" | jq '.' rm "${_tempfile}"
- Använd rapportens id från ovan, och lägg rapporten till kön
_templateid=<template id, from above returned as reportId> _tempfile=$(mktemp) _httpstatus=$(curl -s -H "Content-Type:application/json" -H "Accept:*/*" -o "${_tempfile}" -w "%{http_code}" -X POST -u "${_aname}:${_akey}" "${_baseurl}/apps/${_appid}/reports/queue/${_templateid}?format=xlsx&zipped=false") # -s for silent, -H to specify JSON data, -H to specify return format, -o to specify output file, -w to write-out variable http code, -X POST to use post request, -u for credentials echo "http status code: ${_httpstatus}" echo "response (queue id if successful):"; cat "${_tempfile}" rm "${_tempfile}"
- Undersök status med köid från ovan
_queueid=<queue id, from above> _tempfile=$(mktemp) _httpstatus=$(curl -s -H "Accept:*/*" -o "${_tempfile}" -w "%{http_code}" -X GET -u "${_aname}:${_akey}" "${_baseurl}/apps/${_appid}/reports/queue/${_queueid}/status") # -s for silent, -H to force JSON response, -o to specify output file, -w to write-out variable http code, -X GET to use get request, -u for credentials echo "http status code: ${_httpstatus}" echo "response:"; cat "${_tempfile}" rm "${_tempfile}"
- Efter status "FINISHED", hämta rapporten
_queueid=<queue id, from above> _tempfile=$(mktemp) _httpstatus=$(curl -s -H "Accept:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" -o "${_tempfile}" -w "%{http_code}" -X GET -u "${_aname}:${_akey}" "${_baseurl}/apps/${_appid}/reports/queue/${_queueid}?dispositionType=attachment&delete=false") # -s for silent, -H to force JSON response, -o to specify output file, -w to write-out variable http code, -X GET to use get request, -u for credentials echo "http status code: ${_httpstatus}" _reportfile="${_tempfile##*/}" _reportfile="${_reportfile/./}.xlsx" cp "${_tempfile}" "./${_reportfile}" echo "report file: ${_reportfile}" rm "${_tempfile}"
Upp- och nedladdning av filer
Exemplet använder följande endpoints:post /api/apps/{appid}/tables/{tableid}/records/{recordid}/fielddata/{fieldid}
get /api/apps/{appid}/tables/{tableid}/records/{recordid}/fielddata/{fieldid}
BASH, CURL och JQ
- Uppladdning:
_baseurl=https://<environment name>.istools.com/istools/api # the IS Tools environment API base URL _aname=<service account name> _akey=<service account key> _appid=<IS Tools application ID> _tableid=<Table ID> _fieldid=<Field ID> _recordid=<Record ID> _filepath=<File to upload> _tempfile=$(mktemp) _httpstatus=$(curl -s -H "Content-Type: multipart/form-data" -F "file=@${_filepath}" -o "${_tempfile}" -w "%{http_code}" -X POST -u "${_aname}:${_akey}" "${_baseurl}/apps/${_appid}/tables/${_tableid}/records/${_recordid}/fielddata/${_fieldid}") # -s for silent, -H to declare multipart, -o to specify output file, -w to write-out variable http code, -X POST to use post request, -u for credentials echo "http status code: ${_httpstatus}" echo "response:"; jq '.' < "${_tempfile}" rm "${_tempfile}"
- Nedladdning:
_baseurl=https://<environment name>.istools.com/istools/api # the IS Tools environment API base URL _aname=<service account name> _akey=<service account key> _appid=<IS Tools application ID> _tableid=<Table ID> _fieldid=<Field ID> _recordid=<Record ID> _filepath=<Path of downloaded file> _httpstatus=$(curl -s -H "Accept: */*" -o "${_filepath}" -w "%{http_code}" -X GET -u "${_aname}:${_akey}" "${_baseurl}/apps/${_appid}/tables/${_tableid}/records/${_recordid}/fielddata/${_fieldid}") # -s for silent, -H accept all types, -o to specify output file, -w to write-out variable http code, -X GET to use get request, -u for credentials echo "http status code: ${_httpstatus}"