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

# Validate a Post

> Validate a post before publishing

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "basic") {
      displayPlans = ["Basic", "Premium", "Business", "Enterprise"];
    } else if (lowerCasePlan === "business") {
      displayPlans = ["Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

<PlansAvailable plans={["premium"]} maxPackRequired={false} />

Before publishing a post, you can verify the content and parameters are correct.
Send the exact same JSON you normally send to the `/post` endpoint to the `/validate/post` endpoint and it will return a response with any issues found.

<ul class="custom-bullets">
  <li>Validation tests based on Ayrshare's own internal algorithms.</li>
  <li>Posts are not sent to the social networks.</li>

  <li>
    Posts may still return an error by the social networks at the time of publishing, even with a
    passed validation.
  </li>
</ul>

Please see the [/post endpoint](/apis/post/overview) for sending a post.

## Header Parameters

<HeaderAPI noProfileKey />

## Body Parameters

Send the same body as you would send to the [/post endpoint](/apis/post/post).

<RequestExample>
  ```bash cURL theme={"system"}
  curl --location "https://api.ayrshare.com/api/validate/post" \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer API_KEY" \
  --data '{
    "post": "This is amazing",
    "platforms": [
    "facebook"
    ],
    "mediaUrls": ["https://img.ayrshare.com/012/gb.jpg"]
  }'
  ```

  ```javascript JavaScript theme={"system"}
  const apiKey = 'API_KEY'; // Replace with your actual API key

  const requestData = {
    post: "This is amazing",
    platforms: ["facebook"],
    mediaUrls: ["https://img.ayrshare.com/012/gb.jpg"]
  };

  fetch('https://api.ayrshare.com/api/validate/post', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${apiKey}`
    },
    body: JSON.stringify(requestData)
  })
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));
  ```

  ```python Python theme={"system"}
  import requests

  payload = {
  'post': 'This is amazing',
  'platforms': ['facebook'],
  'mediaUrls': ['https://img.ayrshare.com/012/gb.jpg']
  }

  headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer API_KEY'
  }

  r = requests.post(
  'https://api.ayrshare.com/api/validate/post',
  json=payload,
  headers=headers
  )

  print(r.json())

  ```

  ```php PHP theme={"system"}
  <?php

  $payload = [
      'post' => 'This is amazing',
      'platforms' => ['facebook'],
      'mediaUrls' => ['https://img.ayrshare.com/012/gb.jpg']
  ];

  $headers = [
      'Content-Type: application/json',
      'Authorization: Bearer API_KEY'
  ];

  $ch = curl_init('https://api.ayrshare.com/api/validate/post');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  curl_close($ch);

  $result = json_decode($response, true);
  print_r($result);
  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Net.Http.Json;
  using System.Text.Json;
  using System.Threading.Tasks;

  class Program
  {
      static async Task Main()
      {
          var payload = new
          {
              post = "This is amazing",
              platforms = new[] { "facebook" },
              mediaUrls = new[] { "https://img.ayrshare.com/012/gb.jpg" }
          };

          using var client = new HttpClient();
          client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");

          try
          {
              var response = await client.PostAsJsonAsync(
                  "https://api.ayrshare.com/api/validate/post",
                  payload
              );

              response.EnsureSuccessStatusCode();
              var result = await response.Content.ReadAsStringAsync();
              Console.WriteLine(result);
          }
          catch (HttpRequestException ex)
          {
              Console.WriteLine($"Error: {ex.Message}");
          }
      }
  }
  ```

  ```go Go theme={"system"}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "io"
      "log"
      "net/http"
  )

  type PostRequest struct {
      Post      string   `json:"post"`
      Platforms []string `json:"platforms"`
      MediaUrls []string `json:"mediaUrls"`
  }

  func main() {
      // Create the request payload
      payload := PostRequest{
          Post:      "This is amazing",
          Platforms: []string{"facebook"},
          MediaUrls: []string{"https://img.ayrshare.com/012/gb.jpg"},
      }

      // Convert payload to JSON
      jsonData, err := json.Marshal(payload)
      if err != nil {
          log.Fatalf("Error marshaling JSON: %v", err)
      }

      // Create the request
      req, err := http.NewRequest(
          "POST",
          "https://api.ayrshare.com/api/validate/post",
          bytes.NewBuffer(jsonData),
      )
      if err != nil {
          log.Fatalf("Error creating request: %v", err)
      }

      // Set headers
      req.Header.Set("Content-Type", "application/json")
      req.Header.Set("Authorization", "Bearer API_KEY")

      // Make the request
      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          log.Fatalf("Error making request: %v", err)
      }
      defer resp.Body.Close()

      // Read the response
      body, err := io.ReadAll(resp.Body)
      if err != nil {
          log.Fatalf("Error reading response: %v", err)
      }

      // Print the response
      fmt.Println(string(body))
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200: Success theme={"system"}
  {
      "status": "success",
      "message": "No validation issues were found with this post. This is only an Ayrshare validation test and the post may still return an error by the social networks.",
  }
  ```

  ```json 200: Successful Post with Non-Fatal Warnings theme={"system"}
  {
    "status": "success",
    "message": "No validation issues were found with this post. This is only an Ayrshare validation test and the post may still return an error by the social networks.",
    "warnings": [
      {
        "action": "post",
        "status": "error",
        "code": 156,
        "message": "Twitter is not linked with Ayrshare. Please confirm the linkage on the Social Accounts page in your dashboard."
      }
    ]
  }
  ```

  ```json 400: Error Post theme={"system"}
  {
    "action": "post",
    "status": "error",
    "code": 136,
    "message": "Media URLs invalid. Please verify the media is an externally accessible URL."
  }
  ```
</ResponseExample>
