import requests
# Define the API endpoint
url = "https://app.stammer.ai/en/chatbot/api/website/crawl"
# Set up authentication and headers
headers = {
'Authorization': 'Token <YOUR-API-TOKEN>',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
# Data is passed in the request body as JSON
data = {
"website_urls": ['Item 1', 'Item 2', 'Item 3'],
"max_urls_to_scrape": 610,
"follow_links": True,
"auto_scraping": True,
"use_readability": True,
"use_advance_scraper": True,
"scrape_images": True,
"scroll_to_end": True,
"wait_for": 610,
"chatbot_uuid": "12345678-1234-5678-1234-567812345678",
"initiate_training": True
}
response = requests.post(url, headers=headers, json=data)
# Process the response
if response.status_code in (200, 201, 202):
result = response.json()
print("Response data:", result)
else:
try:
error_data = response.json()
error_message = error_data.get('message') or error_data.get('error', 'Unknown error')
print(f"Error: {error_message}")
except ValueError:
print(f"Error: Status code {response.status_code}")