The HTTP API v2 is a great tool to ingest data into Amplitude via server-side. You can use Shell, HTTP, JavaScript, NodeJS, Ruby, Python, Java, and Go to hit the HTTP API v2 endpoint(https://api2.amplitude.com/2/httpapi).
I will demonstrate how to ingest data from the HTTP API v2 endpoint using a curl command using Terminal on a Mac laptop. The HTTP API v2 endpoint expects the event data to be formatted in JSON. Here is an example call:
curl -H 'Content-Type: application/json' -d '{"api_key": "INSERT_API_KEY","events":s{"device_id":"5f9fbb3b-8b65-5a35-8ec1-699f5cfb2998", "event_type":"test_event", "event_properties": {"button_clicked_name": "Subscribe"},"user_properties": {"is_subscribed": true},"ip":"127.0.0.1"}]}' https://api2.amplitude.com/2/httpapi |
The breakdown of the call above:
-
You will need the API Key of your Amplitude project (only members with manager and admin permissions can see this information)
-
The Device ID or User ID of the unique user. (In the call we are using Device ID)
-
The name of the event in this case being “test_event” (you can choose any event name)
-
Event and User Properties which fall under their own set of curly braces.
-
Event Property name: “button_clicked_name”; Event Property value: “Subscribe”
-
User Property name: “is_subscribed”; User Property value: true
-
-
Notice IP Address is outside of user/event properties. This is because IP Address is an Amplitude property already.
You can find more information on the HTTP API v2 endpoint in the developers center, here.