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,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@@ -2,5 +2,12 @@ import createActivity from './create-activity';
|
|||||||
import createDeal from './create-deal';
|
import createDeal from './create-deal';
|
||||||
import createLead from './create-lead';
|
import createLead from './create-lead';
|
||||||
import createNote from './create-note';
|
import createNote from './create-note';
|
||||||
|
import createOrganization from './create-organization';
|
||||||
|
|
||||||
export default [createActivity, createDeal, createLead, createNote];
|
export default [
|
||||||
|
createActivity,
|
||||||
|
createDeal,
|
||||||
|
createLead,
|
||||||
|
createNote,
|
||||||
|
createOrganization,
|
||||||
|
];
|
||||||
|
@@ -4,6 +4,7 @@ import listDeals from './list-deals';
|
|||||||
import listLeads from './list-leads';
|
import listLeads from './list-leads';
|
||||||
import listLeadLabels from './list-lead-labels';
|
import listLeadLabels from './list-lead-labels';
|
||||||
import listOrganizations from './list-organizations';
|
import listOrganizations from './list-organizations';
|
||||||
|
import listOrganizationLabelField from './list-organization-label-field';
|
||||||
import listPersons from './list-persons';
|
import listPersons from './list-persons';
|
||||||
import listUsers from './list-users';
|
import listUsers from './list-users';
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ export default [
|
|||||||
listLeads,
|
listLeads,
|
||||||
listLeadLabels,
|
listLeadLabels,
|
||||||
listOrganizations,
|
listOrganizations,
|
||||||
|
listOrganizationLabelField,
|
||||||
listPersons,
|
listPersons,
|
||||||
listUsers,
|
listUsers,
|
||||||
];
|
];
|
||||||
|
@@ -0,0 +1,34 @@
|
|||||||
|
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'List organization label field',
|
||||||
|
key: 'listOrganizationLabelField',
|
||||||
|
|
||||||
|
async run($: IGlobalVariable) {
|
||||||
|
const labelFields: {
|
||||||
|
data: IJSONObject[];
|
||||||
|
} = {
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = await $.http.get(
|
||||||
|
`${$.auth.data.apiDomain}/api/v1/organizationFields`
|
||||||
|
);
|
||||||
|
|
||||||
|
const labelField = data.data.filter(
|
||||||
|
(field: IJSONObject) => field.key === 'label'
|
||||||
|
);
|
||||||
|
const labelOptions = labelField[0].options;
|
||||||
|
|
||||||
|
if (labelOptions?.length) {
|
||||||
|
for (const label of labelOptions) {
|
||||||
|
labelFields.data.push({
|
||||||
|
value: label.id,
|
||||||
|
name: label.label,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return labelFields;
|
||||||
|
},
|
||||||
|
};
|
@@ -9,6 +9,8 @@ items:
|
|||||||
desc: Creates a new lead.
|
desc: Creates a new lead.
|
||||||
- name: Create note
|
- name: Create note
|
||||||
desc: Creates a new note.
|
desc: Creates a new note.
|
||||||
|
- name: Create organization
|
||||||
|
desc: Creates a new organization.
|
||||||
---
|
---
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
Reference in New Issue
Block a user