Zapier integration (#491)
* create zapier app * install sanctum * move OAuthProviderController * make `api-external` middleware * add zapier endpoints * add tests * token management * zapier event handler * add policy * use `slug` instead of `id` * wip * check policies * change api prefix to `external` * ui tweaks * validate token abilities * open zapier URL * zapier ui tweaks * update zap * Fix linting * Added sample endpoints + minor UI changes * Run PHP code linter --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
37
integrations/zapier/triggers/list_forms.js
vendored
Normal file
37
integrations/zapier/triggers/list_forms.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
module.exports = {
|
||||
operation: {
|
||||
perform: {
|
||||
headers: { Accept: 'application/json' },
|
||||
params: {
|
||||
api_key: '{{bundle.authData.api_key}}',
|
||||
workspace_id: '{{bundle.inputData.workspace_id}}',
|
||||
},
|
||||
removeMissingValuesFrom: { body: false, params: false },
|
||||
url: '{{process.env.BASE_URL}}/external/zapier/forms',
|
||||
},
|
||||
inputFields: [
|
||||
{
|
||||
key: 'workspace_id',
|
||||
type: 'string',
|
||||
dynamic: 'list_workspaces.id.name',
|
||||
label: 'Workspace',
|
||||
required: true,
|
||||
list: false,
|
||||
altersDynamicFields: false,
|
||||
},
|
||||
],
|
||||
sample: { id: 'my-form', name: 'My Form' },
|
||||
outputFields: [
|
||||
{ key: 'id', label: 'ID', type: 'string' },
|
||||
{ key: 'name', label: 'Name', type: 'string' },
|
||||
],
|
||||
canPaginate: false,
|
||||
},
|
||||
display: {
|
||||
description: 'Get the list of all forms',
|
||||
hidden: true,
|
||||
label: 'List Forms',
|
||||
},
|
||||
key: 'list_forms',
|
||||
noun: 'Form',
|
||||
};
|
||||
21
integrations/zapier/triggers/list_workspaces.js
vendored
Normal file
21
integrations/zapier/triggers/list_workspaces.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
module.exports = {
|
||||
operation: {
|
||||
perform: {
|
||||
headers: { Accept: 'application/json' },
|
||||
removeMissingValuesFrom: { body: false, params: false },
|
||||
url: '{{process.env.BASE_URL}}/external/zapier/workspaces',
|
||||
},
|
||||
sample: { id: 1, name: 'My Workspace' },
|
||||
outputFields: [
|
||||
{ key: 'id', label: 'ID', type: 'integer' },
|
||||
{ key: 'name', label: 'Name', type: 'string' },
|
||||
],
|
||||
},
|
||||
display: {
|
||||
description: "Get the list of all user's workspaces",
|
||||
hidden: true,
|
||||
label: 'List Workspaces',
|
||||
},
|
||||
key: 'list_workspaces',
|
||||
noun: 'Workspace',
|
||||
};
|
||||
81
integrations/zapier/triggers/new_submission.js
vendored
Normal file
81
integrations/zapier/triggers/new_submission.js
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
const perform = async (z, bundle) => {
|
||||
return [bundle.cleanedRequest];
|
||||
};
|
||||
|
||||
const performList = async (z, bundle) => {
|
||||
// Replace with the actual URL that returns recent submissions
|
||||
const response = await z.request({
|
||||
url: `${process.env.BASE_URL}/external/zapier/submissions/recent`,
|
||||
params: {
|
||||
form_id: bundle.inputData.form_id,
|
||||
},
|
||||
});
|
||||
|
||||
// Ensure the structure of the response matches the webhook data structure
|
||||
return response.data;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
operation: {
|
||||
perform: perform,
|
||||
performList: performList,
|
||||
sample: {
|
||||
"form_title": "Your form title",
|
||||
"form_slug": "your-form-slug-og4lhg"
|
||||
},
|
||||
inputFields: [
|
||||
{
|
||||
key: 'workspace_id',
|
||||
type: 'string',
|
||||
label: 'Workspace',
|
||||
dynamic: 'list_workspaces.id.name',
|
||||
required: true,
|
||||
list: false,
|
||||
altersDynamicFields: true,
|
||||
},
|
||||
{
|
||||
key: 'form_id',
|
||||
type: 'string',
|
||||
label: 'Form',
|
||||
dynamic: 'list_forms.id.name',
|
||||
required: true,
|
||||
list: false,
|
||||
altersDynamicFields: false,
|
||||
},
|
||||
],
|
||||
type: 'hook',
|
||||
performUnsubscribe: {
|
||||
body: {
|
||||
hookUrl: '{{bundle.subscribeData.id}}',
|
||||
form_id: '{{bundle.inputData.form_id}}',
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
method: 'DELETE',
|
||||
removeMissingValuesFrom: { body: false, params: false },
|
||||
url: '{{process.env.BASE_URL}}/external/zapier/webhook',
|
||||
},
|
||||
performSubscribe: {
|
||||
body: {
|
||||
hookUrl: '{{bundle.targetUrl}}',
|
||||
form_id: '{{bundle.inputData.form_id}}',
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
removeMissingValuesFrom: { body: false, params: false },
|
||||
url: '{{process.env.BASE_URL}}/external/zapier/webhook',
|
||||
},
|
||||
},
|
||||
display: {
|
||||
description: 'Triggers when a new submission is created.',
|
||||
hidden: false,
|
||||
label: 'New Submission',
|
||||
},
|
||||
key: 'new_submission',
|
||||
noun: 'Submission',
|
||||
};
|
||||
Reference in New Issue
Block a user