I’m trying to upload a JSON file to a Firebase realtime database but I keep getting error 400. I’ve uploaded the same JSON file manually through the firebase website and the upload is completed successfully.
I’ve checked the firebase-debug.log file and I noticed the JSON file is being sent without the filename, but I’m unsure as to why that is.
[debug] [2024-07-11T18:49:42.872Z] >>> [apiv2][query] PUT dbpath.firebaseio.com/users/uid/works/.json
[debug] [2024-07-11T18:49:42.873Z] >>> [apiv2][body] PUT dbpath.firebaseio.com/users/uid/works/.json [stream]
[debug] [2024-07-11T18:49:43.291Z] <<< [apiv2][status] PUT dbpath.firebaseio.com/users/uid/works/.json 400
[debug] [2024-07-11T18:49:43.292Z] <<< [apiv2][body] PUT dbpath.firebaseio.com/users/uid/works/.json {"error":"Invalid data; couldn't parse JSON object, array, or value."}
[debug] HTTP Error: 400, Invalid data; couldn't parse JSON object, array, or value.
[error]
[error] Error: Unexpected error while setting data: FirebaseError: HTTP Error: 400, Invalid data; couldn't parse JSON object, array, or value.
Here’s the piece of bash code I’m running (this code is being ran after verifying the files are valid and both the var and uid files have the same amount of user data):
for ((i=0; i<${#uids[@]}; i++)); do
uid=${uids[$i]}
var=${vars[$i]}
varFile=$var
varFile=${var//[-]/_}
# Simular la llamada a ORCID y guardar el resultado en un archivo JSON
echo "Realizando solicitud a ORCID para ${var}"
echo $varFile
jsonFilePath="/Users/user/Documents/folder/outputs_json/prueba/works${varFile}.json"
curl -H 'Content-Type: application/orcid+json' -H 'Authorization: Bearer authkey' "https://pub.orcid.org/v3.0/${var}/works" -i -o "$jsonFilePath"
jsonFile="works${varFile}.json"
# Quitar las primeras 15 líneas del archivo JSON
tail -n +17 "$jsonFile" > "${jsonFile}.tmp" && mv "${jsonFile}.tmp" "$jsonFile"
# Actualizar Firebase con el UID
echo "Actualizando Firebase para el UID ${uid}"
echo $jsonFile
firebase database:set "/users/${uid}/works/" --data ${jsonFile} -P project-name
done
I’m stumped because I’ve changed the –data value to full filenames and different variables but I’m still getting the same error. I’ve also verified the filenames and paths are being correctly stored in the variables by printing them. Any help will be really appreciated!