> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opigno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a post

Any user associated with a context with `AUTHENTICATED` scope can execute `createPost` mutation.
The current API user will be set as an author. A content such as a started or passed learning path, an acquired certificate or an earned badge can be shared.
If the provided content doesn't relate to the current API user, it will be skipped, and a post will be created only with the text.

Mutation has a single required incoming argument - `data` that represents `PostCreationInput` object:

| Parameter       | Type                                                                                           | Description                                                                                                                                                                                                                                                                                                      |
| :-------------- | :--------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `text`          | `String`                                                                                       | **Required**. The post body text. Available HTML tags are: `<a>`, `<p>`, `<br>`. Any other tag will be trimmed.                                                                                                                                                                                                  |
| `sharedContent` | [`PostSharedContentInput`](/OpignoEnterpriseAPI/Post/CreatePost#postsharedcontentinput-object) | Optional. Contains the data related to the content that is going to be shared in the post (learning path/certificate/badge).                                                                                                                                                                                     |
| `imagesBase64`  | [\[`UploadedFileInput`\]](/OpignoEnterpriseAPI/Post/CreatePost#uploadedfileinput-object)       | The list of post images, each one should be formatted as base64 string. Up to 10 images can be shared, max file size - 20Mb. Allowed extensions: png, jpg, jpeg, gif. Leave empty to not attach any images to the post. **Warning**: once the post was created, this property cannot be updated.                 |
| `filesBase64`   | [\[`UploadedFileInput`\]](/OpignoEnterpriseAPI/Post/CreatePost#uploadedfileinput-object)       | The post files, each one should be formatted as base64 string. Up to 10 files can be shared, max file size - 20Mb. Allowed extensions: txt, pdf, doc, docx, xls, xlsx, ppt, pptx, svg. Leave empty to not attach any files to the post. **Warning**: once the post was created, this property cannot be updated. |
| `communityId`   | `ID`                                                                                           | Should be filled if the post relates to a community. Leave empty to create a regular post. In case if it's filled, the created post will be visible not only to the current user's network, but to all members of the given community. **Warning**: once the post was created, this property cannot be updated.  |

## `PostSharedContentInput` object

| Parameter     | Type                    | Description                                                                                                        |
| :------------ | :---------------------- | :----------------------------------------------------------------------------------------------------------------- |
| `contentId`   | `ID`                    | **Required**. ID of the shared content (learning path/certificate/badge).                                          |
| `contentType` | `PostSharedContentType` | **Required**. Contains the type of the shared content. Available options: `LEARNING_PATH`, `CERTIFICATE`, `BADGE`. |

The list of certificates that are available for sharing can be retrieved by calling [`getPaginatedUserCertificates`](/OpignoEnterpriseAPI/Certificate) query.

Only public trainings that have been started or passed by the current API user can be shared.
To get the list of learning paths (trainings) available for sharing, the [`getTrainingsForSharing`](/OpignoEnterpriseAPI/Post/GetTrainingsForSharing) query should be called.

Also, any badge that has been earned by the current API user can be shared. To get the list of the available badges, use query [`getBadges`](/OpignoEnterpriseAPI/Badges#getbadges).

## `UploadedFileInput` object

Represents an input data to upload a new file through the API.

| Parameter       | Type     | Description                                                                                                                                                                            |
| :-------------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `filename`      | `String` | **Required**. A name of the file that should be created. Available file extensions depend on the entity that should be created.                                                        |
| `contentBase64` | `String` | **Required**. File content formatted as a base64 string. The limit for the file upload is 20 Mb (or the limit that is set for the file upload on the server, if it's less than 20 Mb). |

## An example of a post creation

<CodeGroup>
  ```filename GraphQL theme={null}
    mutation createPost {
      createPost(data: {
        text: "This is a dummy post text",
        sharedContent: {
          contentId: 69,
          contentType: LEARNING_PATH
        }
      }) {
        response {
          id
          text
          created
          authorUserContext {
            id
            uuid
          }
          sharedContent {
          id
          type
          title
          description
          earnedOn
            image {
              alt
              title
              url
            }
          }
          cta {
            actionId
            title
            arguments {
              key
              value
            }
          }
        }
        errors
      }
    }
  ```

  ```File Query result [expandable] theme={null}
    {
      "data": {
        "createPost": {
          "response": {
            "id": "175",
            "text": "<p>This is a dummy post text</p>\n",
            "created": 1751641926,
            "authorUserContext": {
              "id": "915",
              "uuid": "5acfc440-88e0-4286-b089-c0f03575ed9a"
            },
            "sharedContent": {
              "id": "69",
              "type": "LEARNING_PATH",
              "title": "How far would you go for a Nespresso coffee?",
              "description": "<p>How far would you go for the Unforgettable Taste of a Nespresso coffee? Nespresso reunites George Clooney and Jean Dujardin on screen in new action-comedy commercial.</p>",
              "earnedOn": null,
              "image": {
                "alt": null,
                "title": "Nespresso - Quiz.jpg",
                "url": "http://opigno4-project.docksal.site:8080/sites/default/files/2025-02/Nespresso%20-%20Quiz.jpg"
              }
            },
            "cta": [
              {
                "actionId": "COMMENT_POST",
                "title": "Comment",
                "arguments": [
                  {
                    "key": "postId",
                    "value": "175"
                  }
                ]
              },
              {
                "actionId": "PIN_POST",
                "title": "Pin the post to the top",
                "arguments": [
                  {
                    "key": "postId",
                    "value": "175"
                  }
                ]
              },
              {
                "actionId": "EDIT_POST",
                "title": "Edit the post",
                "arguments": [
                  {
                    "key": "postId",
                    "value": "175"
                  }
                ]
              },
              {
                "actionId": "DELETE_POST",
                "title": "Delete the post",
                "arguments": [
                  {
                    "key": "postId",
                    "value": "175"
                  }
                ]
              },
              {
                "actionId": "TOGGLE_LIKE",
                "title": "Toggle like",
                "arguments": [
                  {
                    "key": "postId",
                    "value": "175"
                  }
                ]
              }
            ]
          }
          "errors": []
        }
      }
    }
  ```
</CodeGroup>

The mutation returns a `Post` object. Detailed description and the full list of available properties can be found [here](/OpignoEnterpriseAPI/Post/GetPost).
