| 11 | |
| 12 | |
| 13 | def create_events(events: List[EventDict]) -> Optional[Any]: |
| 14 | try: |
| 15 | data = { |
| 16 | "events": [ |
| 17 | { |
| 18 | "write_key": WRITE_KEY, |
| 19 | "name": event["event"], |
| 20 | "properties": event.get("properties"), |
| 21 | } |
| 22 | for event in events |
| 23 | ] |
| 24 | } |
| 25 | |
| 26 | conn = http.client.HTTPSConnection("app.firstpartyhq.com") |
| 27 | |
| 28 | payload = json.dumps(data) |
| 29 | |
| 30 | headers = { |
| 31 | "Content-Type": "application/json", |
| 32 | "Accept": "application/json", |
| 33 | } |
| 34 | |
| 35 | conn.request("POST", "/events/v1/track/bulk", payload, headers) |
| 36 | |
| 37 | res = conn.getresponse() |
| 38 | |
| 39 | return json.loads(res.read()) |
| 40 | except Exception: |
| 41 | return None |