Skip to main content
POST
/
workspaces
/
{workspace}
/
templates
/
sync
Sync Templates
curl --request POST \
  --url https://lancepilot.com/api/v3/workspaces/{workspace}/templates/sync \
  --header 'Authorization: Bearer <token>'
{
  "data": {}
}

Overview

Synchronize template statuses from Meta (WhatsApp Business API provider). Updates all pending templates with their current approval status.
This endpoint only syncs templates with PENDING status. It fetches the latest status from Meta and updates your local database.

How It Works

  1. Checks if workspace has any templates with status: PENDING
  2. Fetches all templates from Meta’s API
  3. Matches templates by provider_id
  4. Updates local template statuses (APPROVED, REJECTED, etc.)

Response

Success (200 OK)

{
  "success": true,
  "message": "Templates synced successfully"
}

No Pending Templates (404)

{
  "success": false,
  "message": "No pending templates found"
}

Sync Failed (500)

{
  "success": false,
  "message": "Failed to sync the templates"
}

When to Use

After Template Creation

Sync after creating templates to check if they’ve been approved

After Template Update

Check status after updating existing templates

Periodic Checks

Run periodic syncs (e.g., every 30 minutes) for pending templates

Before Sending Messages

Ensure templates are approved before attempting to send

Status Transitions


Example Usage

cURL

curl -X POST \
  https://lancepilot.com/api/v3/workspaces/{workspace}/templates/sync \
  -H 'Authorization: Bearer YOUR_API_TOKEN'

JavaScript

async function syncTemplates(workspaceId) {
  const response = await fetch(
    `https://lancepilot.com/api/v3/workspaces/${workspaceId}/templates/sync`,
    {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${YOUR_API_TOKEN}`
      }
    }
  );
  
  const data = await response.json();
  console.log(data.message);
}

Python

import requests

def sync_templates(workspace_id, api_token):
    url = f"https://lancepilot.com/api/v3/workspaces/{workspace_id}/templates/sync"
    headers = {"Authorization": f"Bearer {api_token}"}
    
    response = requests.post(url, headers=headers)
    return response.json()

Workflow Example

1

Create Template

Create a new template via POST /templatesResponse: status: "PENDING"
2

Wait for Review

Meta typically reviews templates within 5-30 minutes
3

Sync Status

Call sync endpoint to update status
POST /workspaces/{workspace}/templates/sync
4

Check Result

Use GET /templates to verify new statusPossible results: APPROVED or REJECTED

Best Practices

Set up a background job to sync every 30 minutes:
setInterval(() => {
  syncTemplates(workspaceId);
}, 30 * 60 * 1000); // 30 minutes
async function syncWithRetry(workspaceId, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const result = await syncTemplates(workspaceId);
      if (result.success) return result;
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      await new Promise(r => setTimeout(r, 5000)); // Wait 5s
    }
  }
}
Check for pending templates before syncing:
const templates = await getTemplates(workspaceId);
const hasPending = templates.some(t => t.status === 'PENDING');

if (hasPending) {
  await syncTemplates(workspaceId);
}

Common Issues

No Pending TemplatesIf you receive a 404 error, it means there are no templates with PENDING status to sync. This is not an error condition.
Sync Failed (500)This usually indicates:
  • Channel connection issues
  • Meta API temporarily unavailable
  • Invalid channel credentials
Solution: Wait a few minutes and try again, or check channel connection status.

Pro Tip: Combine sync with webhooks (if available) to get real-time template status updates instead of polling.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

workspace
string<uuid>
required

ID of the workspace.

Response

data
object
required