{
	"metadata": {
		"label": "Hoko",
		"description": "Create and find Hoko links, and receive signed link.created events in Make.",
		"visibility": "private",
		"distribution": "editor-sections"
	},
	"base": {
		"baseUrl": "https://api.hoko.to",
		"headers": {
			"Authorization": "Bearer {{connection.apiKey}}"
		},
		"log": {
			"sanitize": [
				"request.headers.authorization"
			]
		},
		"timeout": 10000,
		"followAllRedirect": false,
		"followRedirect": false,
		"response": {
			"type": "json",
			"error": {
				"401": {
					"type": "InvalidAccessTokenError",
					"message": "Hoko API key is invalid or revoked."
				},
				"403": {
					"type": "InvalidConfigurationError",
					"message": "Hoko API key lacks a required scope."
				},
				"429": {
					"type": "RuntimeError",
					"message": "Hoko rate limit reached. Reconcile writes before retrying."
				},
				"type": "RuntimeError",
				"message": "[{{statusCode}}] Hoko request failed; reconcile uncertain writes. Request ID={{ifempty(get(headers, \"x-request-id\"), get(headers, \"X-Request-Id\"))}}"
			}
		}
	},
	"connection": {
		"type": "basic",
		"label": "Hoko API key",
		"parameters": [
			{
				"name": "apiKey",
				"label": "API key",
				"type": "password",
				"required": true
			}
		],
		"communication": {
			"type": "json",
			"method": "GET",
			"url": "https://api.hoko.to/links?take=1",
			"headers": {
				"Authorization": "Bearer {{parameters.apiKey}}"
			},
			"log": {
				"sanitize": [
					"request.headers.authorization",
					"parameters.apiKey"
				]
			},
			"response": {
				"valid": {
					"condition": "{{statusCode == 200}}",
					"message": "Hoko API key was rejected.",
					"type": "InvalidAccessTokenError"
				}
			}
		}
	},
	"webhooks": {
		"hokoLinkCreated": {
			"type": "webhook",
			"connection": "connection",
			"parameters": [
				{
					"name": "relayUrl",
					"label": "Verified relay URL",
					"type": "url",
					"required": true,
					"help": "The customer-owned HTTPS endpoint that verifies Hoko signatures and forwards trusted events to Make."
				},
				{
					"name": "relayAuthToken",
					"label": "Relay auth token",
					"type": "password",
					"required": true,
					"help": "A relay_ token containing 256 bits of entropy. Make accepts only forwards carrying this token."
				},
				{
					"name": "hokoSigningSecret",
					"label": "Hoko signing secret",
					"type": "password",
					"required": true,
					"help": "The whsec_ secret configured in the customer-owned relay. Generate it once and use the same value here and in the relay."
				}
			],
			"label": "Hoko link.created events",
			"description": "Receive verified Hoko link.created events through a customer-owned relay. Direct unauthenticated callbacks are rejected; delivery does not guarantee exactly-once execution.",
			"attach": {
				"method": "POST",
				"url": "/webhooks",
				"body": {
					"name": "Make link.created trigger {{webhook.id}}",
					"url": "{{parameters.relayUrl}}",
					"events": [
						"link.created"
					],
					"signingSecret": "{{parameters.hokoSigningSecret}}"
				},
				"response": {
					"data": {
						"endpointId": "{{body.endpoint.id}}",
						"endpointName": "{{body.endpoint.name}}"
					}
				},
				"log": {
					"sanitize": [
						"request.headers.authorization",
						"request.body.signingSecret",
						"parameters.hokoSigningSecret",
						"response.body.signingSecret"
					]
				}
			},
			"detach": {
				"method": "DELETE",
				"url": "/webhooks/{{webhook.endpointId}}",
				"body": {
					"confirmationName": "{{webhook.endpointName}}"
				},
				"log": {
					"sanitize": [
						"request.headers.authorization"
					]
				}
			},
			"condition": "{{get(headers, \"x-hoko-relay-auth\") == parameters.relayAuthToken && get(headers, \"x-hoko-relay-event-id\") != \"\" && get(headers, \"x-hoko-relay-timestamp\") != \"\" && get(headers, \"x-hoko-relay-signature\") != \"\"}}",
			"respond": {
				"status": 202,
				"type": "json",
				"body": {
					"received": true
				}
			},
			"output": "{{body}}"
		}
	},
	"modules": {
		"createLink": {
			"type": "action",
			"label": "Create Link",
			"parameters": [
				{
					"type": "url",
					"required": true,
					"validate": {
						"min": 1,
						"max": 2048,
						"pattern": "^https?://[^/?#@\\s]+(?:[/?#][^\\s]*)?$"
					},
					"name": "url",
					"label": "Destination URL"
				},
				{
					"type": "text",
					"required": true,
					"validate": {
						"min": 1,
						"max": 255,
						"pattern": "^.+$"
					},
					"name": "collectionId",
					"label": "Collection ID"
				},
				{
					"type": "text",
					"required": true,
					"validate": {
						"min": 1,
						"max": 255,
						"pattern": "^.+$"
					},
					"name": "externalId",
					"label": "External ID"
				},
				{
					"type": "text",
					"required": true,
					"validate": {
						"min": 1,
						"max": 128,
						"pattern": "^[\\x21-\\x7e]{1,128}$"
					},
					"name": "requestId",
					"label": "Request ID",
					"help": "Stable printable request ID for reconciliation."
				}
			],
			"interface": [
				{
					"name": "id",
					"type": "text",
					"label": "Link ID"
				},
				{
					"name": "url",
					"type": "url",
					"label": "Destination URL"
				},
				{
					"name": "shortUrl",
					"type": "url",
					"label": "Short URL"
				},
				{
					"name": "collectionId",
					"type": "text",
					"label": "Collection ID"
				},
				{
					"name": "externalId",
					"type": "text",
					"label": "External ID"
				},
				{
					"name": "requestId",
					"type": "text",
					"label": "Request ID"
				},
				{
					"name": "rateLimit",
					"type": "collection",
					"label": "Rate limit",
					"spec": [
						{
							"name": "limit",
							"type": "uinteger",
							"label": "Rate limit"
						},
						{
							"name": "remaining",
							"type": "uinteger",
							"label": "Rate remaining"
						},
						{
							"name": "resetAt",
							"type": "uinteger",
							"label": "Rate reset timestamp"
						}
					]
				}
			],
			"communication": {
				"type": "json",
				"method": "POST",
				"url": "/links",
				"body": [
					{
						"url": "{{parameters.url}}",
						"collectionId": "{{parameters.collectionId}}",
						"externalId": "{{parameters.externalId}}"
					}
				],
				"headers": {
					"Content-Type": "application/json",
					"X-Request-Id": "{{parameters.requestId}}"
				},
				"response": {
					"valid": {
						"condition": "{{(statusCode == 200 || statusCode == 201) && length(body) == 1 && ifempty(body[1].id, \"\") != \"\" && body[1].url == parameters.url && ifempty(body[1].shortUrl, \"\") != \"\" && body[1].collectionId == parameters.collectionId && body[1].externalId == parameters.externalId && ifempty(get(headers, \"x-request-id\"), get(headers, \"X-Request-Id\")) == parameters.requestId && ifempty(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\")), \"\") != \"\" && ifempty(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\")), \"\") != \"\" && ifempty(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\")), \"\") != \"\" && parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\"))) >= 0 && parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\"))) <= 1000000000 && floor(parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\")))) == parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\"))) && parseNumber(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\"))) >= 0 && parseNumber(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\"))) <= parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\"))) && floor(parseNumber(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\")))) == parseNumber(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\"))) && parseNumber(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\"))) >= 0 && parseNumber(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\"))) <= 4102444800 && floor(parseNumber(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\")))) == parseNumber(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\")))}}",
						"message": "Create response must contain exactly one matching link and request ID.",
						"type": "RuntimeError"
					},
					"output": {
						"id": "{{body[1].id}}",
						"url": "{{body[1].url}}",
						"shortUrl": "{{body[1].shortUrl}}",
						"collectionId": "{{body[1].collectionId}}",
						"externalId": "{{body[1].externalId}}",
						"requestId": "{{ifempty(get(headers, \"x-request-id\"), get(headers, \"X-Request-Id\"))}}",
						"rateLimit": {
							"limit": "{{parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\")))}}",
							"remaining": "{{parseNumber(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\")))}}",
							"resetAt": "{{parseNumber(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\")))}}"
						}
					}
				}
			}
		},
		"findLink": {
			"type": "action",
			"label": "Find Link",
			"parameters": [
				{
					"type": "text",
					"required": true,
					"validate": {
						"min": 1,
						"max": 255,
						"pattern": "^.+$"
					},
					"name": "externalId",
					"label": "External ID"
				},
				{
					"type": "text",
					"required": true,
					"validate": {
						"min": 1,
						"max": 128,
						"pattern": "^[\\x21-\\x7e]{1,128}$"
					},
					"name": "requestId",
					"label": "Request ID",
					"help": "Stable printable request ID for reconciliation."
				}
			],
			"interface": [
				{
					"name": "matches",
					"type": "array",
					"label": "Matching links",
					"spec": [
						{
							"name": "id",
							"type": "text",
							"label": "Link ID"
						},
						{
							"name": "url",
							"type": "url",
							"label": "Destination URL"
						},
						{
							"name": "shortUrl",
							"type": "url",
							"label": "Short URL"
						},
						{
							"name": "collectionId",
							"type": "text",
							"label": "Collection ID"
						},
						{
							"name": "externalId",
							"type": "text",
							"label": "External ID"
						}
					]
				},
				{
					"name": "matchCount",
					"type": "uinteger",
					"label": "Match count"
				},
				{
					"name": "requestId",
					"type": "text",
					"label": "Request ID"
				},
				{
					"name": "rateLimit",
					"type": "collection",
					"label": "Rate limit",
					"spec": [
						{
							"name": "limit",
							"type": "uinteger",
							"label": "Rate limit"
						},
						{
							"name": "remaining",
							"type": "uinteger",
							"label": "Rate remaining"
						},
						{
							"name": "resetAt",
							"type": "uinteger",
							"label": "Rate reset timestamp"
						}
					]
				}
			],
			"communication": {
				"type": "json",
				"method": "GET",
				"url": "/links?externalId={{encodeURL(parameters.externalId)}}&take=2&skip=0&sort=desc",
				"headers": {
					"Content-Type": "application/json",
					"X-Request-Id": "{{parameters.requestId}}"
				},
				"response": {
					"valid": {
						"condition": "{{statusCode == 200 && length(body) <= 2 && (length(body) == 0 || (ifempty(body[1].id, \"\") != \"\" && ifempty(body[1].url, \"\") != \"\" && ifempty(body[1].shortUrl, \"\") != \"\" && ifempty(body[1].collectionId, \"\") != \"\" && body[1].externalId == parameters.externalId)) && (length(body) < 2 || (ifempty(body[2].id, \"\") != \"\" && ifempty(body[2].url, \"\") != \"\" && ifempty(body[2].shortUrl, \"\") != \"\" && ifempty(body[2].collectionId, \"\") != \"\" && body[2].externalId == parameters.externalId)) && ifempty(get(headers, \"x-request-id\"), get(headers, \"X-Request-Id\")) == parameters.requestId && ifempty(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\")), \"\") != \"\" && ifempty(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\")), \"\") != \"\" && ifempty(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\")), \"\") != \"\" && parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\"))) >= 0 && parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\"))) <= 1000000000 && floor(parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\")))) == parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\"))) && parseNumber(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\"))) >= 0 && parseNumber(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\"))) <= parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\"))) && floor(parseNumber(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\")))) == parseNumber(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\"))) && parseNumber(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\"))) >= 0 && parseNumber(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\"))) <= 4102444800 && floor(parseNumber(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\")))) == parseNumber(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\")))}}",
						"message": "Lookup response must contain at most two matching links and the echoed request ID.",
						"type": "RuntimeError"
					},
					"iterate": "{{body}}",
					"output": {
						"id": "{{item.id}}",
						"url": "{{item.url}}",
						"shortUrl": "{{item.shortUrl}}",
						"collectionId": "{{item.collectionId}}",
						"externalId": "{{item.externalId}}"
					},
					"wrapper": {
						"matches": "{{output}}",
						"matchCount": "{{length(body)}}",
						"requestId": "{{ifempty(get(headers, \"x-request-id\"), get(headers, \"X-Request-Id\"))}}",
						"rateLimit": {
							"limit": "{{parseNumber(ifempty(get(headers, \"x-ratelimit-limit\"), get(headers, \"X-RateLimit-Limit\")))}}",
							"remaining": "{{parseNumber(ifempty(get(headers, \"x-ratelimit-remaining\"), get(headers, \"X-RateLimit-Remaining\")))}}",
							"resetAt": "{{parseNumber(ifempty(get(headers, \"x-ratelimit-reset\"), get(headers, \"X-RateLimit-Reset\")))}}"
						}
					}
				}
			}
		},
		"watchLinkCreated": {
			"type": "instant",
			"label": "Watch Link Created",
			"description": "Triggers once for each link.created event forwarded by the verified customer-owned relay. Delivery is bounded and does not guarantee exactly-once execution.",
			"webhook": "hokoLinkCreated",
			"parameters": [],
			"interface": [
				{
					"name": "id",
					"type": "text",
					"label": "Event ID"
				},
				{
					"name": "type",
					"type": "text",
					"label": "Event type"
				},
				{
					"name": "created",
					"type": "date",
					"label": "Created at"
				},
				{
					"name": "data",
					"type": "collection",
					"label": "Event data",
					"spec": [
						{
							"name": "id",
							"type": "text",
							"label": "Link ID"
						},
						{
							"name": "workspaceId",
							"type": "text",
							"label": "Workspace ID"
						}
					]
				}
			],
			"samples": [
				{
					"id": "01JLINKCREATEDMAKE0000000000",
					"type": "link.created",
					"created": "2026-01-01T00:00:00.000Z",
					"data": {
						"id": "01JLINK00000000000000000000",
						"workspaceId": "01JWORKSPACE000000000000000"
					}
				}
			]
		}
	}
}
