Endpoint Workflows
Handle incoming HTTP requests with custom logic. Endpoint workflows allow you to create custom API endpoints backed by your own business logic, with access to identity, integrations, and offer engine utilities.
Usage
const workflow: EndpointWorkflow = async ({ request }: EndpointWorkflowArgs): Promise<EndpointWorkflowResult> => {
const path = new URL(request.url).pathname;
return new Response(`hello, ${path}`);
};
export default workflow;Invocation
Endpoint workflows are executed when the configured endpoint path receives an HTTP request, find more about Endpoint URLs here.
Arguments
See EndpointWorkflowArgs.
Prop
Type
Return Type
The workflow returns EndpointWorkflowResult, which is a standard Web API Response object.
- Can return any valid
Responsewith custom status, headers, and body. - Use standard
Responseconstructor:new Response(body, { status, headers }). - Alternatively, use shorthand static methods like:
Response.json()for JSON responses.Response.error()for network errors.Response.redirect()for redirects.
Access Levels
Endpoints are configured with access levels:
- No Key: No authentication required.
- Public Key: Requires public API key authentication.
- Secret Key: Requires API key authentication via
X-MOS-Keyheader.
Access level is configured in the endpoint settings, not in the workflow, and determines who can call the endpoint. If you are not using Secret Key authentication, you must handle authentication and authorization within the workflow code as needed.
Common Use Cases
- Build custom API endpoints for your application
- Implement webhook listeners to receive external events
- Create data transformation or proxy endpoints
- Expose offer redemption or identity lookup APIs
- Integrate with third-party services requiring custom endpoints