DEV Community

Hommy
Hommy

Posted on

[JCAIGC]Save CapCut draft

SAVE_DRAFT API Documentation

πŸ“‹ Table of Contents

πŸ”§ Interface Information

POST /openapi/capcut-mate/v1/save_draft
Enter fullscreen mode Exit fullscreen mode

Function Description

Save CapCut draft. This interface is used to save the current draft state, ensuring that edited content is persistently stored. This interface is usually called after completing a series of editing operations to prevent loss of edited content.

More Documentation

πŸ“– For more detailed documentation and tutorials, please visit: https://docs.jcaigc.cn

Request Parameters

{
  "draft_url": "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258"
}
Enter fullscreen mode Exit fullscreen mode

Parameter Description

Parameter Name Type Required Default Value Description
draft_url string βœ… - Draft URL to be saved

Parameter Details

draft_url

  • Type: String
  • Required: Yes
  • Format: Complete draft URL, usually returned by the create_draft interface
  • Example: https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258"draft_url": "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258" } ``

Response Field Description

Field Name Type Description
draft_url string Saved draft URL, usually the same as the URL in the request

Error Response (4xx/5xx)

`json
{
"detail": "Error description"
}
`

Usage Examples

cURL Example

1. Basic Draft Save

`bash
curl -X POST https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/save_draft \
-H "Content-Type: application/json" \
-d '{
"draft_url": "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258"
}'
`

JavaScript Example

`javascript
const saveDraft = async (draftUrl) => {
const response = await fetch('/openapi/capcut-mate/v1/save_draft', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ draft_url: draftUrl })
});
return response.json();
};

// Save draft
const draftUrl = "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258";
const result = await saveDraft(draftUrl);
console.log('Draft saved successfully:', result.draft_url);
`

Advanced JavaScript Example

`javascript
class DraftManager {
constructor(baseUrl = 'https://capcut-mate.jcaigc.cn') {
this.baseUrl = baseUrl;
}

async saveDraft(draftUrl) {
const response = await fetch(${this.baseUrl}/openapi/capcut-mate/v1/save_draft, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ draft_url: draftUrl })
});

if (!response.ok) {
  throw new Error(`Failed to save draft: ${response.statusText}`);
}

return response.json();
Enter fullscreen mode Exit fullscreen mode

}

// Auto-save function
async autoSave(draftUrl, intervalMs = 30000) {
const saveInterval = setInterval(async () => {
try {
await this.saveDraft(draftUrl);
console.log(Auto-save successful: ${new Date().toLocaleTimeString()});
} catch (error) {
console.error('Auto-save failed:', error);
}
}, intervalMs);

// Return function to stop auto-save
return () => clearInterval(saveInterval);
Enter fullscreen mode Exit fullscreen mode

}

// Save during editing workflow
async editWorkflow(draftUrl, operations) {
const results = [];

for (const operation of operations) {
  try {
    // Execute editing operation (example here)
    const editResult = await operation();
    results.push(editResult);

    // Auto-save after each operation
    await this.saveDraft(draftUrl);
    console.log(`Operation completed and saved: ${operation.name}`);

  } catch (error) {
    console.error(`Operation failed: ${operation.name}`, error);
    results.push({ error: error.message });
  }
}

return results;
Enter fullscreen mode Exit fullscreen mode

}

// Batch save multiple drafts
async saveMutipleDrafts(draftUrls) {
const results = {};

for (const [name, url] of Object.entries(draftUrls)) {
  try {
    const result = await this.saveDraft(url);
    results[name] = result;

    // Add delay to avoid too fast requests
    await new Promise(resolve => setTimeout(resolve, 100));
  } catch (error) {
    console.error(`Failed to save draft ${name}:`, error);
    results[name] = { error: error.message };
  }
}

return results;
Enter fullscreen mode Exit fullscreen mode

}
}

// Usage example
const draftManager = new DraftManager();

// Basic save
const draftUrl = "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258";
await draftManager.saveDraft(draftUrl);

// Start auto-save (save every 30 seconds)
const stopAutoSave = await draftManager.autoSave(draftUrl, 30000);

// Stop auto-save after editing is complete
setTimeout(() => {
stopAutoSave();
console.log('Auto-save stopped');
}, 300000); // Stop after 5 minutes

// Batch save multiple drafts
const multipleDrafts = {
"project1": "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258",
"project2": "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258"
};
const saveResults = await draftManager.saveMutipleDrafts(multipleDrafts);
`

