Title: Firebase Firestore API does not work on just Flutter
Tags: flutter
Question: Firebase Firestore API does not work on Flutter only. I have tried the same url on my browser and python and they work like a charm. I could not figure out why it does not work Flutter.
API_url = https://firestore.googleapis.com/v1beta1/projects/weathersense-daa83/databases/(default)/documents/weather_data/latest_data
The code I wrote in the HTTP get request in Flutter
var response = await http.post(
'https://firestore.googleapis.com/v1beta1/projects/weathersense-daa83/databases/(default)/documents/weather_data/latest_data');
print(response);
print(response.body);
The output that I got
I/flutter (15665): {
I/flutter (15665):   &quot;error&quot;: {
I/flutter (15665):     &quot;code&quot;: 400,
I/flutter (15665):     &quot;message&quot;: &quot;Document parent name \&quot;projects/weathersense-daa83/databases/(default)/documents/weather_data\&quot; lacks \&quot;/\&quot; at index 70.&quot;,
I/flutter (15665):     &quot;status&quot;: &quot;INVALID_ARGUMENT&quot;
I/flutter (15665):   }
I/flutter (15665): }
The same url on browser retrieves the data.
&quot;name&quot;: &quot;projects/weathersense-daa83/databases/(default)/documents/weather_data/latest_data&quot;,
&quot;fields&quot;: {
&quot;timestamp&quot;: {
&quot;integerValue&quot;: &quot;20201106131503&quot;
},
&quot;rain_intensity&quot;: {
&quot;doubleValue&quot;: 0
},
&quot;wind_speed&quot;: {
&quot;doubleValue&quot;: 0
},
&quot;hail_duration&quot;: {
&quot;doubleValue&quot;: 0
},
&quot;humidity&quot;: {
&quot;doubleValue&quot;: 57.2
},
&quot;supply_voltage&quot;: {
&quot;doubleValue&quot;: 13.9
},
&quot;rain_accumulation&quot;: {
&quot;doubleValue&quot;: 0
},
&quot;ref_voltage&quot;: {
&quot;doubleValue&quot;: 3.615
},
&quot;rain_duration&quot;: {
&quot;doubleValue&quot;: 0
},
&quot;internal_temp&quot;: {
&quot;doubleValue&quot;: 23.6
},
&quot;temp&quot;: {
&quot;doubleValue&quot;: 23.4
},
&quot;pressure&quot;: {
&quot;doubleValue&quot;: 1002.6
&quot;createTime&quot;: &quot;2020-10-31T20:15:04.479800Z&quot;,
&quot;updateTime&quot;: &quot;2020-11-06T05:15:03.935166Z&quot;
Comment: Use GET request it will work.

Here is the accepted answer: I think you should use 'GET' request instead of 'POST', cause thats what browsers do.
var response = await http.get(
'https://firestore.googleapis.com/v1beta1/projects/weathersense-daa83/databases/(default)/documents/weather_data/latest_data');
print(response);
print(response.body);


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:11/06/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<flutter>', 'Title': 'Firebase Firestore API does not work on just Flutter', 'ViewCount': 34, 'id': 64709344, 'user_AboutMe': None, 'user_AccountId': 12093738.0, 'user_DisplayName': 'Phan Qi Xiang', 'user_Reputation': 3.0, 'user_Views': 4.0, 'user_id': 8838621.0}}