Örnekler
Partner API ile tahmin, RFQ launch-disabled handling ve private-beta webhook doğrulaması için referans snippetler.
Örnekler
Bu snippet'leri başlangıç noktası olarak kullanın, ancak payload ve response handling'i 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 launch-disabled yanıtını işleme
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) {
if (response.status === 501) {
const problem = await response.json();
console.log('RFQ public launch is disabled for this environment', problem);
return;
}
throw new Error(`RFQ creation failed: ${response.status}`);
}
const rfq = await response.json();
console.log(rfq.id);
RFQ, quote ve order readiness
RFQ detail, supplier quote, quote acceptance veya order için public client üretmeyin; bu operasyonlar
önce /docs/api/openapi.yaml içinde bulunmalıdır. Güncel yayınlanmış RFQ
create/list operasyonları launch-disabled durumdadır ve 501 döndürür.
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}`;
}
JSON parse etmeden önce raw request body ile doğrulama yapın. Webhook event delivery pilot/rollout kontrollü kalır; quote veya order event'lerinin public-current production enablement olduğunu varsaymayın.
Production notları
- anahtarları ve webhook secret'larını managed server-side secrets içinde tutun
- doğrudan live credentials kullanan client-side entegrasyonlara güvenmeyin
- credentials yerine request ID'leri loglayın
- webhook consumer'larını onaylı pilotlar için idempotent worker olarak tasarlayın
- API key'leri Master Data data-product GA access switch'i olarak yorumlamayın
Bu makale yardımcı oldu mu?
İlgili makaleler
Last updated on