feat(surveymonkey): add create contact action
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create contact',
|
||||
key: 'createContact',
|
||||
description: 'Creates a new contact in your address book.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'First Name',
|
||||
key: 'firstName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Last Name',
|
||||
key: 'lastName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Email',
|
||||
key: 'email',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Contact List',
|
||||
key: 'contactListId',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listContactLists',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const { firstName, lastName, email, contactListId } = $.step.parameters;
|
||||
let url = '/v3/contacts';
|
||||
|
||||
if (contactListId) {
|
||||
url = `/v3/contact_lists/${contactListId}/contacts`;
|
||||
}
|
||||
|
||||
const body = {
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
email,
|
||||
};
|
||||
|
||||
const { data } = await $.http.post(url, body);
|
||||
|
||||
$.setActionItem({
|
||||
raw: data,
|
||||
});
|
||||
},
|
||||
});
|
3
packages/backend/src/apps/surveymonkey/actions/index.js
Normal file
3
packages/backend/src/apps/surveymonkey/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import createContact from './create-contact/index.js';
|
||||
|
||||
export default [createContact];
|
@@ -1,3 +1,4 @@
|
||||
import listContactLists from './list-contact-lists/index.js';
|
||||
import listSurveys from './list-surveys/index.js';
|
||||
|
||||
export default [listSurveys];
|
||||
export default [listSurveys, listContactLists];
|
||||
|
@@ -0,0 +1,36 @@
|
||||
export default {
|
||||
name: 'List contact lists',
|
||||
key: 'listContactLists',
|
||||
|
||||
async run($) {
|
||||
const contactLists = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 100,
|
||||
};
|
||||
|
||||
let fetchedSum = 0;
|
||||
let total;
|
||||
do {
|
||||
const { data } = await $.http.get('/v3/contact_lists', { params });
|
||||
|
||||
params.page = params.page + 1;
|
||||
fetchedSum = fetchedSum + params.per_page;
|
||||
total = data.total;
|
||||
|
||||
if (data.data) {
|
||||
for (const contactList of data.data) {
|
||||
contactLists.data.push({
|
||||
value: contactList.id,
|
||||
name: contactList.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (fetchedSum <= total);
|
||||
|
||||
return contactLists;
|
||||
},
|
||||
};
|
@@ -4,6 +4,7 @@ import auth from './auth/index.js';
|
||||
import setBaseUrl from './common/set-base-url.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
import actions from './actions/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'SurveyMonkey',
|
||||
@@ -18,4 +19,5 @@ export default defineApp({
|
||||
auth,
|
||||
triggers,
|
||||
dynamicData,
|
||||
actions,
|
||||
});
|
||||
|
@@ -442,6 +442,8 @@ export default defineConfig({
|
||||
collapsible: true,
|
||||
collapsed: true,
|
||||
items: [
|
||||
{ text: 'Triggers', link: '/apps/surveymonkey/triggers' },
|
||||
{ text: 'Actions', link: '/apps/surveymonkey/actions' },
|
||||
{ text: 'Connection', link: '/apps/surveymonkey/connection' },
|
||||
],
|
||||
},
|
||||
|
12
packages/docs/pages/apps/surveymonkey/actions.md
Normal file
12
packages/docs/pages/apps/surveymonkey/actions.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
favicon: /favicons/surveymonkey.svg
|
||||
items:
|
||||
- name: Create contact
|
||||
desc: Creates a new contact in your address book.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import CustomListing from '../../components/CustomListing.vue'
|
||||
</script>
|
||||
|
||||
<CustomListing />
|
Reference in New Issue
Block a user