|
| 1 | +import attio from "../../attio.app.mjs"; |
| 2 | +import constants from "../../common/constants.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "attio-create-person", |
| 6 | + name: "Create Person", |
| 7 | + description: "Creates a new person. [See the documentation](https://developers.attio.com/reference/post_v2-objects-people-records).", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + attio, |
| 12 | + firstName: { |
| 13 | + propDefinition: [ |
| 14 | + attio, |
| 15 | + "firstName", |
| 16 | + ], |
| 17 | + }, |
| 18 | + lastName: { |
| 19 | + propDefinition: [ |
| 20 | + attio, |
| 21 | + "lastName", |
| 22 | + ], |
| 23 | + }, |
| 24 | + emailAddress: { |
| 25 | + propDefinition: [ |
| 26 | + attio, |
| 27 | + "emailAddress", |
| 28 | + ], |
| 29 | + }, |
| 30 | + description: { |
| 31 | + propDefinition: [ |
| 32 | + attio, |
| 33 | + "description", |
| 34 | + ], |
| 35 | + }, |
| 36 | + jobTitle: { |
| 37 | + propDefinition: [ |
| 38 | + attio, |
| 39 | + "jobTitle", |
| 40 | + ], |
| 41 | + }, |
| 42 | + phoneNumber: { |
| 43 | + propDefinition: [ |
| 44 | + attio, |
| 45 | + "phoneNumber", |
| 46 | + ], |
| 47 | + }, |
| 48 | + phoneNumberCountryCode: { |
| 49 | + propDefinition: [ |
| 50 | + attio, |
| 51 | + "phoneNumberCountryCode", |
| 52 | + ], |
| 53 | + }, |
| 54 | + linkedin: { |
| 55 | + propDefinition: [ |
| 56 | + attio, |
| 57 | + "linkedin", |
| 58 | + ], |
| 59 | + }, |
| 60 | + twitter: { |
| 61 | + propDefinition: [ |
| 62 | + attio, |
| 63 | + "twitter", |
| 64 | + ], |
| 65 | + }, |
| 66 | + facebook: { |
| 67 | + propDefinition: [ |
| 68 | + attio, |
| 69 | + "facebook", |
| 70 | + ], |
| 71 | + }, |
| 72 | + instagram: { |
| 73 | + propDefinition: [ |
| 74 | + attio, |
| 75 | + "instagram", |
| 76 | + ], |
| 77 | + }, |
| 78 | + companyId: { |
| 79 | + label: "Company ID", |
| 80 | + description: "The ID of the company to associate with the person.", |
| 81 | + optional: true, |
| 82 | + propDefinition: [ |
| 83 | + attio, |
| 84 | + "recordId", |
| 85 | + () => ({ |
| 86 | + targetObject: constants.TARGET_OBJECT.COMPANIES, |
| 87 | + }), |
| 88 | + ], |
| 89 | + }, |
| 90 | + }, |
| 91 | + async run({ $ }) { |
| 92 | + const { |
| 93 | + attio, |
| 94 | + firstName, |
| 95 | + lastName, |
| 96 | + emailAddress, |
| 97 | + description, |
| 98 | + jobTitle, |
| 99 | + phoneNumber, |
| 100 | + phoneNumberCountryCode, |
| 101 | + linkedin, |
| 102 | + twitter, |
| 103 | + facebook, |
| 104 | + instagram, |
| 105 | + companyId, |
| 106 | + } = this; |
| 107 | + |
| 108 | + const response = await attio.createRecord({ |
| 109 | + $, |
| 110 | + targetObject: constants.TARGET_OBJECT.PEOPLE, |
| 111 | + data: { |
| 112 | + data: { |
| 113 | + values: { |
| 114 | + ...(emailAddress && { |
| 115 | + email_addresses: [ |
| 116 | + { |
| 117 | + email_address: emailAddress, |
| 118 | + }, |
| 119 | + ], |
| 120 | + }), |
| 121 | + ...(firstName || lastName) && { |
| 122 | + name: [ |
| 123 | + { |
| 124 | + first_name: firstName || "", |
| 125 | + last_name: lastName || "", |
| 126 | + full_name: `${firstName || ""} ${lastName || ""}`.trim(), |
| 127 | + }, |
| 128 | + ], |
| 129 | + }, |
| 130 | + ...(description && { |
| 131 | + description: [ |
| 132 | + { |
| 133 | + value: description, |
| 134 | + }, |
| 135 | + ], |
| 136 | + }), |
| 137 | + ...(jobTitle && { |
| 138 | + job_title: [ |
| 139 | + { |
| 140 | + value: jobTitle, |
| 141 | + }, |
| 142 | + ], |
| 143 | + }), |
| 144 | + ...(phoneNumber && { |
| 145 | + phone_numbers: [ |
| 146 | + { |
| 147 | + original_phone_number: phoneNumber, |
| 148 | + ...(phoneNumberCountryCode && { |
| 149 | + country_code: phoneNumberCountryCode, |
| 150 | + }), |
| 151 | + }, |
| 152 | + ], |
| 153 | + }), |
| 154 | + ...(linkedin && { |
| 155 | + linkedin: [ |
| 156 | + { |
| 157 | + value: linkedin, |
| 158 | + }, |
| 159 | + ], |
| 160 | + }), |
| 161 | + ...(twitter && { |
| 162 | + twitter: [ |
| 163 | + { |
| 164 | + value: twitter, |
| 165 | + }, |
| 166 | + ], |
| 167 | + }), |
| 168 | + ...(facebook && { |
| 169 | + facebook: [ |
| 170 | + { |
| 171 | + value: facebook, |
| 172 | + }, |
| 173 | + ], |
| 174 | + }), |
| 175 | + ...(instagram && { |
| 176 | + instagram: [ |
| 177 | + { |
| 178 | + value: instagram, |
| 179 | + }, |
| 180 | + ], |
| 181 | + }), |
| 182 | + ...(companyId && { |
| 183 | + company: [ |
| 184 | + { |
| 185 | + target_object: constants.TARGET_OBJECT.COMPANIES, |
| 186 | + target_record_id: companyId, |
| 187 | + }, |
| 188 | + ], |
| 189 | + }), |
| 190 | + }, |
| 191 | + }, |
| 192 | + }, |
| 193 | + }); |
| 194 | + |
| 195 | + $.export("$summary", `Successfully created person with ID \`${response.data.id.record_id}\`.`); |
| 196 | + |
| 197 | + return response; |
| 198 | + }, |
| 199 | +}; |
0 commit comments