Learn how to automate Pinterest uploads with the Pinterest API and cron job scheduling.
This script demonstrates how to automatically post pins to Pinterest using the Pinterest API. Perfect for content creators and marketers who want to schedule their pins in advance.
#!/usr/bin/env python3
import requests
import os
from dotenv import load_dotenv
load_dotenv()
# Pinterest API Configuration
ACCESS_TOKEN = os.getenv("PINTEREST_ACCESS_TOKEN")
BOARD_ID = os.getenv("PINTEREST_BOARD_ID")
def create_pin(image_url, title, description, link):
url = "https://api.pinterest.com/v5/pins"
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Content-Type": "application/json"
}
data = {
"board_id": BOARD_ID,
"title": title,
"description": description,
"link": link,
"media_source": {
"source_type": "image_url",
"url": image_url
}
}
response = requests.post(url, json=data, headers=headers)
if response.status_code == 201:
print(f"✅ Pin created successfully: {title}")
return response.json()
else:
print(f"❌ Error: {response.status_code} - {response.text}")
return None
if __name__ == "__main__":
# Example usage
create_pin(
image_url="https://example.com/image.jpg",
title="My Automated Pin",
description="This pin was posted automatically using Python!",
link="https://integratescript.com"
)