Loading...
Loading...
Pinterest API v5 Development - Authentication, Pins, Boards, Analytics
npx skill4agent add rawveg/skillsforge-marketplace pinterest-apihttps://api.pinterest.com/v5/Authorization: Bearer {access_token}// Redirect user to Pinterest authorization page
const authUrl = `https://www.pinterest.com/oauth/?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&response_type=code&scope=boards:read,pins:read,user_accounts:read`;
window.location.href = authUrl;# After user authorizes, exchange authorization code for access token
curl -X POST https://api.pinterest.com/v5/oauth/token \
--header "Authorization: Basic {BASE64_ENCODED_CLIENT_CREDENTIALS}" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code={AUTHORIZATION_CODE}" \
--data-urlencode "redirect_uri={REDIRECT_URI}"# Encode client_id:client_secret
echo -n "your_client_id:your_client_secret" | base64{
"access_token": "pina_ABC123...",
"token_type": "bearer",
"expires_in": 2592000,
"refresh_token": "DEF456...",
"scope": "boards:read,pins:read,user_accounts:read"
}curl -X POST https://api.pinterest.com/v5/pins \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"link": "https://example.com/my-article",
"title": "My Amazing Pin Title",
"description": "Detailed description of the pin content",
"board_id": "123456789",
"media_source": {
"source_type": "image_url",
"url": "https://example.com/image.jpg"
}
}'curl -X GET https://api.pinterest.com/v5/pins/{PIN_ID} \
-H "Authorization: Bearer {ACCESS_TOKEN}"{
"id": "987654321",
"created_at": "2025-01-15T10:30:00",
"link": "https://example.com/my-article",
"title": "My Amazing Pin Title",
"description": "Detailed description of the pin content",
"board_id": "123456789",
"media": {
"media_type": "image",
"images": {
"150x150": { "url": "...", "width": 150, "height": 150 },
"400x300": { "url": "...", "width": 400, "height": 300 },
"originals": { "url": "...", "width": 1200, "height": 800 }
}
}
}curl -X PATCH https://api.pinterest.com/v5/pins/{PIN_ID} \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"title": "Updated Pin Title",
"description": "Updated description",
"link": "https://example.com/updated-link"
}'curl -X DELETE https://api.pinterest.com/v5/pins/{PIN_ID} \
-H "Authorization: Bearer {ACCESS_TOKEN}"curl -X POST https://api.pinterest.com/v5/boards \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"name": "My New Board",
"description": "A collection of my favorite ideas",
"privacy": "PUBLIC"
}'PUBLICPROTECTEDSECRETcurl -X GET https://api.pinterest.com/v5/boards \
-H "Authorization: Bearer {ACCESS_TOKEN}"curl -X GET https://api.pinterest.com/v5/boards/{BOARD_ID}/pins \
-H "Authorization: Bearer {ACCESS_TOKEN}"curl -X GET https://api.pinterest.com/v5/user_account \
-H "Authorization: Bearer {ACCESS_TOKEN}"{
"account_type": "BUSINESS",
"id": "123456789",
"username": "myusername",
"website_url": "https://example.com",
"profile_image": "https://i.pinimg.com/...",
"follower_count": 1500,
"following_count": 320,
"board_count": 25,
"pin_count": 450
}curl -X GET "https://api.pinterest.com/v5/pins/{PIN_ID}/analytics?start_date=2025-01-01&end_date=2025-01-31&metric_types=IMPRESSION,SAVE,PIN_CLICK" \
-H "Authorization: Bearer {ACCESS_TOKEN}"IMPRESSIONSAVEPIN_CLICKOUTBOUND_CLICKVIDEO_START{
"all": {
"daily_metrics": [
{
"date": "2025-01-01",
"data_status": "READY",
"metrics": {
"IMPRESSION": 1250,
"SAVE": 45,
"PIN_CLICK": 89
}
}
]
}
}{
"code": 3,
"message": "Requested pin not found"
}12348import requests
def create_pin(access_token, board_id, title, image_url):
url = "https://api.pinterest.com/v5/pins"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
data = {
"board_id": board_id,
"title": title,
"media_source": {
"source_type": "image_url",
"url": image_url
}
}
try:
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
return response.json()
except requests.exceptions.HTTPError as e:
error_data = e.response.json()
print(f"Error {error_data.get('code')}: {error_data.get('message')}")
return None
except requests.exceptions.RequestException as e:
print(f"Request failed: {str(e)}")
return None// Pinterest API Client Example
class PinterestClient {
constructor(accessToken) {
this.accessToken = accessToken;
this.baseUrl = 'https://api.pinterest.com/v5';
}
async request(endpoint, options = {}) {
const url = `${this.baseUrl}${endpoint}`;
const headers = {
'Authorization': `Bearer ${this.accessToken}`,
'Content-Type': 'application/json',
...options.headers
};
const response = await fetch(url, {
...options,
headers
});
if (!response.ok) {
const error = await response.json();
throw new Error(`Pinterest API Error: ${error.message}`);
}
return response.json();
}
async createPin(boardId, title, imageUrl, description = '', link = '') {
return this.request('/pins', {
method: 'POST',
body: JSON.stringify({
board_id: boardId,
title: title,
description: description,
link: link,
media_source: {
source_type: 'image_url',
url: imageUrl
}
})
});
}
async getUserBoards() {
return this.request('/boards');
}
async getPinAnalytics(pinId, startDate, endDate) {
const params = new URLSearchParams({
start_date: startDate,
end_date: endDate,
metric_types: 'IMPRESSION,SAVE,PIN_CLICK'
});
return this.request(`/pins/${pinId}/analytics?${params}`);
}
}
// Usage
const client = new PinterestClient('your_access_token');
const pin = await client.createPin('board_id', 'Pin Title', 'https://example.com/image.jpg');references/view# Initial request
curl -X GET "https://api.pinterest.com/v5/boards/{BOARD_ID}/pins?page_size=25" \
-H "Authorization: Bearer {ACCESS_TOKEN}"
# Follow-up with bookmark from response
curl -X GET "https://api.pinterest.com/v5/boards/{BOARD_ID}/pins?page_size=25&bookmark={BOOKMARK}" \
-H "Authorization: Bearer {ACCESS_TOKEN}"# Create multiple pins efficiently
def bulk_create_pins(access_token, board_id, pin_data_list):
results = []
for pin_data in pin_data_list:
result = create_pin(
access_token,
board_id,
pin_data['title'],
pin_data['image_url']
)
results.append(result)
time.sleep(0.5) # Respect rate limits
return resultsboards:readboards:writepins:readpins:writeuser_accounts:readads:readX-RateLimit-LimitX-RateLimit-RemainingX-RateLimit-ResetBearer {token}X-RateLimit-Reset