import functions_framework
import json
import requests
@functions_framework.http
def hello_http(request):
req = request.get_json(silent=True)
e = {
'event': req['type'],
'properties': {
'$insert_id': req['id'],
'$device_id': req['data']['object'].get('customer', ''), # If your project is on Original ID Merge, you would specify distinct_id for the user identifier
'time': req['created'],
**req['data']['object']
}
}
resp = requests.post(
"https://api.mixpanel.com/import",
params={"strict": "1"},
headers={
"Content-Type": "application/x-ndjson",
"User-Agent": "mixpanel-stripe"
},
auth=(request.args.get('token'), ""),
data=json.dumps(e),
)
return resp.json()