Overwrite event
Records a new version of the event with the idempotencyKey, whose properties, value included, replace those of the recorded event, and answers the latest version of the event. When no event has the key, the route records its first version. When the properties are the same as those of the recorded event and it is not archived, the route records nothing. The eventName, the customerExternalId and the occurredAt of an event stay the same in all its versions.
Requires the role events:write.
curl --request PUT \
--url https://api.useaira.com/v1/events/{idempotencyKey} \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"eventName": "api_request",
"customerExternalId": "cust_1234567890abcdef",
"properties": {
"value": 3600,
"endpoint": "/api/v1/users",
"method": "GET",
"status_code": 200
},
"occurredAt": "2024-01-01T12:00:00Z"
}
'import requests
url = "https://api.useaira.com/v1/events/{idempotencyKey}"
payload = {
"eventName": "api_request",
"customerExternalId": "cust_1234567890abcdef",
"properties": {
"value": 3600,
"endpoint": "/api/v1/users",
"method": "GET",
"status_code": 200
},
"occurredAt": "2024-01-01T12:00:00Z"
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
eventName: 'api_request',
customerExternalId: 'cust_1234567890abcdef',
properties: {value: 3600, endpoint: '/api/v1/users', method: 'GET', status_code: 200},
occurredAt: '2024-01-01T12:00:00Z'
})
};
fetch('https://api.useaira.com/v1/events/{idempotencyKey}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.useaira.com/v1/events/{idempotencyKey}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'eventName' => 'api_request',
'customerExternalId' => 'cust_1234567890abcdef',
'properties' => [
'value' => 3600,
'endpoint' => '/api/v1/users',
'method' => 'GET',
'status_code' => 200
],
'occurredAt' => '2024-01-01T12:00:00Z'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.useaira.com/v1/events/{idempotencyKey}"
payload := strings.NewReader("{\n \"eventName\": \"api_request\",\n \"customerExternalId\": \"cust_1234567890abcdef\",\n \"properties\": {\n \"value\": 3600,\n \"endpoint\": \"/api/v1/users\",\n \"method\": \"GET\",\n \"status_code\": 200\n },\n \"occurredAt\": \"2024-01-01T12:00:00Z\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.useaira.com/v1/events/{idempotencyKey}")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"eventName\": \"api_request\",\n \"customerExternalId\": \"cust_1234567890abcdef\",\n \"properties\": {\n \"value\": 3600,\n \"endpoint\": \"/api/v1/users\",\n \"method\": \"GET\",\n \"status_code\": 200\n },\n \"occurredAt\": \"2024-01-01T12:00:00Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.useaira.com/v1/events/{idempotencyKey}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"eventName\": \"api_request\",\n \"customerExternalId\": \"cust_1234567890abcdef\",\n \"properties\": {\n \"value\": 3600,\n \"endpoint\": \"/api/v1/users\",\n \"method\": \"GET\",\n \"status_code\": 200\n },\n \"occurredAt\": \"2024-01-01T12:00:00Z\"\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"idempotencyKey": "123e4567-e89b-12d3-a456-426614174000",
"eventName": "api_request",
"customerExternalId": "cust_1234567890abcdef",
"properties": {
"value": 3600,
"endpoint": "/api/v1/users",
"method": "GET",
"status_code": 200
},
"occurredAt": "2024-01-01T12:00:00Z",
"createdAt": "2023-11-07T05:31:56Z",
"archivedAt": "2023-11-07T05:31:56Z",
"version": 123
}Path Parameters
Body
The event with the idempotencyKey: its properties, value included, replace those of the recorded event, and its eventName, customerExternalId and occurredAt are those of the recorded event, which stay the same in all its versions.
The moment when the event occurred, in ISO 8601 with its time zone: Z for UTC, or an offset such as -03:00 for Brasília time. Aira refuses a moment without a time zone. Aira always converts the moment to UTC, so 2024-01-01T09:00:00-03:00 becomes 2024-01-01T12:00:00Z.
"2024-01-01T12:00:00Z"
"2024-01-01T09:00:00-03:00"
Response
An event: one usage record that you send for a customer, with an event name, properties and a time.
The moment when the event occurred, in ISO 8601 with its time zone: Z for UTC, or an offset such as -03:00 for Brasília time. Aira refuses a moment without a time zone. Aira always converts the moment to UTC, so 2024-01-01T09:00:00-03:00 becomes 2024-01-01T12:00:00Z.
"2024-01-01T12:00:00Z"
"2024-01-01T09:00:00-03:00"
curl --request PUT \
--url https://api.useaira.com/v1/events/{idempotencyKey} \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"eventName": "api_request",
"customerExternalId": "cust_1234567890abcdef",
"properties": {
"value": 3600,
"endpoint": "/api/v1/users",
"method": "GET",
"status_code": 200
},
"occurredAt": "2024-01-01T12:00:00Z"
}
'import requests
url = "https://api.useaira.com/v1/events/{idempotencyKey}"
payload = {
"eventName": "api_request",
"customerExternalId": "cust_1234567890abcdef",
"properties": {
"value": 3600,
"endpoint": "/api/v1/users",
"method": "GET",
"status_code": 200
},
"occurredAt": "2024-01-01T12:00:00Z"
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
eventName: 'api_request',
customerExternalId: 'cust_1234567890abcdef',
properties: {value: 3600, endpoint: '/api/v1/users', method: 'GET', status_code: 200},
occurredAt: '2024-01-01T12:00:00Z'
})
};
fetch('https://api.useaira.com/v1/events/{idempotencyKey}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.useaira.com/v1/events/{idempotencyKey}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'eventName' => 'api_request',
'customerExternalId' => 'cust_1234567890abcdef',
'properties' => [
'value' => 3600,
'endpoint' => '/api/v1/users',
'method' => 'GET',
'status_code' => 200
],
'occurredAt' => '2024-01-01T12:00:00Z'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.useaira.com/v1/events/{idempotencyKey}"
payload := strings.NewReader("{\n \"eventName\": \"api_request\",\n \"customerExternalId\": \"cust_1234567890abcdef\",\n \"properties\": {\n \"value\": 3600,\n \"endpoint\": \"/api/v1/users\",\n \"method\": \"GET\",\n \"status_code\": 200\n },\n \"occurredAt\": \"2024-01-01T12:00:00Z\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.useaira.com/v1/events/{idempotencyKey}")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"eventName\": \"api_request\",\n \"customerExternalId\": \"cust_1234567890abcdef\",\n \"properties\": {\n \"value\": 3600,\n \"endpoint\": \"/api/v1/users\",\n \"method\": \"GET\",\n \"status_code\": 200\n },\n \"occurredAt\": \"2024-01-01T12:00:00Z\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.useaira.com/v1/events/{idempotencyKey}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"eventName\": \"api_request\",\n \"customerExternalId\": \"cust_1234567890abcdef\",\n \"properties\": {\n \"value\": 3600,\n \"endpoint\": \"/api/v1/users\",\n \"method\": \"GET\",\n \"status_code\": 200\n },\n \"occurredAt\": \"2024-01-01T12:00:00Z\"\n}"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"idempotencyKey": "123e4567-e89b-12d3-a456-426614174000",
"eventName": "api_request",
"customerExternalId": "cust_1234567890abcdef",
"properties": {
"value": 3600,
"endpoint": "/api/v1/users",
"method": "GET",
"status_code": 200
},
"occurredAt": "2024-01-01T12:00:00Z",
"createdAt": "2023-11-07T05:31:56Z",
"archivedAt": "2023-11-07T05:31:56Z",
"version": 123
}