Back to API Reference

Data Sync API

Automate data synchronization from connected sources (Google Sheets, Microsoft Excel, SQL Server) on scheduled intervals.

---

Base URL

https://app.datapublisher.io/api/sync

---

Authentication

All endpoints require JWT authentication via Authorization: Bearer header.

---

Overview

The Data Sync API allows you to:

Supported Sync Sources:

Sync Frequencies:

---

Sync Schedules

Create Sync Schedule

Create a new automated sync schedule.

Endpoint: POST /schedules

Headers:

Authorization: Bearer 

Content-Type: application/json

Request Body (Google Sheets sync):

{

"name": "Sales Data Hourly Sync",

"dataSourceId": "google-sheets-uuid",

"frequency": "hourly",

"targetFileId": "csv-file-uuid",

"enabled": true,

"config": {

"spreadsheetId": "1ABC-DEF",

"sheetName": "Sales Data",

"range": "A1:L1000"

}

}

Request Body (Excel sync):

{

"name": "Customer Database Daily Sync",

"dataSourceId": "microsoft-excel-uuid",

"frequency": "daily",

"targetFileId": "csv-file-uuid",

"enabled": true,

"config": {

"workbookId": "01AZJL5P...",

"worksheetName": "Customers",

"syncTime": "06:00"

}

}

Request Body (SQL Server sync):

{

"name": "Orders Weekly Sync",

"dataSourceId": "sql-server-uuid",

"frequency": "weekly",

"targetFileId": "csv-file-uuid",

"enabled": true,

"config": {

"databaseName": "SalesDB",

"query": "SELECT * FROM dbo.Orders WHERE OrderDate >= DATEADD(day, -7, GETDATE())",

"dayOfWeek": "monday",

"syncTime": "08:00"

}

}

Response (200 OK):

{

"success": true,

"schedule": {

"id": "schedule-uuid",

"name": "Sales Data Hourly Sync",

"dataSourceId": "google-sheets-uuid",

"dataSourceType": "google-sheets",

"targetFileId": "csv-file-uuid",

"frequency": "hourly",

"enabled": true,

"config": {

"spreadsheetId": "1ABC-DEF",

"sheetName": "Sales Data",

"range": "A1:L1000"

},

"nextSyncAt": "2026-02-12T11:00:00Z",

"createdAt": "2026-02-12T10:30:00Z"

},

"message": "Sync schedule created successfully"

}

---

List Sync Schedules

Get all sync schedules for the user.

Endpoint: GET /schedules

Headers:

Authorization: Bearer 

Query Parameters:

Response (200 OK):

{

"success": true,

"schedules": [

{

"id": "schedule-uuid-1",

"name": "Sales Data Hourly Sync",

"dataSourceType": "google-sheets",

"frequency": "hourly",

"enabled": true,

"lastSyncAt": "2026-02-12T10:00:00Z",

"nextSyncAt": "2026-02-12T11:00:00Z",

"lastSyncStatus": "success",

"lastSyncRowCount": 150

},

{

"id": "schedule-uuid-2",

"name": "Customer Database Daily Sync",

"dataSourceType": "microsoft-excel",

"frequency": "daily",

"enabled": true,

"lastSyncAt": "2026-02-12T06:00:00Z",

"nextSyncAt": "2026-02-13T06:00:00Z",

"lastSyncStatus": "success",

"lastSyncRowCount": 500

},

{

"id": "schedule-uuid-3",

"name": "Orders Weekly Sync",

"dataSourceType": "sql-server",

"frequency": "weekly",

"enabled": false,

"lastSyncAt": "2026-02-05T08:00:00Z",

"nextSyncAt": null,

"lastSyncStatus": "error",

"lastSyncError": "SQL Server connection timeout"

}

],

"totalCount": 3

}

---

Get Sync Schedule Details

Get detailed information about a specific schedule.

Endpoint: GET /schedules/:scheduleId

Headers:

Authorization: Bearer 

Path Parameters:

Response (200 OK):

{

"success": true,

"schedule": {

"id": "schedule-uuid-1",

"name": "Sales Data Hourly Sync",

"dataSourceId": "google-sheets-uuid",

"dataSourceType": "google-sheets",

"dataSourceName": "Sales Tracking Spreadsheet",

"targetFileId": "csv-file-uuid",

"targetFileName": "sales-data.csv",

"frequency": "hourly",

"enabled": true,

"config": {

"spreadsheetId": "1ABC-DEF",

"sheetName": "Sales Data",

"range": "A1:L1000"

},

"lastSyncAt": "2026-02-12T10:00:00Z",

"nextSyncAt": "2026-02-12T11:00:00Z",

"lastSyncStatus": "success",

"lastSyncRowCount": 150,

"lastSyncDuration": "1.2s",

"createdAt": "2026-01-15T10:00:00Z",

"updatedAt": "2026-02-12T10:00:00Z"

}

}

---

Update Sync Schedule

Update schedule configuration.

Endpoint: PUT /schedules/:scheduleId

Headers:

Authorization: Bearer 

Content-Type: application/json

Request Body:

{

"name": "Updated Schedule Name",

"frequency": "daily",

"enabled": true,

"config": {

"syncTime": "09:00"

}

}

