SDK
HTTP Reference
HttpEndpoint
HttpEndpoint
allows you to create and HttpTrigger, which means you can trigger your Jobs from any webhooks
const caldotcom = client.defineHttpEndpoint({
//this should be unique inside your project
id: "cal.com",
//usually you'd use the domain name of the service
source: "cal.com",
//the icon is optional, it displays in the dashboard
icon: "caldotcom",
//this function is called when a webhook is received
verify: async (request) => {
//this is a useful helper function that can verify sha256 signatures
//each API has a different header name
return await verifyRequestSignature({
request,
//you can find the header name in the API's documentation
headerName: "X-Cal-Signature-256",
//you can find the secret in the Trigger.dev dashboard, on the HTTP endpoint page
secret: process.env.CALDOTCOM_SECRET!,
algorithm: "sha256",
});
},
});
client.defineJob({
id: "http-caldotcom",
name: "HTTP Cal.com",
version: "1.0.0",
enabled: true,
//this create a Trigger using the caldotcom endpoint
trigger: caldotcom.onRequest(),
run: async (request, io, ctx) => {
//note that when using HTTP endpoints, the first parameter is the request
//you need to get the body, usually it will be json so you do:
const body = await request.json();
await io.logger.info(`Body`, body);
},
});
There are two steps to using an HttpEndpoint
:
- Use client.defineHttpEndpoint() to create an
HttpEndpoint
. - Use onRequest() to create an
HttpTrigger
. This method is shown below.
You can see a complete example on this page.
Creating an HttpEndpoint
Use client.defineHttpEndpoint() to create an HttpEndpoint
.
Methods
onRequest()
You don’t need to provide any options to onRequest()
. But you can provide a filter – if an incoming request matches the filter then the Job will run.
Only Requests that match this filter will cause the corresponding function to run. For example, you can use this to only allow GET
Requests.
An array of HTTP methods to match. For example, ["GET", "POST"]
will match both GET
and POST
Requests.
An object of query parameters to match. This uses the EventFilter matching syntax.
filter: {
query: {
"hub.mode": [{ $startsWith: "sub" }],
},
},
An object of header key/values to match. This uses the EventFilter matching syntax.
filter: {
header: {
"content-type": ["application/json"],
},
},
An object of key/values to match. This uses the EventFilter matching syntax.
const caldotcom = client.defineHttpEndpoint({
//this should be unique inside your project
id: "cal.com",
//usually you'd use the domain name of the service
source: "cal.com",
//the icon is optional, it displays in the dashboard
icon: "caldotcom",
//this function is called when a webhook is received
verify: async (request) => {
//this is a useful helper function that can verify sha256 signatures
//each API has a different header name
return await verifyRequestSignature({
request,
//you can find the header name in the API's documentation
headerName: "X-Cal-Signature-256",
//you can find the secret in the Trigger.dev dashboard, on the HTTP endpoint page
secret: process.env.CALDOTCOM_SECRET!,
algorithm: "sha256",
});
},
});
client.defineJob({
id: "http-caldotcom",
name: "HTTP Cal.com",
version: "1.0.0",
enabled: true,
//this create a Trigger using the caldotcom endpoint
trigger: caldotcom.onRequest(),
run: async (request, io, ctx) => {
//note that when using HTTP endpoints, the first parameter is the request
//you need to get the body, usually it will be json so you do:
const body = await request.json();
await io.logger.info(`Body`, body);
},
});
Was this page helpful?
const caldotcom = client.defineHttpEndpoint({
//this should be unique inside your project
id: "cal.com",
//usually you'd use the domain name of the service
source: "cal.com",
//the icon is optional, it displays in the dashboard
icon: "caldotcom",
//this function is called when a webhook is received
verify: async (request) => {
//this is a useful helper function that can verify sha256 signatures
//each API has a different header name
return await verifyRequestSignature({
request,
//you can find the header name in the API's documentation
headerName: "X-Cal-Signature-256",
//you can find the secret in the Trigger.dev dashboard, on the HTTP endpoint page
secret: process.env.CALDOTCOM_SECRET!,
algorithm: "sha256",
});
},
});
client.defineJob({
id: "http-caldotcom",
name: "HTTP Cal.com",
version: "1.0.0",
enabled: true,
//this create a Trigger using the caldotcom endpoint
trigger: caldotcom.onRequest(),
run: async (request, io, ctx) => {
//note that when using HTTP endpoints, the first parameter is the request
//you need to get the body, usually it will be json so you do:
const body = await request.json();
await io.logger.info(`Body`, body);
},
});