# Building workflows

Workflows are constructed using building blocks called actions, each having its own purpose. Learn how to compose single and multi-step workflows with sequential and nested action execution.

Workflows are constructed using building blocks called actions, each having its own purpose (you may learn more about actions on the [actions overview](/docs/actions-overview) page).

A workflow, after being successfully executed, produces a `completion`, that contains the results of all actions. See the [executing workflows](/docs/executing-workflows) page for details.

Here you'll learn how to build various workflows, from single-action to advanced.

> In most cases, you don't need to build workflows from scratch. The left menu contains pages with pre-built workflows for popular scenarios you can simply copy and use.

## Single-action workflows

Single-action workflows contain exactly one action. You can only use actions that allow [root start in their constraints](/docs/actions-overview).

### Example 1

Let's say you want to build a workflow to check the connection status between your LinkedIn account and another person.

You only need to use [st.checkConnectionStatus](/docs/action-st-check-connection-status) action to accomplish this.

**Workflow:**

```json
{
  "actionType": "st.checkConnectionStatus",
  "personUrl": "https://www.linkedin.com/in/person1"
}
```

**Completion:**

```json
{
  "actionType": "st.checkConnectionStatus",
  "success": true,
  "data": { 
    "connectionStatus": "pending"
  }
}
```

### Example 2

Let's say you want to build a workflow to retrieve basic information about a company.

You only need to use [st.openCompanyPage](/docs/action-st-open-company-page) action to accomplish this.

**Workflow:**

```json
{
  "actionType": "st.openCompanyPage",
  "companyUrl": "https://www.linkedin.com/company/company1",
  "basicInfo": true
}
```

**Completion:**

```json
{
  "actionType": "st.openCompanyPage",
  "success": true,
  "data": {
    "name": "TechCorp",
    "publicUrl": "https://www.linkedin.com/company/company1",
    "description": "TechCorp is a leading provider of innovative technology solutions for businesses worldwide.",
    "location": "Cupertino, California",
    "headquarters": "US",
    "industry": "Information Technology",
    "specialties": "Cloud Computing, AI, Software Development",
    "website": "https://techcorp.com",
    "employeeCount": 500,
    "yearFounded": 2019,
    "ventureFinancing": true,
    "jobsCount": 12
  }
}
```

## Array workflows

Array workflows contain multiple actions executed sequentially. You can only use actions that allow [root start in their constraints](/docs/actions-overview).

> When you need to perform multiple identical operations, use one array workflow with multiple actions instead of separate single-action workflows. This approach is significantly faster due to API optimizations.

### Example 1

Let's say you want to build a workflow to check the connection status between your LinkedIn account and 5 different people.

You need to use [st.checkConnectionStatus](/docs/action-st-check-connection-status) action multiple times to accomplish this.

**Workflow:**

```json
[
  {
    "actionType": "st.checkConnectionStatus",
    "personUrl": "https://www.linkedin.com/in/person1"
  },
  {
    "actionType": "st.checkConnectionStatus",
    "personUrl": "https://www.linkedin.com/in/person2"
  },
  {
    "actionType": "st.checkConnectionStatus",
    "personUrl": "https://www.linkedin.com/in/person3"
  },
  {
    "actionType": "st.checkConnectionStatus",
    "personUrl": "https://www.linkedin.com/in/person4"
  },
  {
    "actionType": "st.checkConnectionStatus",
    "personUrl": "https://www.linkedin.com/in/person5"
  }
]
```

**Completion:**

```json
[
  {
    "actionType": "st.checkConnectionStatus",
    "success": true,
    "data": { 
      "connectionStatus": "connected"
    }
  },
  {
    "actionType": "st.checkConnectionStatus",
    "success": true,
    "data": { 
      "connectionStatus": "notConnected"
    }
  },
  {
    "actionType": "st.checkConnectionStatus",
    "success": true,
    "data": { 
      "connectionStatus": "pending"
    }
  },
  {
    "actionType": "st.checkConnectionStatus",
    "success": true,
    "data": { 
      "connectionStatus": "connected"
    }
  },
  {
    "actionType": "st.checkConnectionStatus",
    "success": true,
    "data": { 
      "connectionStatus": "connected"
    }
  }
]
```

