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

# Retry Posts

> Retry one or more failed posts

## Endpoint

```
POST https://api.ugc.inc/post/retry
```

## Overview

Retry one or more failed posts by resetting their status to `scheduled` and setting their post time to now. This allows you to re-attempt posting content that previously failed.

<Warning>
  **Important Restrictions:**

  * You can **only** retry posts with status `failed`
  * Posts with other statuses (`scheduled`, `pending`, `complete`, `retrying`) **cannot** be retried using this endpoint
  * The retry will reset the post time to the current time and change the status to `scheduled`
</Warning>

## Request Body

<ParamField body="postIds" type="string[]" required>
  Array of post IDs to retry

  All posts must belong to your organization and must have status `failed`
</ParamField>

## Response

<ResponseField name="data" type="object">
  Retry result information

  <Expandable title="Result properties">
    <ResponseField name="retried" type="number">
      Number of posts successfully retried
    </ResponseField>

    <ResponseField name="ids" type="string[]">
      Array of retried post IDs
    </ResponseField>
  </Expandable>
</ResponseField>

## Error Cases

* **400 Bad Request**: Attempting to retry posts that are not in failed status
* **404 Not Found**: Some posts don't exist or don't belong to your organization
* **400 Bad Request**: No post IDs provided

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.ugc.inc/post/retry \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "postIds": ["post_abc123", "post_def456"]
    }'
  ```

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

  response = requests.post(
      'https://api.ugc.inc/post/retry',
      headers={
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json'
      },
      json={
          'postIds': ['post_abc123', 'post_def456']
      }
  )

  data = response.json()

  if data['ok']:
      print(f"Retried {data['data']['retried']} posts")
      print("Posts will be reattempted shortly")
  else:
      print(f"Error: {data['message']}")
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.ugc.inc/post/retry', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      postIds: ['post_abc123', 'post_def456']
    })
  });

  const data = await response.json();

  if (data.ok) {
    console.log(`Retried ${data.data.retried} posts`);
    console.log('Posts will be reattempted shortly');
  } else {
    console.error(`Error: ${data.message}`);
  }
  ```

  ```typescript React theme={null}
  import { UGCClient } from 'ugcinc';

  const client = new UGCClient({
    apiKey: 'YOUR_API_KEY'
  });

  // Retry multiple failed posts
  const response = await client.posts.retryPosts({
    postIds: ['post_abc123', 'post_def456']
  });

  if (response.ok) {
    console.log(`Successfully retried ${response.data.retried} posts`);
    console.log('Retried IDs:', response.data.ids);
    console.log('Posts will be reattempted shortly');
  } else {
    console.error(`Error: ${response.message}`);
    // Common errors:
    // - "Cannot retry X post(s) that are not in failed status"
    // - "Some posts not found or don't belong to your organization"
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "ok": true,
    "code": 200,
    "message": "Successfully retried 2 post(s)",
    "data": {
      "retried": 2,
      "ids": [
        "post_abc123",
        "post_def456"
      ]
    }
  }
  ```

  ```json Error - Not Failed Status theme={null}
  {
    "ok": false,
    "code": 400,
    "message": "Cannot retry 2 post(s) that are not in failed status"
  }
  ```

  ```json Error - Not Found theme={null}
  {
    "ok": false,
    "code": 404,
    "message": "Some posts not found or don't belong to your organization"
  }
  ```

  ```json Error - No Post IDs theme={null}
  {
    "ok": false,
    "code": 400,
    "message": "No post IDs provided"
  }
  ```
</ResponseExample>

## What Happens When You Retry

When you retry a failed post, the system:

1. **Updates the status** from `failed` to `scheduled`
2. **Sets the post time** to the current time (now)
3. **Resets the retry count** to 0
4. **Queues the post** for immediate processing

The post will be picked up by the posting system and attempted again shortly.

## Best Practices

<Tip>
  **Check post status before retrying:**

  Always verify that posts have failed before attempting to retry them. Use the [Get Posts](/api-reference/endpoint/posts-get) endpoint to check post statuses first.
</Tip>

<Steps>
  <Step title="Fetch posts">
    Use the Get Posts endpoint to retrieve posts and check their status
  </Step>

  <Step title="Filter failed posts">
    Filter out posts with status `failed` from your post list
  </Step>

  <Step title="Retry posts">
    Call the retry endpoint with the filtered post IDs
  </Step>

  <Step title="Monitor status">
    Use the [Get Post Status](/api-reference/endpoint/posts-status) endpoint to track the retry attempt
  </Step>
</Steps>

### Example: Automatic Retry Workflow

```typescript theme={null}
// Get all posts
const postsResponse = await client.posts.getPosts();

if (postsResponse.ok) {
  // Filter posts that failed
  const failedPosts = postsResponse.data.filter(
    post => post.status === 'failed'
  );
  
  if (failedPosts.length > 0) {
    console.log(`Found ${failedPosts.length} failed posts`);
    
    const retryResponse = await client.posts.retryPosts({
      postIds: failedPosts.map(p => p.id)
    });
    
    if (retryResponse.ok) {
      console.log(`Retried ${retryResponse.data.retried} posts`);
      
      // Wait a bit and check status
      await new Promise(resolve => setTimeout(resolve, 5000));
      
      for (const postId of retryResponse.data.ids) {
        const statusResponse = await client.posts.getStatus({ postId });
        
        if (statusResponse.ok) {
          console.log(`Post ${postId} status: ${statusResponse.data.status}`);
        }
      }
    }
  }
}
```

## Common Retry Reasons

Posts typically fail for reasons such as:

* **Temporary network issues** - Retry usually succeeds
* **Account authentication expired** - May need account re-authorization
* **Platform rate limits** - Retry after waiting period
* **Content violations** - Review and modify content before retrying
* **Invalid media URLs** - Fix media URLs before retrying

<Note>
  If a post continues to fail after multiple retries, check the post details and error logs to identify the underlying issue. Some failures may require manual intervention or content modifications.
</Note>
