Logging
The easiest way to log data is to use the auto generated logging code in the visualizer logging tab. However you can find the official documentation below.
API Endpoint
https://api.graphjson.com/api/log
API Parameters
Field | Type | Description |
---|---|---|
api_key | string | your account api key |
collection | string | the collection you want to query data from |
timestamp | number | the unix timestamp of the event |
json | string | the json event you want to log |
So for instance, in Python your code might look like
import requests
import json
import time
payload = {
"api_key": os.getenv('GRAPHJSON_API_KEY'),
"collection": "all_events",
"timestamp": int(time.time()),
"json": json.dumps({
"Event": "Uber Ride",
"Price": 9.99,
"Driver_Rating": 5,
"Driver_ID": "123",
"Day_Of_Week": "Saturday",
}),
}
r = requests.post("https://api.graphjson.com/api/log", json=payload)
Bulk Logging
We also have a bulk logging API. It's very similar to the log API except instead of timestamp
and json
, you have timestamps
and jsons
. The endpoint is also /api/bulk-log
instead of /api/log
. So for instance in python your code might look like
import requests
import json
import time
payload = {
"api_key": os.getenv('GRAPHJSON_API_KEY'),
"collection": "all_events",
"timestamps": [
int(time.time()),
int(time.time())
],
"jsons": [
json.dumps({
"Event": "Uber Ride",
"Price": 9.99,
"Driver_Rating": 5,
"Driver_ID": "123",
"Day_Of_Week": "Saturday",
}),
json.dumps({
"Event": "Uber Ride",
"Price": 9.99,
"Driver_Rating": 5,
"Driver_ID": "123",
"Day_Of_Week": "Saturday",
}),
],
}
r = requests.post("https://api.graphjson.com/api/bulk-log", json=payload)
Do note that the this endpoint can at max handle aggregate json blobs of 50k characters. If you have large json blobs, you'll likely want to use smaller batch sizes.
Nested JSON
It's useful to note that all JSON blobs will be flattened. eg.
{
"a": {
"b": 1
}
}
Will be flattened into
{
"a.b": 1
}
Before being inserted into GraphJSON
FAQ
What is a unix timestamp?
The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch. Some APIs erroneously describe unix timestamps as milliseconds or nanoseconds since epoch. This is wrong, so please don't pass in milliseconds or nanoseconds as your unix timestamp. The API will reject the request.