Response (200 OK):

{

"success": true,

"schedule": {

"id": "schedule-uuid",

"name": "Updated Schedule Name",

"frequency": "daily",

"enabled": true,

"nextSyncAt": "2026-02-13T09:00:00Z"

},

"message": "Sync schedule updated successfully"

}

---

Delete Sync Schedule

Remove a sync schedule.

Endpoint: DELETE /schedules/:scheduleId

Headers:

Authorization: Bearer 

Response (200 OK):

{

"success": true,

"message": "Sync schedule deleted successfully"

}

Note: Does not delete target CSV file, only removes the sync schedule.

---

Manual Sync Operations

Trigger Manual Sync

Manually execute a sync schedule immediately.

Endpoint: POST /schedules/:scheduleId/sync

Headers:

Authorization: Bearer 

Response (200 OK):

{

"success": true,

"syncResult": {

"scheduleId": "schedule-uuid",

"status": "success",

"rowCount": 150,

"columnCount": 12,

"duration": "1.2s",

"syncedAt": "2026-02-12T10:45:00Z",

"changes": {

"added": 5,

"updated": 10,

"deleted": 2

}

},

"message": "Manual sync completed successfully"

}

Response (500 Internal Server Error) - Failed:

{

"success": false,

"error": "Sync failed",

"message": "Google Sheets API quota exceeded",

"retryAfter": "2026-02-12T11:00:00Z"

}

---

Sync History

Get Sync History

View sync execution history for a schedule.

Endpoint: GET /schedules/:scheduleId/history

Headers:

Authorization: Bearer 

Query Parameters:

Response (200 OK):

{

"success": true,

"history": [

{

"id": "sync-log-uuid-1",

"scheduleId": "schedule-uuid",

"status": "success",

"startedAt": "2026-02-12T10:00:00Z",

"completedAt": "2026-02-12T10:00:01.2Z",

"duration": "1.2s",

"rowCount": 150,

"columnCount": 12,

"changes": {

"added": 5,

"updated": 10,

"deleted": 2

}

},

{

"id": "sync-log-uuid-2",

"scheduleId": "schedule-uuid",

"status": "error",

"startedAt": "2026-02-12T09:00:00Z",

"completedAt": "2026-02-12T09:00:15Z",

"duration": "15s",

"error": "Token expired - re-authentication required"

}

],

"totalCount": 2,

"pagination": {

"limit": 50,

"offset": 0,

"hasMore": false

}

}

---

Configuration Options

Frequency Settings

Hourly:

{

"frequency": "hourly"

}

Daily:

{

"frequency": "daily",

"config": {

"syncTime": "06:00"

}

}

Weekly:

{

"frequency": "weekly",

"config": {

"dayOfWeek": "monday",

"syncTime": "08:00"

}

}

---

Rate Limiting

---

Common Error Codes

| Status Code | Description |

|-------------|-------------|

| 400 | Invalid schedule configuration |

| 401 | Unauthorized - invalid JWT |

| 403 | Data source access denied or token expired |

| 404 | Schedule or data source not found |

| 429 | Rate limit exceeded |

| 500 | Sync execution failed |

---

Usage Examples

JavaScript

// Create hourly sync

async function createHourlySync(dataSourceId, targetFileId) {

const response = await fetch('https://app.datapublisher.io/api/sync/schedules', {

method: 'POST',

headers: {

'Authorization': Bearer ${jwtToken},

'Content-Type': 'application/json'

},

body: JSON.stringify({

name: 'Hourly Data Sync',

dataSourceId: dataSourceId,

targetFileId: targetFileId,

frequency: 'hourly',

enabled: true

})

});

return await response.json();

}

// List all schedules

async function listSyncSchedules() {

const response = await fetch('https://app.datapublisher.io/api/sync/schedules', {

headers: { 'Authorization': Bearer ${jwtToken} }

});

const { schedules } = await response.json();

return schedules;

}

// Trigger manual sync

async function manualSync(scheduleId) {

const response = await fetch(https://app.datapublisher.io/api/sync/schedules/${scheduleId}/sync, {

method: 'POST',

headers: { 'Authorization': Bearer ${jwtToken} }

});

return await response.json();

}

// Get sync history

async function getSyncHistory(scheduleId) {

const response = await fetch(https://app.datapublisher.io/api/sync/schedules/${scheduleId}/history, {

headers: { 'Authorization': Bearer ${jwtToken} }

});

const { history } = await response.json();

return history;

}

// Delete schedule

async function deleteSchedule(scheduleId) {

const response = await fetch(https://app.datapublisher.io/api/sync/schedules/${scheduleId}, {

method: 'DELETE',

headers: { 'Authorization': Bearer ${jwtToken} }

});

return await response.json();

}

---

Best Practices

  • Frequency: Choose appropriate sync frequency based on data update rate
  • Off-Peak Hours: Schedule daily/weekly syncs during off-peak hours
  • Error Monitoring: Monitor sync history for failures
  • Token Refresh: Ensure OAuth2 tokens are valid (Google/Microsoft)
  • Query Optimization: Optimize SQL queries for better performance
  • Target Files: Create separate target files for different sync purposes
  • Testing: Test manual sync before enabling automated schedule
  • ---

    Related Documentation