diff --git a/packages/docs/pages/build-integrations/actions.md b/packages/docs/pages/build-integrations/actions.md index 2638b742..0e69b9a5 100644 --- a/packages/docs/pages/build-integrations/actions.md +++ b/packages/docs/pages/build-integrations/actions.md @@ -41,7 +41,7 @@ export default defineApp({ ## Define actions -Let's create the `actions/index.ts` file inside of the `thecatapi` folder. +Create the `actions/index.ts` file inside of the `thecatapi` folder. ```typescript import mark-cat-image-as-favorite from './mark-cat-image-as-favorite'; @@ -55,7 +55,7 @@ If you add new actions, you need to add them to the actions/index.ts file and ex ## Add metadata -Let's create the `actions/mark-cat-image-as-favorite.ts` file inside the `thecatapi` folder. +Create the `actions/mark-cat-image-as-favorite.ts` file inside the `thecatapi` folder. ```typescript import defineAction from '../../../../helpers/define-action'; @@ -91,9 +91,9 @@ Let's briefly explain what we defined here. ## Implement the action -Let's implement the action. Open the `actions/mark-cat-image-as-favorite.ts` file and add the highlighted lines. +Open the `actions/mark-cat-image-as-favorite.ts` file and add the highlighted lines. -```typescript{7-15} +```typescript{7-20} import defineAction from '../../../../helpers/define-action'; export default defineAction({ @@ -103,9 +103,14 @@ export default defineAction({ const requestPath = `/v1/favorites`; const imageId = $.step.parameters.imageId; + const headers = { + 'x-api-key': $.auth.data.apiKey, + }; + const response = await $.http.post( requestPath, - { image_id: imageId } + { image_id: imageId }, + { headers } ); $.setActionItem({ raw: response.data }); @@ -119,4 +124,4 @@ In this action, we send a request to the cat API to mark the cat image as favori ## Test the action -Let's go to the flows page of Automatisch and create a new flow. Add the `Search cat images` as a trigger in the flow. Add the `Mark the cat image as favorite` action to the flow as a second step. Add one of the image IDs you got from the cat API as `Image ID` argument to the action. Click `Test & Continue` button. If you a see JSON response in the user interface, it means that both the trigger and the action we built are working properly. +Go to the flows page of Automatisch and create a new flow. Add the `Search cat images` as a trigger in the flow. Add the `Mark the cat image as favorite` action to the flow as a second step. Add one of the image IDs you got from the cat API as `Image ID` argument to the action. Click `Test & Continue` button. If you a see JSON response in the user interface, it means that both the trigger and the action we built are working properly. diff --git a/packages/docs/pages/build-integrations/triggers.md b/packages/docs/pages/build-integrations/triggers.md index bed17db5..90872070 100644 --- a/packages/docs/pages/build-integrations/triggers.md +++ b/packages/docs/pages/build-integrations/triggers.md @@ -43,7 +43,7 @@ export default defineApp({ ## Define triggers -Let's create the `triggers/index.ts` file inside of the `thecatapi` folder. +Create the `triggers/index.ts` file inside of the `thecatapi` folder. ```typescript import searchCatImages from './search-cat-images'; @@ -57,7 +57,7 @@ If you add new triggers, you need to add them to the `triggers/index.ts` file an ## Add metadata -Let's create the `triggers/search-cat-images.ts` file inside of the `thecatapi` folder. +Create the `triggers/search-cat-images.ts` file inside of the `thecatapi` folder. ```typescript import defineTrigger from '../../../../helpers/define-trigger'; @@ -91,9 +91,9 @@ Let's briefly explain what we defined here. ::: -Let's implement the `run` function. +Implement the `run` function by adding highlighted lines. -```typescript{10-34} +```typescript{6-29} import defineTrigger from '../../../../helpers/define-trigger'; export default defineTrigger({ @@ -127,7 +127,7 @@ export default defineTrigger({ }); ``` -Let's briefly explain what we did here. We are using the `$.http` object to make HTTP requests. Our API is paginated, so we are making requests until we get less than 10 items, which means the last page. +We are using the `$.http` object to make HTTP requests. Our API is paginated, so we are making requests until we get less than 10 items, which means the last page. We do not have to return anything from the `run` function. We are using the `$.pushTriggerItem` function to push the data to Automatisch. $.pushTriggerItem accepts an object with the following fields: @@ -146,4 +146,4 @@ We do not have to return anything from the `run` function. We are using the `$.p ### Test the trigger -Let's go to the flows page of Automatisch and create a new flow. Choose `The cat API` app and the `Search cat images` trigger and click `Test & Continue` button. If you a see JSON response in the user interface, it means that the trigger is working properly. +Go to the flows page of Automatisch and create a new flow. Choose `The cat API` app and the `Search cat images` trigger and click `Test & Continue` button. If you a see JSON response in the user interface, it means that the trigger is working properly.