2038 zapier integration 1 initialize a zapier app with a twenty related account (#2089)
* Add doc for Zapier development * Add twenty-zapier package * Install zapier packages * Update doc * Add twenty-zapier app * Update doc * Update apiKey slug * Update integration * Update create people to person * Update version * Fix lint * Remove useless comments * Update docs * Update version * Update naming * Add prettier * Simplify docs * Remove twenty related stuff from public doc * Use typescript boilerplate * Update details
This commit is contained in:
54
packages/twenty-zapier/src/authentication.ts
Normal file
54
packages/twenty-zapier/src/authentication.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { Bundle, HttpRequestOptions, ZObject } from 'zapier-platform-core';
|
||||
|
||||
const testAuthentication = async (z: ZObject, bundle: Bundle) => {
|
||||
const options = {
|
||||
url: `${process.env.SERVER_BASE_URL}/graphql`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${bundle.authData.apiKey}`,
|
||||
},
|
||||
body: {
|
||||
query: 'query currentWorkspace {currentWorkspace {id displayName}}',
|
||||
},
|
||||
} satisfies HttpRequestOptions;
|
||||
|
||||
return z
|
||||
.request(options)
|
||||
.then((response) => {
|
||||
const results = response.json;
|
||||
if (results.errors) {
|
||||
throw new z.errors.Error(
|
||||
'The API Key you supplied is incorrect',
|
||||
'AuthenticationError',
|
||||
results.errors,
|
||||
);
|
||||
}
|
||||
response.throwForStatus();
|
||||
return results;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new z.errors.Error(
|
||||
'The API Key you supplied is incorrect',
|
||||
'AuthenticationError',
|
||||
err.message,
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
type: 'custom',
|
||||
test: testAuthentication,
|
||||
fields: [
|
||||
{
|
||||
computed: false,
|
||||
key: 'apiKey',
|
||||
required: true,
|
||||
label: 'Api Key',
|
||||
type: 'string',
|
||||
helpText:
|
||||
'Create the api key in [your twenty workspace](https://app.twenty.com/settings/apis)',
|
||||
},
|
||||
],
|
||||
connectionLabel: '{{data.currentWorkspace.displayName}}',
|
||||
customConfig: {},
|
||||
};
|
||||
Reference in New Issue
Block a user