### Example 2

Let's say you want to build a workflow to retrieve basic information about several people.

You need to use [st.openPersonPage](/docs/action-st-open-person-page) action multiple times to accomplish this.

**Workflow:**

```json
[
  {
    "actionType": "st.openPersonPage",
    "label": "person1",
    "personUrl": "https://www.linkedin.com/in/person1",
    "basicInfo": true
  },
  {
    "actionType": "st.openPersonPage",
    "label": "person2",
    "personUrl": "https://www.linkedin.com/in/person2",
    "basicInfo": true
  }
]
```

**Completion:**

```json
[
  {
    "actionType": "st.openPersonPage",
    "label": "person1",
    "success": true,
    "data": {
      "name": "John Doe",
      "publicUrl": "https://www.linkedin.com/in/person1",
      "hashedUrl": "https://www.linkedin.com/in/SInQBmjJ015eLr8OeJoj0mrkxx7Jiuy0",
      "headline": "Software Engineer at TechCorp",
      "location": "San Francisco, USA",
      "countryCode": "US",
      "position": "Software Engineer",
      "companyName": "TechCorp",
      "companyUrl": "https://www.linkedin.com/company/12345678"
    }
  },
  {
    "actionType": "st.openPersonPage",
    "label": "person2",
    "success": true,
    "data": {
      "name": "Jane Doe",
      "publicUrl": "https://www.linkedin.com/in/person2",
      "headline": "Product Manager at Cognito Inc.",
      "location": "Lisbon, Portugal",
      "countryCode": "PT",
      "position": "Product Manager",
      "companyName": "Cognito Inc.",
      "companyUrl": "https://www.linkedin.com/company/87654321"
    }
  }
]
```

## Advanced workflows

With Linked API, you can build **any workflow you can imagine** by combining arrays and parent-child action relationships through `then` parameter.

Only two rules apply:

- You must follow the [constraints of all actions](/docs/actions-overview) used.
- The final workflow cannot exceed **5 levels of nesting**.

### Example 1

Let's say you want to build a workflow that searches for companies using specific filters and keywords, then retrieves basic information about all companies from the search results.

You need to use [st.searchCompanies](/docs/action-st-search-companies), [st.doForCompanies](/docs/action-st-do-for-companies) and [st.openCompanyPage](/docs/action-st-open-company-page) actions to accomplish this.

**Workflow:**

```json
{
  "actionType": "st.searchCompanies",
  "term": "Tech Inc",
  "filter": {
    "sizes": ["51-200", "2001-500"],
    "locations": ["San Francisco", "New York"],
    "industries": ["Software Development", "Robotics Engineering"],
    "annualRevenue": {
      "min": "0",
      "max": "2.5"
    }
  },
  "then": {
    "actionType": "st.doForCompanies",
    "then": {
      "actionType": "st.openCompanyPage",
      "basicInfo": true
    }
  }
}
```

**Completion:**

```json
{
  "actionType": "st.searchCompanies",
  "success": true,
  "data": [
    {
      "name": "TechCorp",
      "publicUrl": "https://www.linkedin.com/company/techcorp",
      "industry": "Information Technology",
      "location": "California",
      "then": {
        "actionType": "st.openCompanyPage",
        "success": true,
        "data": {
          "name": "TechCorp",
          "publicUrl": "https://www.linkedin.com/company/techcorp",
          "description": "TechCorp is a leading provider of innovative technology solutions for businesses worldwide.",
          "location": "California",
          "headquarters": "US",
          "industry": "Information Technology",
          "specialties": "Cloud Computing, AI, Software Development",
          "website": "https://techcorp.com",
          "employeeCount": 500,
          "yearFounded": 2019,
          "ventureFinancing": true,
          "jobsCount": 12
        }
      }
    },
    {
      "name": "Techical Life",
      "publicUrl": "https://www.linkedin.com/company/techlife",
      "industry": "Software Development",
      "location": "Mountain View",
      "then": {
        "actionType": "st.openCompanyPage",
        "success": true,
        "data": {
          "name": "Techical Life",
          "publicUrl": "https://www.linkedin.com/company/techlife",
          "description": "TechLife is a worldwide leader in software development for sustainability.",
          "location": "Mountain View",
          "headquarters": "US",
          "industry": "Software Development",
          "specialties": "Software Development, AI",
          "website": "https://techlife.com",
          "employeeCount": 163,
          "yearFounded": 2016,
          "ventureFinancing": false,
          "jobsCount": 4
        }
      }
    }
  ]
}
```

