Hello Marcin,
I have a question about API manipulations for jobod, pathid and filed.
I have a bash function to get an access token :
function bacula_access_token_api()
## Uses oauth2 to query the Bacula API and retrieve an access token
## Delay of the token access : 2min
{
## Get authorization code to prepare access token asking
LOCATION=$(curl -s -I -X GET -H 'Content-Type: application/x-www-form-urlencoded' "${AUTH_URL}?response_type=code&client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&scope=${SCOPE}")
AUTH_CODE=$(echo "${LOCATION}" | grep -i location | awk -F'=' '{print $2}' | tr -d '\r')
## Build the access token with the auhtorization code
RESPONSE=$(curl -s -X POST "${TOKEN_URL}" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code=${AUTH_CODE}" \
--data-urlencode "client_id=${CLIENT_ID}" \
--data-urlencode "client_secret=${CLIENT_SECRET}" \
--data-urlencode "redirect_uri=${REDIRECT_URI}")
ACCESS_TOKEN=$(echo "${RESPONSE}" | jq -r '.access_token')
if [[ -z "${ACCESS_TOKEN}" || "${ACCESS_TOKEN}" == "null" ]]; then
echo "Erreur : Impossible de récupérer le token d'accès."
return 1
fi
echo "Real access token : $ACCESS_TOKEN"
MASKED_TOKEN="${ACCESS_TOKEN:0:4}********${ACCESS_TOKEN: -4}"
echo "Obfuscate access token : ${MASKED_TOKEN}"
}
Then i'm able to use the API with several calls :
API_JOBS=$(curl -s -X GET "${API_URL}/jobs" -H "Authorization: Bearer ${ACCESS_TOKEN_2_MIN}" -H "Content-Type: application/json")
LAST_JOB_LOGS=$(curl -s -X GET "${API_URL}/joblog/${LAST_JOB_ID}" -H "Authorization: Bearer ${ACCESS_TOKEN_2_MIN}" -H "Content-Type: application/json")
LAST_JOB_INFOS=$(curl -s -X GET "${API_URL}/jobs/${LAST_JOB_ID}" -H "Authorization: Bearer ${ACCESS_TOKEN_2_MIN}" -H "Content-Type: application/json")
LAST_JOB_PATHID=$(curl -s -X GET "${API_URL}/bvfs/lsdirs/?jobids=${LAST_JOB_ID}&offset=0&limit=2000&output=json&pathid=${PATHID}" -H "Authorization: Bearer ${ACCESS_TOKEN_2_MIN}" -H "Content-Type: application/json")
LAST_JOB_FILEID=$(curl -s -X GET "${API_URL}/bvfs/lsfiles/?jobids=${LAST_JOB_ID}&offset=0&limit=2000&output=json&pathid=${PATHID}" -H "Authorization: Bearer ${ACCESS_TOKEN_2_MIN}" -H "Content-Type: application/json")
Most of the time, it works without a hitch, and all operations are carried out correctly.
However, sometimes calls suddenly stop going through... Especially when several calls are made for the same bacula job (by searching several times in a row for the last job played).
Under these conditions I have an empty return...
This call is ok :
ALL_JOBS=$(curl -s -X GET "${API_URL}/jobs" -H "Authorization: Bearer ${ACCESS_TOKEN_2_MIN}" -H "Content-Type: application/json")
Same for :
LAST_JOB_INFOS=$(curl -s -X GET "${API_URL}/jobs/${LAST_JOB_ID}" -H "Authorization: Bearer ${ACCESS_TOKEN_2_MIN}" -H "Content-Type: application/json")
BUT this one :
RESPONSE=$(curl -s -X GET "${API_URL}/bvfs/lsdirs/?jobids=${LAST_JOB_ID}&offset=0&limit=2000&output=json&path=" -H "Authorization: Bearer ${ACCESS_TOKEN_2_MIN}" -H "Content-Type: application/json")
DEBUG ECHO : {"output":[],"error":0}
But the problem doesn't arise systematically...
I tried to add :
GET_ALL_JOBIDS=$(curl -s -X GET "${API_URL}/bvfs/getjobids/?jobid=${LAST_JOB_ID}" -H "Authorization: Bearer ${ACCESS_TOKEN_2_MIN}" -H "Content-Type: application/json")
JOBIDS=$(echo "$GET_ALL_JOBIDS" | jq -r '.output | last')
BFVS_UPDATE=$(curl -s -X PUT "${API_URL}/bvfs/update" --data-raw "{\"jobids\":\"$JOBIDS\"}" -H "Authorization: Bearer ${ACCESS_TOKEN_2_MIN}" -H "Content-Type: application/json")
But, it doesn't change anytning...
Do you have any idea ?
Hope all is well with you,
Sincerely yours,
Romain