|
1 | 1 | ---
|
2 | 2 | sidebar_position: 2
|
3 |
| -title: Setup backend |
| 3 | +title: Set up backend |
4 | 4 | ---
|
5 | 5 |
|
6 | 6 | import BackendTypesJson from '/docs/actions-and-automations/templates/_backend-types-json.md'
|
7 | 7 | import PayloadAdvancedFunctions from '/docs/actions-and-automations/templates/_payload_advanced_functions.mdx'
|
8 | 8 | import Tabs from "@theme/Tabs"
|
9 | 9 | import TabItem from "@theme/TabItem"
|
10 | 10 |
|
11 |
| -# Setup backend |
| 11 | +# Set up backend |
12 | 12 |
|
13 | 13 | The automation's backend is the logic that you want to execute when a trigger event occurs. It will run on all entities tied to the blueprint specified in the automation's definition, whenever the trigger event occurs.
|
14 | 14 |
|
15 | 15 | Port uses the same backend types for automations and for [self-service actions](/actions-and-automations/create-self-service-experiences/).
|
16 | 16 |
|
17 |
| -## Backend JSON structure |
| 17 | +## Define the backend |
18 | 18 |
|
19 |
| -The backend is defined under the `invocationMethod` key in the automation's JSON structure: |
| 19 | +The automation's backend is defined under the `Backend` tab of the automation creation form in Port's UI. |
| 20 | +Let's break the definition down to two parts: |
20 | 21 |
|
21 |
| -```json showLineNumbers |
22 |
| -{ |
23 |
| - "identifier": "unique_id", |
24 |
| - "title": "Title", |
25 |
| - "icon": "icon_identifier", |
26 |
| - "description": "automation description", |
27 |
| - "trigger": { |
28 |
| - "type": "automation", |
29 |
| - "event": { |
30 |
| - "type": "event_type", |
31 |
| - "blueprintIdentifier": "blueprint_id" |
32 |
| - }, |
33 |
| - "condition": { |
34 |
| - "type": "JQ", |
35 |
| - "expressions": ["expression1", "expression2"], |
36 |
| - "combinator": "and" |
37 |
| - } |
38 |
| - }, |
39 |
| - # highlight-start |
40 |
| - "invocationMethod": { |
41 |
| - "type": "WEBHOOK", |
42 |
| - "url": "https://example.com", |
43 |
| - "headers": { |
44 |
| - "RUN_ID": "{{ .run.id }}" |
45 |
| - }, |
46 |
| - "body": { |
47 |
| - "payload_key": "{{ some-jq-value }}" |
48 |
| - } |
49 |
| - }, |
50 |
| - # highlight-end |
51 |
| - "publish": false |
52 |
| -} |
53 |
| -``` |
| 22 | +### Define your backend's type and metadata |
54 | 23 |
|
55 |
| -## Supported backends |
| 24 | +In this section we provide information about the backend logic and its location, so that Port can access and run it. |
56 | 25 |
|
57 |
| -<BackendTypesJson /> |
| 26 | +Port uses the same backend types for both automations and [self-service actions](https://docs.port.io/actions-and-automations/create-self-service-experiences/). |
| 27 | +For more information and examples for the available backend types, check out the [backend types](/actions-and-automations/setup-backend/) page. |
58 | 28 |
|
59 |
| -To read more about each backend type, see the [backend types](/actions-and-automations/setup-backend/) page. |
| 29 | +Depending on the backend type you choose, you will need to provide different configuration parameters. |
60 | 30 |
|
61 | 31 | ### Define the payload
|
62 | 32 |
|
63 |
| -When creating a self-service action or automation, you can construct a JSON payload that will be sent to your backend upon every execution. You can use this to send data about the automation that you want your backend to have. |
| 33 | +When creating an automation, you can construct a JSON payload that will be sent to your backend upon every execution. You can use this to send data about the automation that you want your backend to have. |
64 | 34 |
|
65 |
| -The payload is defined under the `invocationMethod` object in the automation's JSON structure. The key under which the payload is defined depends on the backend you are using (see the table above). |
| 35 | +Still in the `Backend` tab, scroll down to the `Configure the invocation payload` section. This is where we define the automation's payload. |
66 | 36 |
|
67 | 37 | The payload is defined using JSON, and accessing your data is done using `jq`, wrapping each expression with `{{ }}`.
|
68 | 38 |
|
69 |
| -For example, the following payload definition will send a timestamp of when the execution was triggered: |
| 39 | +Here is an example for an automation payload: |
70 | 40 |
|
71 | 41 | ```json showLineNumbers
|
72 | 42 | {
|
73 |
| - "execution_time": "{{ .trigger.at }}", |
74 | 43 | "port_context": {
|
75 |
| - "run_id": "{{ .run.id }}" |
| 44 | + "runId": "{{ .run.id }}" |
76 | 45 | }
|
77 | 46 | }
|
78 | 47 | ```
|
79 | 48 |
|
80 |
| -You may have noticed that the example above also sends `{{ .run.id }}`. This is a unique identifier for each execution of the action, and can be used to [interact with the action run](/actions-and-automations/reflect-action-progress/) in Port from your backend. |
| 49 | +You may have noticed that the example above also sends `{{ .run.id }}`. This is a unique identifier for each execution of the automation, and can be used to interact with the autmation run in Port from your backend. |
81 | 50 |
|
82 |
| -The data that is available to you when constructing the payload is detailed in the `Trigger data` section below. |
| 51 | +Now you might be thinking - *how do I know what data is available to me when constructing the payload?* |
| 52 | +Enter `trigger data`. |
83 | 53 |
|
84 | 54 | #### Trigger data
|
85 | 55 |
|
@@ -391,4 +361,66 @@ The other trigger events have the same structure, with the following differences
|
391 | 361 | </TabItem>
|
392 | 362 | </Tabs>
|
393 | 363 |
|
| 364 | +You can access any value in this structure and add it to the payload. For example, to add the executing user's name to the payload, you can use the following expression: |
| 365 | + |
| 366 | +```json |
| 367 | +{ |
| 368 | + "executing_user_email": "{{.trigger.by.user.email}}" |
| 369 | +} |
| 370 | +``` |
| 371 | + |
| 372 | +Use the `Test JQ` button in the bottom-left corner to test your expressions against your automation and ensure you are sending the correct data. |
| 373 | + |
| 374 | +:::tip Inspect the Full Object in `jq` |
| 375 | +You can use the `jq` expression `{{ . }}` when testing to see the entire available object, and then drill down to the specific data you need. |
| 376 | +::: |
| 377 | + |
394 | 378 | <PayloadAdvancedFunctions />
|
| 379 | + |
| 380 | +## Backend JSON structure |
| 381 | + |
| 382 | +In some cases, you may prefer to define the backend configuration using a JSON object. |
| 383 | +The backend is defined under the `invocationMethod` object in the automation's JSON structure. |
| 384 | + |
| 385 | +```json showLineNumbers |
| 386 | +{ |
| 387 | + "identifier": "unique_id", |
| 388 | + "title": "Title", |
| 389 | + "icon": "icon_identifier", |
| 390 | + "description": "automation description", |
| 391 | + "trigger": { |
| 392 | + "type": "automation", |
| 393 | + "event": { |
| 394 | + "type": "event_type", |
| 395 | + "blueprintIdentifier": "blueprint_id" |
| 396 | + }, |
| 397 | + "condition": { |
| 398 | + "type": "JQ", |
| 399 | + "expressions": ["expression1", "expression2"], |
| 400 | + "combinator": "and" |
| 401 | + } |
| 402 | + }, |
| 403 | + # highlight-start |
| 404 | + "invocationMethod": { |
| 405 | + "type": "WEBHOOK", |
| 406 | + "url": "https://example.com", |
| 407 | + "headers": { |
| 408 | + "RUN_ID": "{{ .run.id }}" |
| 409 | + }, |
| 410 | + "body": { |
| 411 | + "payload_key": "{{ some-jq-value }}" |
| 412 | + } |
| 413 | + }, |
| 414 | + # highlight-end |
| 415 | + "publish": false |
| 416 | +} |
| 417 | +``` |
| 418 | + |
| 419 | +## Supported backends |
| 420 | + |
| 421 | +<BackendTypesJson /> |
| 422 | + |
| 423 | +To read more about each backend type, see the [backend types](/actions-and-automations/setup-backend/) page. |
| 424 | + |
| 425 | + |
| 426 | + |
0 commit comments