Custom HTTP endpoints
Give your Python code its own URL, so forms, web pages and other systems can call into Octocom.
A custom HTTP endpoint gives your Python code its own URL. Anything outside Octocom can call it, and your handle(context) function decides what happens. For example, a supplier opens a review link and approves a replacement, and the endpoint records the decision so the AI agent can follow up with the customer. Changes take effect on the next request, with nothing to deploy.
Use one for help-center forms, review pages and callbacks from a warehouse or payment system.
Choose the building block by direction:
| Direction | Use |
|---|---|
| Another system or a web page calls Octocom and your code decides what happens | A custom HTTP endpoint (this page) |
| Another system reads or changes Octocom data directly | The REST API |
| Octocom tells another system that something happened | A webhook or event handler |
| The AI agent calls another system during a conversation | A custom action |
Endpoints are built for human-driven workflows and integration callbacks, not high-volume APIs. See Limits and retries. For a complete example, see the external decisions playbook, where an endpoint backs a supplier's review page.
Create an endpoint
Open Settings -> Advanced -> HTTP Endpoints, select Create endpoint, and enter a name and Python code. Select the allowed methods and save. Copy the generated URL from the editor.
Endpoints belong to the selected business. Their URLs remain stable when you rename or edit them. Disable an endpoint to stop execution immediately; disabled and deleted URLs return 404.
def handle(context):
body = context["request"]["body"]
if not isinstance(body, dict) or not isinstance(body.get("name"), str):
return http_response({"error": "Please provide your name"}, status=422)
return {"message": f"Hello, {body['name']}!"}POST JSON to the URL:
const response = await fetch(endpointUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "Alex" }),
credentials: "omit",
});
const result = await response.json();Browser cross-origin requests and preflight requests are handled by Octocom. Preflight requests do not run your code. These endpoints do not use dashboard login cookies as authentication.
GET and POST
POST is the default. Use it to submit forms, change state, or trigger actions. Enable GET when you need to retrieve data. The endpoint receives the actual method; unconfigured methods return 405 without executing your code.
Do not perform mutations on GET. An email button should open a page where a confirmation button sends POST. Merely opening a link, including an automated preview, should not make the decision.
Endpoints accept GET and POST only. Use POST for any change and put the operation in the body.
Request context
Define handle(context). context["request"] has the fields below, context["business"] holds the business name and slug, and the usual Python helpers (get_secret, organization_store_*, ...) are globals, exactly as in custom actions. See Python context and Python helpers.
| Field | Value |
|---|---|
context["business"] | Business name and slug, resolved by Octocom |
context["request"]["id"] | Unique request ID |
context["request"]["method"] | HTTP method |
context["request"]["headers"] | Headers with lowercase names |
context["request"]["query"] | Query values; repeated parameters become lists |
context["request"]["body"] | Parsed JSON, parsed URL-encoded form, text, or None for an empty body |
context["request"]["rawBody"] | Body decoded as UTF-8 |
context["request"]["rawBodyBase64"] | Exact request bytes encoded as base64, for signature verification |
JSON content types include application/json and +json. Malformed JSON returns 400. Multipart uploads are not parsed into files: store the file elsewhere and send its URL or ID in the request body.
Caller input cannot replace the trusted business or organization context. There is no automatically selected conversation or customer: a conversation ID in the body is untrusted input, and your code must check whether the caller may act on it before using conversation helpers.
Authentication is your code
Invocation URLs have no built-in authentication. Public contact forms can accept public submissions. If your endpoint needs authentication, verify it at the beginning of handle, before any side effects.
For a server-to-server token check, store WAREHOUSE_ENDPOINT_TOKEN in Secrets, then:
import hmac
def handle(context):
supplied = context["request"]["headers"].get("authorization")
expected = "Bearer " + get_secret("WAREHOUSE_ENDPOINT_TOKEN")
if not isinstance(supplied, str) or not hmac.compare_digest(supplied, expected):
return http_response({"error": "Unauthorized"}, status=401)
return {"accepted": True}Do not embed a reusable secret in public HTML. For signed callbacks, decode rawBodyBase64 (base64.b64decode) and verify the signature against those exact bytes with hmac/hashlib, following the sender's protocol. Query parameters and headers are not trusted merely because they exist.
Responses
Return any JSON-serializable value for a 200 response. To choose the status or supported headers, use:
def handle(context):
return http_response(
{"error": "Please try again later"},
status=429,
headers={"Retry-After": "30"},
)Responses are JSON. Return a JSON-serializable value or http_response(body, status=..., headers=...). Status codes from 200 through 599 are supported; 204, 205, and 304 have no body. Custom headers can be Retry-After, Content-Language, or X-* headers other than the platform-managed X-Request-Id, X-Accel-*, and X-Sendfile. Response headers are limited to 8 KiB in total. Cookies, redirects, HTML, streaming, and binary responses are not supported.
A normal object with status and body keys is still ordinary JSON; only the helper creates an HTTP response envelope. Cache-Control: no-store and X-Request-Id are set by Octocom. Execution failures return a generic error and request ID; full diagnostics are available to authorized authors.
Limits and retries
These endpoints are for human-driven workflows, not high-volume APIs.
| Limit | Default |
|---|---|
| Traffic per caller IP | 10 requests/minute refill, burst capacity 5 |
| Endpoint traffic | 20 requests/minute refill, burst capacity 10 |
| Organization traffic | 30 requests/minute refill, burst capacity 10 |
| Concurrent executions | 2 per endpoint, 5 per organization |
| Execution deadline | 30 seconds, including startup and waiting |
| Request body | 64 KiB |
| Response body | 256 KiB |
The per-IP limit is checked first, so one caller cannot use up an endpoint's budget for everyone else. When a rate or concurrency limit is reached, the endpoint returns 429 with Retry-After; requests are not queued by Octocom. A request with a method the endpoint does not accept gets 405 and uses no budget. Tests share the endpoint and organization limits. Contact Octocom if you need higher limits.
A timeout returns 504. A timeout does not prove that no action happened. Dispatched code or a third-party request can still finish after the HTTP caller stops waiting. Octocom does not automatically retry endpoint executions. Make state changes idempotent when duplicate calls would matter, and inspect the outcome before retrying an uncertain request. A concurrency slot with an uncertain outcome is held for up to five minutes to bound outstanding work.
Test and debug
Save the endpoint, then use Test request. You can test unsaved code in the editor; method settings come from the saved endpoint. Tests work while an endpoint is disabled.
Tests execute real code and may make real writes. They are not a dry run. The result shows the HTTP status, body, headers, duration, request ID, and execution failure details.
Recent requests that reached your code retain metadata for 24 hours: request ID, code revision, timestamp, method, status, duration, and whether the request was a test. Failures additionally retain bounded, secret-redacted error details, the traceback and captured output. Request headers, request bodies, and response bodies are not stored in invocation history. Avoid logging customer data or tokens: authored output can appear in failure diagnostics.
Requests refused before your code runs (429 rate limit, 405 wrong method, 400 malformed JSON, 413 oversized body) are not recorded one by one. list_http_endpoint_invocations returns a count of them per status for the last 24 hours instead.
Invocation records are diagnostics, not a permanent audit trail: they expire after 24 hours, and at most the newest 1,000 records are kept per endpoint. The dashboard shows the latest 100 records. Configuration history is kept separately; inspect and restore it under Version history. Restoring a version also restores its enabled state.
Copilot and MCP
Ask Copilot to create an endpoint, implement the behavior, and test it with a sample request. Available tools:
list_http_endpointsandget_http_endpointcreate_http_endpoint,update_http_endpoint, andarchive_http_endpointtest_http_endpointlist_http_endpoint_invocationslist_http_endpoint_versionsandrestore_http_endpoint_version
Archiving stops the endpoint URL from executing and retains its configuration. Use its version history to restore it; restoring an enabled version makes the endpoint callable again.
Tools are scoped to the selected organization. Creation requires a businessId from that organization. Test tools are writes because the code they run can perform actions.
REST configuration API
The management API uses your normal Octocom X-API-Key. This is separate from invoking the generated URL, where your code defines any authentication.
| Method | Path | Purpose |
|---|---|---|
| GET | /rest/v1/custom-http-endpoints | List endpoint configurations; optionally filter by businessId |
| GET | /rest/v1/custom-http-endpoints/:id | Get configuration and Python code |
| POST | /rest/v1/custom-http-endpoints | Create an endpoint |
| PATCH | /rest/v1/custom-http-endpoints/:id | Update supplied fields |
| DELETE | /rest/v1/custom-http-endpoints/:id | Soft-delete an endpoint |
Create with:
{
"businessId": "YOUR_BUSINESS_UUID",
"name": "Contact form",
"description": "Accept a help-center contact form",
"methods": ["POST"],
"isActive": true,
"language": "python",
"code": "def handle(context):\n return {\"success\": True}"
}language is optional and defaults to "python", the only accepted value.
Responses use a data envelope. Creation returns 201 with the generated invocation URL. List responses omit source code; use the detail route to retrieve it. The API key's organization controls which endpoints and businesses are accessible.
Example: find a phone call's conversation
An endpoint that serves a contact-center or telephony system often needs the Octocom conversation for a call. Organization-scoped Python code can resolve an exact Twilio Call SID through
GET /rest/v1/conversations?twilioCallSid=CA...&businessSlug=your-business.
Use the injected OCTOCOM_API_BASE_URL and OCTOCOM_ORG_API_KEY for that request.
This filter finds calls as soon as they start. Organization, business and
historical-data restrictions still apply. An unknown or inaccessible SID returns an empty data array.
Validate your caller's authentication before any lookup. Accept an external contact ID, map it to a provider SID in your organization store, and restrict the lookup to the intended business. A phone-number match alone cannot tell repeated or simultaneous calls apart. Generate summaries in a separate event handler and let a GET endpoint return the saved results and whether they are ready; keep LLM calls out of time-sensitive routing requests.