06-22-2024 04:26 PM
Hi Friends — I need some help with the new_event trigger in this custom connector. The trigger passes validation & testing done via the SDK development screen, but it throws a 400 error if I try to start a recipe with it.
Below are some screenshots and the code for the custom connector. API documentation here.
Is there any way for me to see the HTTP request Workato is making when I the trigger is executed? Any tips or words of encouragement appreciated 😅
Successful Test in Postman:
Successful Test in Workato:
Failed Recipe:
Code:
{
title: 'Basecamp',
connection: {
fields: [
{
name: 'client_id',
label: 'Client ID',
hint: 'You can find your client ID in your OAuth app settings',
optional: false
},
{
name: 'client_secret',
label: 'Client Secret',
hint: 'You can find your client secret in your OAuth app settings',
optional: false,
control_type: 'password'
},
{
name: 'account_id',
label: 'Account ID',
hint: 'https://3.basecamp.com/XXXXXXX',
optional: false,
control_type: 'text'
}
],
authorization: {
type: 'oauth2',
client_id: lambda do |connection|
connection['client_id']
end,
client_secret: lambda do |connection|
connection['client_secret']
end,
authorization_url: lambda do |connection|
"https://launchpad.37signals.com/authorization/new?type=web_server&client_id=#{connection['client_id']}&redirect_uri=https://www.workato.com/oauth/callback"
end,
acquire: lambda do |connection, auth_code, redirect_uri|
response = post('https://launchpad.37signals.com/authorization/token').
payload(
type: 'web_server',
code: auth_code,
client_id: connection['client_id'],
client_secret: connection['client_secret'],
redirect_uri: redirect_uri
).
request_format_www_form_urlencoded
{
access_token: response["access_token"],
refresh_token: response["refresh_token"],
expires_at: Time.now + response["expires_in"].to_i.seconds
}
end,
refresh: lambda do |connection, refresh_token|
response = post('https://launchpad.37signals.com/authorization/token').
payload(
type: 'refresh',
refresh_token: refresh_token,
client_id: connection['client_id'],
client_secret: connection['client_secret']
).
request_format_www_form_urlencoded
{
access_token: response["access_token"],
refresh_token: response["refresh_token"],
expires_at: Time.now + response["expires_in"].to_i.seconds
}
end,
refresh_on: [401],
apply: lambda do |_connection, access_token|
headers('Authorization': "Bearer #{access_token}")
end
},
base_uri: lambda do |connection|
"https://3.basecampapi.com/#{connection['account_id']}/"
end
},
triggers: {
new_event: {
title: 'New Event',
subtitle: 'Triggers when a new event occurs in Basecamp',
description: 'Triggers when a specified event happens in Basecamp',
input_fields: lambda do
[
{
name: 'project_id',
label: 'Project ID',
optional: false,
hint: 'ID of the Basecamp project to monitor for events'
},
{
name: 'event_types',
label: 'Event Types',
type: 'string',
control_type: 'text',
optional: false,
hint: 'No spaces allowed! Events to monitor (ex: ToDo,Todolist,Comment,Message,Upload)'
}
]
end,
webhook_subscribe: lambda do |webhook_url, connection, input, recipe_id|
response = post("https://3.basecampapi.com/#{connection['account_id']}/buckets/#{input['project_id']}/webhooks.json",
payload_url: webhook_url,
types: input['event_types'].split(","))
end,
webhook_unsubscribe: lambda do |webhook, connection|
delete("https://3.basecampapi.com/#{connection['account_id']}/buckets/#{webhook['project_id']}/webhooks/#{webhook['id']}.json")
end,
webhook_notification: lambda do |input, payload, extended_input_schema, extended_output_schema, headers, params|
payload["data"]
end,
dedup: lambda do |event|
event['id']
end,
output_fields: lambda do |object_definitions|
object_definitions['event']
end
}
},
actions: {
},
object_definitions: {
event: {
fields: lambda do
# removed for brevity
end
}
}
}
Solved! Go to Solution.
06-22-2024 05:01 PM - edited 06-22-2024 05:02 PM
omg nvm I got it sorted. Here is the corrected triggers block, for anyone interested:
triggers: {
new_event: {
title: 'New Event',
subtitle: 'Triggers when a new event occurs in Basecamp',
description: 'Triggers when a specified event happens in Basecamp',
input_fields: lambda do
[
{
name: 'project_id',
label: 'Project ID',
type: 'string',
optional: false,
hint: 'ID of the Basecamp project to monitor for events'
},
{
name: 'event_types',
label: 'Event Types',
type: 'string',
control_type: 'text',
optional: false,
hint: 'No spaces allowed! Events to monitor (ex: ToDo,Todolist,Comment,Message,Upload)'
}
]
end,
webhook_subscribe: lambda do |webhook_url, connection, input, recipe_id|
response = post("https://3.basecampapi.com/#{connection['account_id']}/buckets/#{input['project_id']}/webhooks.json",
payload_url: webhook_url)
end,
webhook_unsubscribe: lambda do |webhook, connection|
delete("https://3.basecampapi.com/#{connection['account_id']}/buckets/#{webhook['project_id']}/webhooks/#{webhook['id']}.json")
end,
webhook_notification: lambda do |input, payload, extended_input_schema, extended_output_schema, headers, params|
payload
end,
dedup: lambda do |event|
event['id']
end,
output_fields: lambda do |object_definitions|
object_definitions['event']
end
}
}
06-22-2024 05:01 PM - edited 06-22-2024 05:02 PM
omg nvm I got it sorted. Here is the corrected triggers block, for anyone interested:
triggers: {
new_event: {
title: 'New Event',
subtitle: 'Triggers when a new event occurs in Basecamp',
description: 'Triggers when a specified event happens in Basecamp',
input_fields: lambda do
[
{
name: 'project_id',
label: 'Project ID',
type: 'string',
optional: false,
hint: 'ID of the Basecamp project to monitor for events'
},
{
name: 'event_types',
label: 'Event Types',
type: 'string',
control_type: 'text',
optional: false,
hint: 'No spaces allowed! Events to monitor (ex: ToDo,Todolist,Comment,Message,Upload)'
}
]
end,
webhook_subscribe: lambda do |webhook_url, connection, input, recipe_id|
response = post("https://3.basecampapi.com/#{connection['account_id']}/buckets/#{input['project_id']}/webhooks.json",
payload_url: webhook_url)
end,
webhook_unsubscribe: lambda do |webhook, connection|
delete("https://3.basecampapi.com/#{connection['account_id']}/buckets/#{webhook['project_id']}/webhooks/#{webhook['id']}.json")
end,
webhook_notification: lambda do |input, payload, extended_input_schema, extended_output_schema, headers, params|
payload
end,
dedup: lambda do |event|
event['id']
end,
output_fields: lambda do |object_definitions|
object_definitions['event']
end
}
}