I’m trying to use the data api to write to a timeseries collection.
First I’m just trying to test it using postman.
I’ve copied the URL endpoint from Atlas
https://data.mongodb-api.com/app/data-gtvwb/endpoint/data/beta
And here’s the curl of my postman request
curl --location --request POST 'https://data.mongodb-api.com/app/data-gtvwb/endpoint/data/beta' \
--header 'api-key: 623162099d97dbf78443a478' \
--header 'Content-Type: application/json' \
--data-raw '{
"dataSource": "Beta",
"database": "Spot_Chair",
"collection": "Timeseries",
"document": {
"tstamp": { "$date": { "$numberLong": "1638551310749" } }
}
}'
I’m directly copy pasting the URL and the API-Key from the interface so I’m not really sure what’s going wrong here.
What’s even stranger is that the Data API log shows my requests with an OK status
I tried with the generated python code and got a bit further but the response is still that document is not a valid parameter
Invalid parameter(s) specified: document
import requests
import json
url = "https://data.mongodb-api.com/app/data-gtvwb/endpoint/data/beta/action/findOne"
payload = json.dumps({
"collection": "TimeSeries",
"database": "Spot_Chair",
"dataSource": "Beta",
"projection": {
"_id": 1
},
"document" : {
"tstamp" : { "$date": { "$numberLong": "1638551310749" } },
"device" : "FFFFF",
"data" : "-999",
"batt" : "-99"
}
})
headers = {
'Content-Type': 'application/json',
'Access-Control-Request-Headers': '*'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Hi Anton - I would suggest not pasting your API key in our forums.
My guess here is the problem with your URLs. Your first request snippet doesn’t have an /insertOne
at the end of the URL and the second paste is doing a findOne
but that endpoint doesn’t take the ‘document’ value https://www.mongodb.com/docs/atlas/api/data-api-resources/