Developer & APIPartner api
Örnekler
Partner API ile tahminler, RFQ'lar ve webhook doğrulama için referans kod parçacıkları.
Geliştiricidocs2 dk okumaİncelendi 16 Nis 2026
Örnekler
Bu kod parçacıklarını başlangıç noktası olarak kullanın, ancak yükleri ve yanıt işlemeyi her zaman
/docs/api/openapi.yaml adresindeki yayınlanmış sözleşmeye göre doğrulayın.
cURL: tahmin isteği
curl -X POST https://api.nowtoprint.com/api/v1/estimate \
-H "Authorization: Bearer ntp_test_your_key" \
-H "Content-Type: application/json" \
-d '{
"category": "brochure",
"quantity": 500,
"specifications": {
"pageCount": 16
}
}'
Node.js: RFQ oluşturma
const response = await fetch('https://api.nowtoprint.com/api/v1/rfq', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.NOWTOPRINT_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': crypto.randomUUID(),
},
body: JSON.stringify({
title: 'Spring brochure batch',
category: 'brochure',
quantity: 2500,
deliveryCity: 'Istanbul',
}),
});
if (!response.ok) {
throw new Error(`RFQ creation failed: ${response.status}`);
}
const rfq = await response.json();
console.log(rfq.id);
Python: RFQ durumu sorgulama
import os
import requests
headers = {
"Authorization": f"Bearer {os.environ['NOWTOPRINT_API_KEY']}",
"Accept": "application/json",
}
response = requests.get(
"https://api.nowtoprint.com/api/v1/rfq/rfq_123456",
headers=headers,
timeout=30,
)
response.raise_for_status()
print(response.json())
Node.js: webhook imza doğrulama
import crypto from 'node:crypto';
export function verifyWebhookSignature(payload: string, signature: string, secret: string) {
const digest = crypto.createHmac('sha256', secret).update(payload).digest('hex');
return signature === `sha256=${digest}`;
}
Doğrulama için JSON ayrıştırmasından önce ham istek gövdesini kullanın.
Üretim notları
- Anahtarları ve webhook gizli anahtarlarını yönetilen sunucu taraflı gizli depolamada tutun
- Doğrudan canlı kimlik bilgileriyle istemci taraflı entegrasyonlara güvenmeyin
- Kimlik bilgilerini değil, istek kimliklerini loglayın
- Webhook tüketicilerini idempotent çalışanlar olarak tasarlayın
Bu makale yardımcı oldu mu?
İlgili makaleler
Edit on GitHub
Son güncellenme