I'm stuck with an axios get request to my firebase realtime database Rest endpoint.
The fetching with postman works well using three parameters (see below) and following produced final url :
https://projectname.firebaseio.com/latestMeasurements.json?orderBy="$key"&startAt="key000010"&endAt="key000020"
Subsequently I created following simple axios request. For the "startAt" and "endAt" I receive the error "Constraint key field must be a valid key name" as it seems the constraints are not translated in quotes. For "orderBy" parameter I receive "orderBy must be a valid JSON encoded path". As the "$key" does also not have quotes in the end url.
I tried multiple ways of passing the params but not one worked. As said, with postman everything works fine...
Any help is appreciated!
axios({
method: 'GET',
url:'https://projectname.firebaseio.com/latestMeasurements.json,
params: { startAt: "key000010", endAt: "key000020", orderBy : "$key" },
})
.then((res) => {
console.log("SUCCESSFUL FETCH", res.data);
})
.catch((e) => {
console.log("ERROR",e);
});
example data under /latestMeasurements:
[{
"key000001": {
"city": "Stockholm",
"country": "SE",
"lastUpdated": 1522854000000,
"latitued": "N/A",
"location": "(Folkungagatan tillf?lligt avst?ngd)",
"longitued": "N/A",
"measurements": [
{
"parameter": "no2",
"unit": "μg/m3",
"value": -99
},
{
"parameter": "pm10",
"unit": "μg/m3",
"value": -99
}
]
},
"key000002": {
"city": "Ulaanbaatar",
"country": "MN",
"lastUpdated": 1552513500000,
"latitude": 47.91798,
"location": "1-r khoroolol",
"longitude": 106.84806,
"measurements": [
{
"parameter": "co",
"unit": "μg/m3",
"value": 57
},
{
"parameter": "no2",
"unit": "μg/m3",
"value": 30
},
{
"parameter": "pm10",
"unit": "μg/m3",
"value": 199
},
{
"parameter": "pm25",
"unit": "μg/m3",
"value": 217
},
{
"parameter": "so2",
"unit": "μg/m3",
"value": 21
}
]
}
}
]
error fetching frontend (here orderBy is fixed in url and not passed as a param to only produce the error on the other parameters) :
reproduction of this error in postman (param values not in quotes):
success in postman (param values in quotes):
question from:
https://stackoverflow.com/questions/65643638/axios-params-problem-with-passing-the-param-values-in-quotes-paramvalue