Python Example

`python
import requests
import time
import threading
from typing import Dict, List, Callable

class DraftSaver:
def init(self, base_url: str = "https://assets.jcaigc.cn"):
self.base_url = base_url
self._auto_save_threads = {}

def save_draft(self, draft_url: str) -> Dict:
"""Save draft"""
response = requests.post(
f'{self.base_url}/openapi/capcut-mate/v1/save_draft',
headers={'Content-Type': 'application/json'},
json={"draft_url": draft_url}
)
response.raise_for_status()
return response.json()

def auto_save(self, draft_url: str, interval_seconds: int = 30) -> str:
"""Start auto-save, return thread ID for stopping"""
def save_loop():
while True:
try:
self.save_draft(draft_url)
print(f"Auto-save successful: {time.strftime('%H:%M:%S')}")
time.sleep(interval_seconds)
except Exception as e:
print(f"Auto-save failed: {e}")
time.sleep(5) # Wait 5 seconds before retry after error

thread_id = f"auto_save_{int(time.time())}"
thread = threading.Thread(target=save_loop, daemon=True)
thread.start()
self._auto_save_threads[thread_id] = thread

return thread_id
Enter fullscreen mode Exit fullscreen mode

def stop_auto_save(self, thread_id: str):
"""Stop auto-save"""
if thread_id in self._auto_save_threads:
# Thread is daemon, will stop automatically when program ends
del self._auto_save_threads[thread_id]
print(f"Auto-save thread {thread_id} marked to stop")

def save_with_retry(self, draft_url: str, max_retries: int = 3) -> Dict:
"""Save with retry mechanism"""
for attempt in range(max_retries):
try:
return self.save_draft(draft_url)
except Exception as e:
if attempt == max_retries - 1:
raise e
print(f"Save failed, attempt {attempt + 1} retry: {e}")
time.sleep(2 ** attempt) # Exponential backoff

Enter fullscreen mode Exit fullscreen mode




Usage example

saver = DraftSaver()

Basic save

draft_url = "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258"
result = saver.save_draft(draft_url)
print(f"Draft saved successfully: {result['draft_url']}")

Save with retry

try:
result = saver.save_with_retry(draft_url, max_retries=3)
print("Save successful (with retry mechanism)")
except Exception as e:
print(f"Save ultimately failed: {e}")

Start auto-save

auto_save_id = saver.auto_save(draft_url, interval_seconds=30)
print(f"Auto-save started, ID: {auto_save_id}")

Stop auto-save after 10 minutes

time.sleep(600)
saver.stop_auto_save(auto_save_id)
`

Error Codes

Error Code Error Message Description Solution
400 draft_url is required Missing draft URL parameter Provide valid draft_url
400 Invalid draft_url format URL format is incorrect Check if URL format is correct
404 Draft does not exist Specified draft cannot be found Confirm if draft URL is correct and exists
500 Save failed Internal service error Contact technical support or retry later
503 Service unavailable System under maintenance Retry later

Notes

  1. URL Validity: Ensure the draft_url passed in is valid and exists
  2. Network Stability: Save operation requires stable network connection
  3. Frequency Control: Avoid too frequent save operations
  4. Auto-save: It is recommended to enable auto-save feature for long editing sessions
  5. Error Handling: There should be retry mechanism when save fails
  6. Concurrency Safety: Concurrent saves of the same draft may cause conflicts

Workflow

  1. Validate draft_url parameter
  2. Check if draft exists
  3. Get current draft state
  4. Persistently save draft data
  5. Return save result

Best Practices

  1. Regular Save: Save promptly after important operations
  2. Auto-save: Set up auto-save for long editing sessions
  3. Error Recovery: Provide retry mechanism when save fails
  4. Status Display: Show save status to users
  5. Backup Strategy: Consider multi-version backup mechanism

Related Interfaces


πŸ“š Project Resources

GitHub: https://github.com/Hommy-master/capcut-mate

Gitee: https://gitee.com/taohongmin-gitee/capcut-mate

Top comments (0)