# Reacting and commenting

This page describes how to create workflows for reacting and commenting on LinkedIn posts.

## Reacting to post

To react to a post, you need to include [`st.reactToPost`](/docs/action-st-react-to-post) action in your workflow. Here's an example:

**Workflow:**

```json
{
  "actionType": "st.reactToPost",
  "postUrl": "https://www.linkedin.com/posts/post1",
  "type": "like"
}
```

**Completion:**

```json
{
  "actionType": "st.reactToPost",
  "success": true
}
```

## Commenting on post

To comment on a post, you need to include [`st.commentOnPost`](/docs/action-st-comment-on-post) action in your workflow. Here's an example:

**Workflow:**

```json
{
  "actionType": "st.commentOnPost",
  "postUrl": "https://www.linkedin.com/posts/post1",
  "text": "I completely agree with your point."
}
```

**Completion:**

```json
{
  "actionType": "st.commentOnPost",
  "success": true
}
```

## Reacting + commenting

To react and comment on the same post, you need to include [`st.reactToPost`](/docs/action-st-react-to-post) and [`st.commentOnPost`](/docs/action-st-comment-on-post) as child actions of [`st.openPost`](/docs/action-st-open-post) action. Here's an example:

**Workflow:**

```json
{
  "actionType": "st.openPost",
  "postUrl": "https://www.linkedin.com/posts/post1",
  "basicInfo": false,
  "then": [
    {
      "actionType": "st.reactToPost",
      "type": "like"
    },
    {
      "actionType": "st.commentOnPost",
      "text": "I completely agree with your point."
    }
  ]
}
```

**Completion:**

```json
{
  "actionType": "st.openPost",
  "success": true,
  "data": {
    "then": [
      {
        "actionType": "st.reactToPost",
        "success": true
      },
      {
        "actionType": "st.commentOnPost",
        "success": true
      }
    ]
  }
}
```

## Reacting to a comment

To react to a comment, you need to include [`st.reactToComment`](/docs/action-st-react-to-comment) action in your workflow. It accepts a `commentUrl`, which you can obtain from the `commentUrl` field returned by [`st.commentOnPost`](/docs/action-st-comment-on-post), [`st.replyToComment`](/docs/action-st-reply-to-comment), or [`st.retrievePostComments`](/docs/action-st-retrieve-post-comments). Here's an example:

**Workflow:**

```json
{
  "actionType": "st.reactToComment",
  "commentUrl": "https://www.linkedin.com/feed/update/urn:li:activity:1234567890123456789/?dashCommentUrn=urn%3Ali%3Afsd_comment%3A(9876543210%2Curn%3Ali%3Aactivity%3A1234567890123456789)",
  "type": "like"
}
```

**Completion:**

```json
{
  "actionType": "st.reactToComment",
  "success": true
}
```

## Replying to a comment

To reply to a comment, you need to include [`st.replyToComment`](/docs/action-st-reply-to-comment) action in your workflow. It returns the `commentUrn` and `commentUrl` of the created reply. Here's an example:

**Workflow:**

```json
{
  "actionType": "st.replyToComment",
  "commentUrl": "https://www.linkedin.com/feed/update/urn:li:activity:1234567890123456789/?dashCommentUrn=urn%3Ali%3Afsd_comment%3A(9876543210%2Curn%3Ali%3Aactivity%3A1234567890123456789)",
  "text": "Thanks for sharing your thoughts!"
}
```

**Completion:**

```json
{
  "actionType": "st.replyToComment",
  "success": true,
  "data": {
    "commentUrn": "urn:li:comment:(urn:li:activity:1234567890123456789,1122334455)",
    "commentUrl": "https://www.linkedin.com/feed/update/urn:li:activity:1234567890123456789/?dashCommentUrn=urn%3Ali%3Afsd_comment%3A(1122334455%2Curn%3Ali%3Aactivity%3A1234567890123456789)"
  }
}
```

## Engaging with all comments on a post

To react to or reply to every comment on a post without knowing their URLs upfront, retrieve the comments with [`st.retrievePostComments`](/docs/action-st-retrieve-post-comments) and iterate over them with [`st.doForComments`](/docs/action-st-do-for-comments). Each iterated comment can either react/reply directly, or open first with [`st.openComment`](/docs/action-st-open-comment) to run several comment-scoped actions. Here's an example that likes and replies to each of the 3 most relevant comments:

**Workflow:**

```json
{
  "actionType": "st.retrievePostComments",
  "postUrl": "https://www.linkedin.com/posts/post1",
  "limit": 3,
  "sort": "mostRelevant",
  "then": {
    "actionType": "st.doForComments",
    "then": {
      "actionType": "st.openComment",
      "then": [
        {
          "actionType": "st.reactToComment",
          "type": "celebrate"
        },
        {
          "actionType": "st.replyToComment",
          "text": "Great point, thanks for sharing!"
        }
      ]
    }
  }
}
```

**Completion:**

```json
{
  "actionType": "st.retrievePostComments",
  "success": true,
  "data": [
    {
      ...
      "then": {
        "actionType": "st.openComment",
        "success": true,
        "data": {
          "commentUrn": "urn:li:comment:(urn:li:activity:1234567890123456789,9876543210)",
          "commentUrl": "https://www.linkedin.com/feed/update/urn:li:activity:1234567890123456789/?dashCommentUrn=urn%3Ali%3Afsd_comment%3A(9876543210%2Curn%3Ali%3Aactivity%3A1234567890123456789)",
          "then": [
            {
              "actionType": "st.reactToComment",
              "success": true
            },
            {
              "actionType": "st.replyToComment",
              "success": true,
              "data": {
                "commentUrn": "urn:li:comment:(urn:li:activity:1234567890123456789,1122334455)",
                "commentUrl": "https://www.linkedin.com/feed/update/urn:li:activity:1234567890123456789/?dashCommentUrn=urn%3Ali%3Afsd_comment%3A(1122334455%2Curn%3Ali%3Aactivity%3A1234567890123456789)"
              }
            }
          ]
        }
      }
    }
  ]
}
```

> 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).
