Files
twenty/packages/twenty-zapier/src/utils/requestDb.ts
T
martmull b1841d0e2f 2114 timebox make sure the zapier integrations supports custom objects (#3091)
* Fix build command

* Add hidden trigger to fetch object names

* Remove useless actions

* Rename createObject to createRecord
2023-12-20 18:41:30 +01:00

56 lines
1.4 KiB
TypeScript

import { Bundle, HttpRequestOptions, ZObject } from 'zapier-platform-core';
export const requestSchema = async (z: ZObject, bundle: Bundle) => {
const options = {
url: `${process.env.SERVER_BASE_URL}/open-api`,
method: 'GET',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${bundle.authData.apiKey}`,
},
} satisfies HttpRequestOptions;
return z.request(options)
.then((response) => response.json)
}
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(
`query: ${query}, error: ${JSON.stringify(results.errors)}`,
'ApiError',
response.status
);
}
response.throwForStatus();
return results;
})
.catch((err) => {
throw new z.errors.Error(
`query: ${query}, error: ${err.message}`,
'Error',
err.status
);
});
};
export default requestDb;