### Actix-web Example for Webhook Handling Source: https://documentation.hook0.com/docs/sdk-rust A basic Actix-web server setup in Rust to demonstrate handling incoming webhooks. It binds to a local address and defines a route for POST requests. ```rust use actix_web::{web, App, HttpServer}; #[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| App::new().route("/webhook", web::post().to(handle_webhook))) .bind("127.0.0.1:8081")? .run() .await } ``` -------------------------------- ### List Application Secrets using PHP Source: https://documentation.hook0.com/reference Illustrates how to get application secrets in PHP using cURL. This example requires the cURL extension to be enabled in your PHP installation. ```php ``` -------------------------------- ### List Application Secrets using Node.js Source: https://documentation.hook0.com/reference Provides a Node.js code example to fetch application secrets. It utilizes the 'axios' library for making HTTP requests. Ensure 'axios' is installed (`npm install axios`). ```javascript const axios = require('axios'); const getSecrets = async () => { try { const response = await axios.get('https://app.hook0.com/api/v1/application_secrets/', { headers: { 'accept': 'application/json' } }); console.log(response.data); return response.data; } catch (error) { console.error('Error fetching secrets:', error); throw error; } }; getSecrets(); ``` -------------------------------- ### Install Hook0 Javascript Client Source: https://documentation.hook0.com/docs/sdk-typescript Install the Hook0 Javascript / Typescript client in your project using npm. This is the initial step to integrate Hook0's webhooks-as-a-service platform. ```bash npm install hook0-client ``` -------------------------------- ### List Application Secrets using Ruby Source: https://documentation.hook0.com/reference Shows how to retrieve application secrets in Ruby using the built-in 'net/http' library. This example demonstrates a direct HTTP GET request. ```ruby require 'net/http' require 'uri' uri = URI.parse('https://app.hook0.com/api/v1/application_secrets/') request = Net::HTTP::Get.new(uri) request['accept'] = 'application/json' response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| http.request(request) end puts response.body ``` -------------------------------- ### GET /api/v1/applications/ Source: https://documentation.hook0.com/reference/applicationslist Retrieves all applications associated with an organization. Requires an `organization_id` to filter applications. ```APIDOC ## GET /api/v1/applications/ ### Description Retrieves all applications. This endpoint allows you to fetch a list of all applications within a specific organization. ### Method GET ### Endpoint /api/v1/applications/ ### Parameters #### Query Parameters - **organization_id** (string) - Required - The unique identifier for the organization. Applications will be filtered by this ID. ### Request Example ``` GET /api/v1/applications/?organization_id=a1b2c3d4-e5f6-7890-1234-567890abcdef ``` ### Response #### Success Response (200) - **application_id** (string) - The unique identifier of the application. - **name** (string) - The name of the application. - **organization_id** (string) - The identifier of the organization the application belongs to. #### Response Example ```json [ { "application_id": "123e4567-e89b-12d3-a456-426614174000", "name": "Example App 1", "organization_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef" }, { "application_id": "987e6543-e21b-12d3-a456-426614174001", "name": "Example App 2", "organization_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ] ``` #### Error Responses - **400 Bad Request**: The request was malformed or invalid. - **403 Forbidden**: The authenticated user does not have permission to perform this action. - **404 Not Found**: The specified resource was not found. - **409 Conflict**: A conflict occurred, likely due to resource state. - **500 Internal Server Error**: An unexpected error occurred on the server. ``` -------------------------------- ### GET /api/v1/instance/ Source: https://documentation.hook0.com/reference/instanceget Retrieves the configuration details for the current instance. This object shows how the instance is configured, including settings related to compatibility, migrations, keys, integrations, and user-specific options. ```APIDOC ## GET /api/v1/instance/ ### Description Get an object that shows how this instance is configured. ### Method GET ### Endpoint /api/v1/instance/ ### Parameters ### Request Body None ### Request Example None ### Response #### Success Response (200) - **application_secret_compatibility** (boolean) - Indicates if application secret compatibility is enabled. - **auto_db_migration** (boolean) - Indicates if automatic database migration is enabled. - **biscuit_public_key** (string) - The public key for Biscuit authentication. - **cloudflare_turnstile_site_key** (string) - The site key for Cloudflare Turnstile. - **formbricks** (object) - Formbricks integration settings. - **api_host** (string) - The API host for Formbricks. - **environment_id** (string) - The environment ID for Formbricks. - **matomo** (object) - Matomo analytics settings. - **site_id** (integer) - The site ID for Matomo. - **url** (string) - The URL for Matomo. - **password_minimum_length** (integer) - The minimum required length for passwords. - **quota_enforcement** (boolean) - Indicates if quota enforcement is enabled. - **registration_disabled** (boolean) - Indicates if user registration is disabled. - **support_email_address** (string) - The support email address. #### Response Example ```json { "application_secret_compatibility": true, "auto_db_migration": false, "biscuit_public_key": "pk_test_abcdef1234567890", "cloudflare_turnstile_site_key": "1x00000000000000000000AA", "formbricks": { "api_host": "https://api.formbricks.com", "environment_id": "env_abcdef1234567890" }, "matomo": { "site_id": 1, "url": "https://analytics.example.com" }, "password_minimum_length": 8, "quota_enforcement": true, "registration_disabled": false, "support_email_address": "support@example.com" } ``` #### Error Responses - **400 Bad Request**: The request was invalid. - **403 Forbidden**: Authentication failed or user lacks permissions. - **404 Not Found**: The requested resource was not found. - **409 Conflict**: A conflict occurred, such as trying to create a resource that already exists. - **500 Internal Server Error**: An unexpected error occurred on the server. ``` -------------------------------- ### List Application Secrets using Python Source: https://documentation.hook0.com/reference A Python example for fetching application secrets using the 'requests' library. Ensure 'requests' is installed (`pip install requests`). ```python import requests url = "https://app.hook0.com/api/v1/application_secrets/" headers = { 'accept': 'application/json' } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes print(response.json()) except requests.exceptions.RequestException as e: print(f"Error fetching secrets: {e}") ``` -------------------------------- ### Setup Hook0 Rust Client Source: https://documentation.hook0.com/docs/sdk-rust Instructions for adding the Hook0 Rust client to your project using Cargo. It shows both the `cargo add` command and the direct TOML dependency addition. ```bash cargo add hook0-client ``` ```toml [dependencies] hook0-client = "hook0-client-version" ``` -------------------------------- ### List Service Tokens using Python Source: https://documentation.hook0.com/reference/service-tokens-management This Python code snippet shows how to list active service tokens using the 'requests' library. It performs a GET request to the Hook0 API and prints the JSON response. Make sure to install the 'requests' library (`pip install requests`). ```python import requests url = "https://app.hook0.com/api/v1/service_token/" headers = { "accept": "application/json" } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes print(response.json()) except requests.exceptions.RequestException as e: print(f"Error: {e}") ``` -------------------------------- ### List Organizations Ruby Request Source: https://documentation.hook0.com/reference/organizations-management An example in Ruby for fetching organization data. It utilizes the 'net/http' library to perform a GET request to the specified Hook0 API endpoint. ```ruby require 'net/http' require 'uri' uri = URI.parse('https://app.hook0.com/api/v1/organizations/') request = Net::HTTP::Get.new(uri) request['accept'] = 'application/json' response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end puts response.body ``` -------------------------------- ### Create Subscription with cURL Source: https://documentation.hook0.com/docs/getting-started This snippet demonstrates how to create a new subscription using a cURL command. It includes all necessary parameters such as application ID, description, event types, and target URL. Authentication is handled via an Authorization header using an application secret. ```curl curl --request POST \ --url 'https://app.hook0.com/api/v1/subscriptions/' \ --header "Authorization: Bearer $APPLICATION_SECRET" \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data ' { "application_id": "your_app_ID", "description": "This is the subscription from the tutorial", "metadata": { "tutorial": "true" }, "is_enabled": true, "event_types": [ "mycrm.customer.created" ], "label_key": "all", "label_value": "yes", "target": { "type": "http", "method": "POST", "url": "https://webhook.site/...", "headers": {} } } ' ``` -------------------------------- ### Build Hook0 API with Rust Source: https://documentation.hook0.com/docs/manual-setup Compiles the Hook0 API using Rust stable. This command builds the release executable for the API server. SQLX_OFFLINE=true is used to prevent SQLx from needing to connect to the database during build time. ```shell cd api SQLX_OFFLINE=true cargo build --release cd .. ``` -------------------------------- ### Create a Hook0 Subscription using cURL Source: https://documentation.hook0.com/docs/getting-started-1 This snippet demonstrates how to create a new subscription to receive webhooks from Hook0. It requires an application ID, description, metadata, enabled status, event types, label, and target information (URL and headers). Authentication is done using the application secret. ```curl curl --request POST \ --url 'https://app.hook0.com/api/v1/subscriptions/' \ --header "Authorization: Bearer $APPLICATION_SECRET" \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data ' { "application_id": "your_app_ID", "description": "This is the subscription from the tutorial", "metadata": { "tutorial": "true" }, "is_enabled": true, "event_types": [ "mycrm.customer.created" ], "label_key": "all", "label_value": "yes", "target": { "type": "http", "method": "POST", "url": "https://webhook.site/…", "headers": {} } } ' ``` -------------------------------- ### List Errors Request (Node.js) Source: https://documentation.hook0.com/reference/hook0 Example of how to list errors using Node.js. This code snippet utilizes the 'axios' library to make a GET request to the Hook0 API endpoint for errors. ```javascript const axios = require('axios'); axios.get('https://app.hook0.com/api/v1/errors/', { headers: { 'accept': 'application/json' } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error fetching errors:', error); }); ``` -------------------------------- ### Project Websites API Documentation Source: https://documentation.hook0.com/reference/organizationsget Details the structure of a project website object, including consumption, onboarding steps, organization ID, quotas, and user information. ```APIDOC ## Project Websites API ### Description This API documentation details the structure of a project website object, including its consumption, onboarding steps, organization ID, quotas, and user information. It also specifies the security scheme for authentication. ### Method N/A (This section describes the data structure, not a specific endpoint) ### Endpoint N/A ### Parameters #### Request Body Structure (for creating/updating project websites) - **consumption** (object) - Required - Represents consumption details. - **storage** (integer) - Required - Storage consumption in bytes. - **bandwidth** (integer) - Required - Bandwidth consumption in bytes. - **name** (string) - Required - The name of the project website. - **onboarding_steps** (array) - Required - A list of onboarding steps. - **completed** (boolean) - Required - Indicates if the step is completed. - **name** (string) - Required - The name of the onboarding step. - **organization_id** (string) - Required - The ID of the organization the website belongs to. - **quotas** (object) - Required - Quotas for the project website. - **max_storage** (integer) - Required - Maximum storage quota in bytes. - **max_bandwidth** (integer) - Required - Maximum bandwidth quota in bytes. - **users** (array) - Required - A list of users associated with the project website. - **email** (string) - Required - The email address of the user. - **first_name** (string) - Required - The first name of the user. - **last_name** (string) - Required - The last name of the user. - **role** (string) - Required - The role of the user within the project website. - **user_id** (string, uuid) - Required - The unique identifier for the user. ### Security #### Security Schemes - **biscuit** (apiKey) - Required - Authentication using a Biscuit token. Use the format `Bearer TOKEN` in the `Authorization` header. ``` -------------------------------- ### List Organizations Node.js Request Source: https://documentation.hook0.com/reference/organizations-management Example of how to fetch organizations using Node.js. This code uses the 'node-fetch' library to make a GET request to the Hook0 API and expects a JSON response. ```javascript import fetch from 'node-fetch'; const options = { method: 'GET', headers: { 'accept': 'application/json' } }; fetch('https://app.hook0.com/api/v1/organizations/', options) .then(response => response.json()) .then(response => console.log(response)) .catch(error => console.error(error)); ``` -------------------------------- ### POST /api/v1/event/ Source: https://documentation.hook0.com/reference/eventsingest Ingest an event into your Hook0 application. This will trigger any matching subscriptions. ```APIDOC ## POST /api/v1/event/ ### Description Send an event to your Hook0 application. Matching subscriptions will be triggered, if any. ### Method POST ### Endpoint https://app.hook0.com/api/v1/event/ ### Parameters #### Query Parameters None #### Request Body - **application_id** (string) - Required - The ID of the Hook0 application. - **event_id** (string) - Required - The unique ID for the event. - **event_type** (string) - Required - The type of the event. - **labels** (object) - Required - Key-value pairs for labeling the event. - **occurred_at** (string) - Required - The timestamp when the event occurred (ISO 8601 format). - **payload** (string) - Required - The event payload. - **payload_content_type** (string) - Required - The content type of the payload. - **metadata** (object) - Optional - Additional metadata for the event. ### Request Example ```json { "application_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "event_id": "f0e9d8c7-b6a5-4321-fedc-ba9876543210", "event_type": "user.created", "labels": { "source": "api", "region": "us-east-1" }, "metadata": { "request_id": "xyz789" }, "occurred_at": "2023-10-27T10:00:00Z", "payload": "{\"user_id\": 123, \"email\": \"test@example.com\"}", "payload_content_type": "application/json" } ``` ### Response #### Success Response (201 Created) - **application_id** (string) - The ID of the Hook0 application. - **event_id** (string) - The ID of the ingested event. - **received_at** (string) - The timestamp when the event was received by Hook0 (ISO 8601 format). #### Response Example ```json { "application_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "event_id": "f0e9d8c7-b6a5-4321-fedc-ba9876543210", "received_at": "2023-10-27T10:00:01Z" } ``` #### Error Responses - **400 Bad Request**: The request payload is invalid. - **403 Forbidden**: Authentication failed or insufficient permissions. - **404 Not Found**: The specified application ID was not found. - **409 Conflict**: An event with the same `event_id` already exists. - **500 Internal Server Error**: An unexpected error occurred on the server. ``` -------------------------------- ### List Errors Request (PHP) Source: https://documentation.hook0.com/reference/hook0 A PHP example for fetching errors from Hook0's API. This code uses cURL to perform the GET request and retrieve the error list in JSON format. ```php ``` -------------------------------- ### Clone Hook0 Repository Source: https://documentation.hook0.com/docs/manual-setup Clones the Hook0 repository from GitLab and navigates into the project directory. This is the initial step for any bare metal deployment. ```shell git clone https://gitlab.com/hook0/hook0 cd hook0 ``` -------------------------------- ### Build Hook0 UI with Node.js Source: https://documentation.hook0.com/docs/manual-setup Builds the Hook0 UI component using Node.js and npm. Requires Node.js LTS and npm. The `API_ENDPOINT` environment variable must be set to the base URL of the Hook0 API. ```shell cd frontend npm ci npm run build cd .. ``` -------------------------------- ### List Request Attempts - Ruby Example Source: https://documentation.hook0.com/reference/subscriptions-management This Ruby code snippet demonstrates how to retrieve request attempts using the Net::HTTP library. It makes a GET request to the specified API endpoint and prints the response body. ```ruby require 'net/http' require 'uri' uri = URI.parse('https://app.hook0.com/api/v1/request_attempts/') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) request['accept'] = 'application/json' response = http.request(request) puts response.body ``` -------------------------------- ### List Request Attempts - Python Example Source: https://documentation.hook0.com/reference/subscriptions-management This Python code snippet shows how to make a GET request to the Hook0 API using the 'requests' library to list request attempts. It handles potential errors and prints the JSON response. ```python import requests url = "https://app.hook0.com/api/v1/request_attempts/" headers = { "accept": "application/json" } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes print(response.json()) except requests.exceptions.RequestException as e: print(f"Error: {e}") ``` -------------------------------- ### Build Hook0 Output Worker with Rust Source: https://documentation.hook0.com/docs/manual-setup Compiles the Hook0 Output Worker using Rust stable. Similar to the API build, this command creates the release executable for the output worker. SQLX_OFFLINE=true is used for build-time optimization. ```shell cd output-worker SQLX_OFFLINE=true cargo build --release cd .. ``` -------------------------------- ### Create New Application (OpenAPI) Source: https://documentation.hook0.com/reference/applicationscreate This snippet details the OpenAPI definition for creating a new application. It specifies the request body schema, expected responses, and authentication method. This endpoint allows registration of new applications within an organization that emit events for webhook subscriptions. ```json { "openapi": "3.0.0", "info": { "title": "Hook0 API", "description": "Core REST API of Hook0 — Open-Source Webhooks as a service for SaaS", "version": "0.1.0" }, "servers": [ { "url": "https://app.hook0.com" } ], "paths": { "/api/v1/applications/": { "post": { "tags": [ "Applications Management" ], "summary": "Create a new application", "description": "Registers a new application within an organization. An application emits events that customers can subscribe to using webhooks.", "operationId": "applications.create", "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ApplicationPost" } } }, "required": true }, "responses": { "201": { "description": "Created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Application" } } } }, "400": { "description": "Bad Request" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" }, "409": { "description": "Conflict" }, "500": { "description": "Internal Server Error" } }, "security": [ { "biscuit": [] } ] } } }, "components": { "schemas": { "Application": { "type": "object", "properties": { "application_id": { "type": "string", "format": "uuid" }, "name": { "type": "string" }, "organization_id": { "type": "string", "format": "uuid" } }, "required": [ "application_id", "name", "organization_id" ] }, "ApplicationPost": { "type": "object", "properties": { "name": { "type": "string" }, "organization_id": { "type": "string", "format": "uuid" } }, "required": [ "name", "organization_id" ] } }, "securitySchemes": { "biscuit": { "type": "apiKey", "in": "header", "name": "Authorization", "description": "Authentication using a Biscuit token (use the format `Bearer TOKEN`)" } } }, "x-readme": { "explorer-enabled": true, "proxy-enabled": true }, "_id": "6687c4b6e4a7bb0056e69fe3" } ``` -------------------------------- ### List Service Tokens using Node.js Source: https://documentation.hook0.com/reference/service-tokens-management This Node.js code snippet shows how to fetch active service tokens using the 'node-fetch' library. It sends a GET request to the Hook0 API endpoint and handles the JSON response. Ensure 'node-fetch' is installed. ```javascript import fetch from 'node-fetch'; const url = "https://app.hook0.com/api/v1/service_token/"; const options = { method: 'GET', headers: { 'accept': 'application/json' } }; fetch(url, options) .then(res => res.json()) .then(json => console.log(json)) .catch(err => console.error('error:' + err)); ``` -------------------------------- ### POST /api/v1/applications/ Source: https://documentation.hook0.com/reference/applicationscreate Registers a new application within an organization. An application emits events that customers can subscribe to using webhooks. ```APIDOC ## POST /api/v1/applications/ ### Description Registers a new application within an organization. An application emits events that customers can subscribe to using webhooks. ### Method POST ### Endpoint https://app.hook0.com/api/v1/applications/ ### Parameters #### Request Body - **name** (string) - Required - The name of the application. - **organization_id** (string, uuid) - Required - The ID of the organization to which the application belongs. ### Request Example ```json { "name": "My New App", "organization_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ### Response #### Success Response (201) - **application_id** (string, uuid) - The unique identifier for the created application. - **name** (string) - The name of the application. - **organization_id** (string, uuid) - The ID of the organization the application belongs to. #### Response Example ```json { "application_id": "f0e9d8c7-b6a5-4321-fedc-ba9876543210", "name": "My New App", "organization_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` #### Error Responses - **400**: Bad Request - **403**: Forbidden - **404**: Not Found - **409**: Conflict - **500**: Internal Server Error ``` -------------------------------- ### List Service Tokens using PHP Source: https://documentation.hook0.com/reference/service-tokens-management This PHP code snippet illustrates how to fetch active service tokens using cURL. It makes a GET request to the Hook0 API endpoint and outputs the JSON response. Ensure the cURL extension is enabled in your PHP installation. ```php ``` -------------------------------- ### POST /api/v1/auth/login Source: https://documentation.hook0.com/reference/authlogin Logs in a user and returns an access token using their credentials. ```APIDOC ## POST /api/v1/auth/login ### Description Get an access token using a user's credentials. ### Method POST ### Endpoint /api/v1/auth/login #### Request Body - **email** (string) - Required - The user's email address. - **password** (string) - Required - The user's password. ### Request Example ```json { "email": "user@example.com", "password": "your_password" } ``` ### Response #### Success Response (201) - **access_token** (string) - The access token for authenticated requests. - **access_token_expiration** (string) - The expiration date and time of the access token. - **email** (string) - The user's email address. - **first_name** (string) - The user's first name. - **last_name** (string) - The user's last name. - **refresh_token** (string) - The refresh token for obtaining new access tokens. - **refresh_token_expiration** (string) - The expiration date and time of the refresh token. - **user_id** (string) - The unique identifier for the user. #### Response Example ```json { "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "access_token_expiration": "2024-07-10T10:00:00Z", "email": "user@example.com", "first_name": "John", "last_name": "Doe", "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "refresh_token_expiration": "2024-08-09T10:00:00Z", "user_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` #### Error Responses - **400** Bad Request - **403** Forbidden - **404** Not Found - **409** Conflict - **500** Internal Server Error ```