feat(pipedrive): add create organization action
This commit is contained in:
@@ -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,
|
||||
});
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user