{% extends "admin_extra_buttons/action_page.html" %} {% load i18n %} {% block content %}

{% translate "Trigger URL" %}

{{ trigger_url }}

{% translate "Authenticate using your API key (available in Application settings)." %}

{% if can_read_apikeys and api_keys %}
{% endif %}
curl -X POST {{ trigger_url }} \
  -H "Authorization: Key YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"context": {}, "options": {}}'
wget --no-check-certificate \
  --method POST \
  --header "Authorization: Key YOUR_API_KEY" \
  --header "Content-Type: application/json" \
  --body-data '{"context": {}, "options": {}}' \
                    {{ trigger_url }}
http POST {{ trigger_url }} \
  Authorization:"Key YOUR_API_KEY" \
  Content-Type:"application/json" \
  context:={} \
  options:={}
bitcaster trigger \
  --organization {{ original.application.project.organization.slug }} \
  --project {{ original.application.project.slug }} \
  --application {{ original.application.slug }} \
  --event {{ original.slug }} \
  --api-key YOUR_API_KEY

{% translate "Client (sync)" %}

from bitcaster_sdk import Client
client = Client(base_url="https://example.com", api_key="YOUR_API_KEY")
client.event.trigger(
    organization="{{ original.application.project.organization.slug }}",
    project="{{ original.application.project.slug }}",
    application="{{ original.application.slug }}",
    event="{{ original.slug }}",
    context={"key": "value"},
)

{% translate "AsyncClient" %}

from bitcaster_sdk import AsyncClient
client = AsyncClient(base_url="https://example.com", api_key="YOUR_API_KEY")
await client.event.trigger(
    organization="{{ original.application.project.organization.slug }}",
    project="{{ original.application.project.slug }}",
    application="{{ original.application.slug }}",
    event="{{ original.slug }}",
    context={"key": "value"},
)
import requests
response = requests.post(
    "{{ trigger_url }}",
    headers={
        "Authorization": "Key YOUR_API_KEY",
        "Content-Type": "application/json",
    },
    json={"context": {}, "options": {}},
)
import httpx
with httpx.Client() as client:
    response = client.post(
        "{{ trigger_url }}",
        headers={"Authorization": "Key YOUR_API_KEY"},
        json={"context": {}, "options": {}},
    )
// Using fetch (browser)
fetch("{{ trigger_url }}", {
    method: "POST",
    headers: {
        "Authorization": "Key YOUR_API_KEY",
        "Content-Type": "application/json",
    },
    body: JSON.stringify({ context: {}, options: {} }),
});
// Using axios
const axios = require("axios");

await axios.post("{{ trigger_url }}",
    { context: {}, options: {} },
    {
        headers: {
            Authorization: "Key YOUR_API_KEY",
            "Content-Type": "application/json",
        },
    },
);

// Using fetch (node 18+)
const response = await fetch("{{ trigger_url }}", {
    method: "POST",
    headers: {
        "Authorization": "Key YOUR_API_KEY",
        "Content-Type": "application/json",
    },
    body: JSON.stringify({ context: {}, options: {} }),
});
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Key", "YOUR_API_KEY");

var payload = JsonSerializer.Serialize(new {
    context = new { },
    options = new { }
});

var response = await client.PostAsync(
    "{{ trigger_url }}",
    new StringContent(payload, Encoding.UTF8, "application/json")
);

{% translate "Guzzle" %}

$client = new GuzzleHttp\Client();
$response = $client->post('{{ trigger_url }}', [
    'headers' => [
        'Authorization' => 'Key YOUR_API_KEY',
        'Content-Type' => 'application/json',
    ],
    'json' => [
        'context' => [],
        'options' => [],
    ],
]);

{% translate "cURL" %}

$ch = curl_init('{{ trigger_url }}');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Key YOUR_API_KEY',
    'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'context' => [],
    'options' => [],
]));
$response = curl_exec($ch);
require 'net/http'
require 'uri'

uri = URI.parse("{{ trigger_url }}")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.path)
request["Authorization"] = "Key YOUR_API_KEY"
request["Content-Type"] = "application/json"
request.body = { context: {}, options: {} }.to_json

response = http.request(request)

# Using httprb (gem)
# require 'httparty'
# response = HTTParty.post(
#   "{{ trigger_url }}",
#   headers: {
#     "Authorization" => "Key YOUR_API_KEY",
#     "Content-Type" => "application/json",
#   },
#   body: { context: {}, options: {} }.to_json,
# )

{% translate "libcurl (C++)" %}

#include 
#include 

CURL *curl = curl_easy_init();
if (curl) {
    struct curl_slist *headers = NULL;
    headers = curl_slist_append(headers, "Authorization: Key YOUR_API_KEY");
    headers = curl_slist_append(headers, "Content-Type: application/json");

    nlohmann::json body = {
        {"context", nlohmann::json::object()},
        {"options", nlohmann::json::object()}
    };

    curl_easy_setopt(curl, CURLOPT_URL, "{{ trigger_url }}");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.dump().c_str());
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(curl, CURLOPT_POST, 1L);

    CURLcode res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
}

{% translate "cpprestsdk" %}

#include 
#include 

using namespace web;
using namespace web::http;

auto client = http_client(U("{{ trigger_url }}"));
json::value body;
body[U("context")] = json::value::object();
body[U("options")] = json::value::object();

auto headers = http_headers();
headers.add(U("Authorization"), U("Key YOUR_API_KEY"));
headers.add(U("Content-Type"), U("application/json"));

auto response = client.request(methods::POST, U(""), body.serialize(), headers).get();
{% endblock content %} {% block extrahead %} {{ block.super }} {% endblock extrahead %}