feat(pipedrive): add create organization action

This commit is contained in:
Rıdvan Akca
2023-10-18 15:29:42 +03:00
committed by Ali BARIN
parent fb1f520096
commit 0772308bf5
5 changed files with 131 additions and 1 deletions

View File

@@ -0,0 +1,85 @@
import defineAction from '../../../../helpers/define-action';
function filterProvidedFields(body: Record<string, unknown>) {
return Object.keys(body).reduce<Record<string, unknown>>((result, key) => {
if (body[key]) {
result[key] = body[key];
}
return result;
}, {});
}
export default defineAction({
name: 'Create organization',
key: 'createOrganization',
description: 'Creates a new organization.',
arguments: [
{
label: 'Name',
key: 'name',
type: 'string' as const,
required: true,
description: '',
variables: true,
},
{
label: 'Owner',
key: 'ownerId',
type: 'dropdown' as const,
required: false,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listUsers',
},
],
},
},
{
label: 'Label',
key: 'labelId',
type: 'dropdown' as const,
required: false,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listOrganizationLabelField',
},
],
},
},
],
async run($) {
const { name, ownerId, labelId } = $.step.parameters;
const fields = {
name: name,
owner_id: ownerId,
label: labelId,
};
const body = filterProvidedFields(fields);
const {
data: { data },
} = await $.http.post(
`${$.auth.data.apiDomain}/api/v1/organizations`,
body
);
$.setActionItem({
raw: data,
});
},
});