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

# Create BlogPost

> Create a new BlogPost record.

A **BlogPost** represents an article published on the Members Portal. Articles can be used to share news, updates, or useful content with customers.

Articles support scheduled publishing via `PublishDate` and automatic unpublishing via `UnpublishDate`. Setting a `PublishDate` in the past publishes the article immediately; setting a future date schedules it. Leaving `UnpublishDate` blank keeps the article published until it is manually unpublished or deleted.

Each article has a `SummaryText` (short overview displayed at the top) and a `FullText` (the main body content). Articles can be organised into categories using the `BlogCategory` entity and can optionally allow customer comments.

Visibility can be controlled with `OnlyForMembers` (customers with an active contract) and `OnlyForContacts` (customers without an active contract). Articles can also be featured on the Members Portal home page before login (`ShowInHomeBanner`) or after login (`ShowInHomePage`).

## Authentication

<Note>
  This endpoint requires OAuth2 authentication. Include a valid bearer token in the `Authorization` header.
  The authenticated user must be a full unrestricted administrator or have the **`BlogPost-Create`** role.
</Note>

## Request Body

### Required Fields

<ParamField body="BusinessId" type="integer" required>
  Business Id.
</ParamField>

<ParamField body="Title" type="string" required>
  Article title.
</ParamField>

<ParamField body="CommentsCount" type="integer" required>
  Number of comments on this article.
</ParamField>

### Optional Fields

<ParamField body="LanguageId" type="integer">
  Language Id.
</ParamField>

<ParamField body="PostedById" type="integer">
  Posted By Id.
</ParamField>

<ParamField body="SummaryText" type="string">
  Short overview displayed at the top of the article.
</ParamField>

<ParamField body="FullText" type="string">
  Main body content of the article.
</ParamField>

<ParamField body="NewImageUrl" type="string">
  New Image Url.
</ParamField>

<ParamField body="ClearImageFile" type="boolean">
  Clear Image File.
</ParamField>

<ParamField body="NewLargeImageUrl" type="string">
  New Large Image Url.
</ParamField>

<ParamField body="ClearLargeImageFile" type="boolean">
  Clear Large Image File.
</ParamField>

<ParamField body="PublishDate" type="string">
  Date and time when the article is published. Past dates publish immediately; future dates schedule publication.
</ParamField>

<ParamField body="ShowInHomeBanner" type="boolean">
  Feature this article on the Members Portal home page before users log in.
</ParamField>

<ParamField body="ShowInHomePage" type="boolean">
  Feature this article on the Members Portal home page after users log in.
</ParamField>

<ParamField body="UnpublishDate" type="string">
  Date and time when the article is automatically unpublished. Leave blank to keep published indefinitely.
</ParamField>

<ParamField body="AllowComments" type="boolean">
  Whether customers can post comments on this article.
</ParamField>

<ParamField body="BlogCategories" type="integer[]">
  Blog Categories.
</ParamField>

<ParamField body="OnlyForContacts" type="boolean">
  Restrict visibility to contacts (customers without an active contract).
</ParamField>

<ParamField body="OnlyForMembers" type="boolean">
  Restrict visibility to members (customers with an active contract).
</ParamField>

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    "https://spaces.nexudus.com/api/content/blogposts" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "BusinessId": 0,
      "Title": "",
      "CommentsCount": 0
  }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://spaces.nexudus.com/api/content/blogposts',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        BusinessId: 0,
        Title: '',
        CommentsCount: 0
      })
    }
  );

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://spaces.nexudus.com/api/content/blogposts',
      headers={
          'Authorization': 'Bearer YOUR_TOKEN',
          'Content-Type': 'application/json'
      },
      json={
          'BusinessId': 0,
          'Title': '',
          'CommentsCount': 0
      }
  )

  data = response.json()
  ```
</CodeGroup>

## Response

### 200

<ResponseField name="Status" type="integer">
  HTTP status code. `200` on success.
</ResponseField>

<ResponseField name="Message" type="string">
  A human-readable message confirming the creation.
</ResponseField>

<ResponseField name="Value" type="object">
  Contains the `Id` of the newly created record.
</ResponseField>

<ResponseField name="WasSuccessful" type="boolean">
  `true` if the blogpost was created successfully.
</ResponseField>

<ResponseField name="Errors" type="array">
  `null` on success.
</ResponseField>

```json Example Response theme={null}
{
  "Status": 200,
  "Message": "BlogPost was successfully created.",
  "Value": {
    "Id": 87654321
  },
  "OpenInDialog": false,
  "OpenInWindow": false,
  "RedirectURL": null,
  "JavaScript": null,
  "UpdatedOn": "2025-01-15T10:30:00Z",
  "UpdatedBy": "admin@example.com",
  "Errors": null,
  "WasSuccessful": true
}
```

### 400

<ResponseField name="Message" type="string">
  A summary of the validation error(s), in the format `PropertyName: error message`.
</ResponseField>

<ResponseField name="Value" type="any">
  `null` on validation failure.
</ResponseField>

<ResponseField name="Errors" type="object[]">
  Array of validation errors.

  <Expandable>
    <ResponseField name="AttemptedValue" type="any">
      The value that was submitted for the field, or `null` if missing.
    </ResponseField>

    <ResponseField name="Message" type="string">
      The validation error message.
    </ResponseField>

    <ResponseField name="PropertyName" type="string">
      The name of the property that failed validation.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="WasSuccessful" type="boolean">
  `false` when the request fails validation.
</ResponseField>

```json Example Response theme={null}
{
  "Message": "Title: is a required field",
  "Value": null,
  "Errors": [
    {
      "AttemptedValue": null,
      "Message": "is a required field",
      "PropertyName": "Title"
    }
  ],
  "WasSuccessful": false
}
```
