Files
twenty_crm/packages/twenty-zapier/src/utils/requestDb.ts
martmull e9092162e0 2049 timebox 1j zapier integration 4 define and implement a first trigger for zapier app (#2132)
* Add create company trigger

* Refactor

* Add operation in subscribe

* Add create hook api endpoint

* Add import of hook module

* Add a test for hook subscribe

* Add delete hook api endpoint

* Add delete hook test

* Add findMany hook route

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2023-10-19 22:48:34 +02:00

41 lines
1014 B
TypeScript

import { Bundle, HttpRequestOptions, ZObject } from 'zapier-platform-core';
const requestDb = async (z: ZObject, bundle: Bundle, query: string) => {
const options = {
url: `${process.env.SERVER_BASE_URL}/graphql`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${bundle.authData.apiKey}`,
},
body: {
query,
},
} 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 requestDb;