### Example 2

Let's say you want to build a workflow that retrieves basic company information, finds all managers, gets their basic information and education details, then sends them connection requests.

You need to use [st.openCompanyPage](/docs/action-st-open-company-page), [st.retrieveCompanyEmployees](/docs/action-st-retrieve-company-employees), [st.doForPeople](/docs/action-st-do-for-people), [st.openPersonPage](/docs/action-st-open-person-page), [st.retrievePersonEducation](/docs/action-st-retrieve-person-education) and [st.sendConnectionRequest](/docs/action-st-send-connection-request) actions to accomplish this.

**Workflow:**

```json
{
  "actionType": "st.openCompanyPage",
  "companyUrl": "https://www.linkedin.com/company/techcorp",
  "basicInfo": true,
  "then": {
    "actionType": "st.retrieveCompanyEmployees",
    "filter": {
      "position": "Manager"
    },
    "then": {
      "actionType": "st.doForPeople",
      "then": {
        "actionType": "st.openPersonPage",
        "basicInfo": true,
        "then": [
          {
            "actionType": "st.retrievePersonEducation"
          },
          {
            "actionType": "st.sendConnectionRequest"
          }
        ]
      }
    }
  }
}
```

**Completion:**

```json
{
  "actionType": "st.openCompanyPage",
  "success": true,
  "data": {
    "name": "TechCorp",
    "publicUrl": "https://www.linkedin.com/company/techcorp",
    "description": "TechCorp is a leading provider of innovative technology solutions for businesses worldwide.",
    "location": "California",
    "headquarters": "US",
    "industry": "Information Technology",
    "specialties": "Cloud Computing, AI, Software Development",
    "website": "https://techcorp.com",
    "employeeCount": 500,
    "yearFounded": 2019,
    "ventureFinancing": true,
    "jobsCount": 12,
    "then": {
      "actionType": "st.retrieveCompanyEmployees",
      "success": true,
      "data": [
        {
          "name": "John Doe",
          "publicUrl": "https://www.linkedin.com/in/johndoe",
          "headline": "Product Manager at TechCorp",
          "location": "New York, USA",
          "then": {
            "actionType": "st.openPersonPage",
            "success": true,
            "data": {
              "name": "John Doe",
              "publicUrl": "https://www.linkedin.com/in/johndoe",
              "hashedUrl": "https://www.linkedin.com/in/SInQBmjJ015eLr8",
              "headline": "Product Manager at TechCorp",
              "location": "New York, USA",
              "countryCode": "US",
              "position": "Product Manager",
              "companyName": "TechCorp",
              "hashedCompanyUrl": "https://www.linkedin.com/company/87654321",
              "then": [
                {
                  "actionType": "st.retrievePersonEducation",
                  "success": true,
                  "data": [
                    {
                      "schoolName": "Harvard University",
                      "schoolHashedUrl": "https://www.linkedin.com/company/12345678",
                      "details": "Master of Science in Computer Science, Artificial Intelligence"
                    },
                    {
                      "schoolName": "MIT",
                      "schoolHashedUrl": "https://www.linkedin.com/company/87654321",
                      "details": "Bachelor of Science in Electrical Engineering and Computer Science"
                    }
                  ]
                },
                {
                  "actionType": "st.sendConnectionRequest",
                  "success": true
                }
              ]
            }
          }
        }
        ...
      ]
    }
  }
}
```

> This page provides examples of [workflows](/docs/building-workflows) and their [completions](/docs/executing-workflows). For detailed documentation on constraints, parameters, and possible results of specific actions, always refer to the corresponding [action documentation pages](/docs/actions-overview).
