docs: Adjust wording for building triggers and actions

This commit is contained in:
Faruk AYDIN
2022-11-09 20:32:28 +01:00
parent 1cb951056a
commit 580e97ffe3
2 changed files with 17 additions and 12 deletions

View File

@@ -41,7 +41,7 @@ export default defineApp({
## Define actions ## 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 ```typescript
import mark-cat-image-as-favorite from './mark-cat-image-as-favorite'; 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 ## 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 ```typescript
import defineAction from '../../../../helpers/define-action'; import defineAction from '../../../../helpers/define-action';
@@ -91,9 +91,9 @@ Let's briefly explain what we defined here.
## Implement the action ## 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'; import defineAction from '../../../../helpers/define-action';
export default defineAction({ export default defineAction({
@@ -103,9 +103,14 @@ export default defineAction({
const requestPath = `/v1/favorites`; const requestPath = `/v1/favorites`;
const imageId = $.step.parameters.imageId; const imageId = $.step.parameters.imageId;
const headers = {
'x-api-key': $.auth.data.apiKey,
};
const response = await $.http.post( const response = await $.http.post(
requestPath, requestPath,
{ image_id: imageId } { image_id: imageId },
{ headers }
); );
$.setActionItem({ raw: response.data }); $.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 ## 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.

View File

@@ -43,7 +43,7 @@ export default defineApp({
## Define triggers ## 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 ```typescript
import searchCatImages from './search-cat-images'; 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 ## 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 ```typescript
import defineTrigger from '../../../../helpers/define-trigger'; 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'; import defineTrigger from '../../../../helpers/define-trigger';
export default defineTrigger({ 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: 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 ### 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.