Files
twenty/packages/twenty-apps/hello-world/serverlessFunctions/create-new-post-card/src/index.ts
T
martmull f6240fabd0 Fix hello world application (#14880)
Updates of the hello-world application
- remove the old hello-world application
- adds an object "postCard"
- adds a serverlessFunction `create-new-post-card` that calls the twenty
api to create a new postCard record
- add a route trigger /post-card/create?recipient=John
2025-10-06 10:51:33 +02:00

28 lines
637 B
TypeScript

import axios from 'axios';
const TWENTY_API_KEY = '<SET_YOUR_TWENTY_API>';
export const main = async (params: { recipient: string }): Promise<object> => {
const { recipient } = params;
const options = {
method: 'POST',
url: 'http://localhost:3000/rest/postCards',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${TWENTY_API_KEY}`,
},
data: { name: recipient ?? 'Unknown' },
};
try {
const { data } = await axios.request(options);
console.log(`New post card to "${recipient}" created`);
return { data };
} catch (error) {
console.error(error);
}
};