Manygent API

अपने कोड से कॉन्टैक्ट जोड़ें, WhatsApp टेम्पलेट और जवाब भेजें, फ़्लो शुरू करें, और ऑर्डर व प्रोडक्ट पढ़ें। Manygent में कुछ होते ही webhooks आपके सिस्टम को बताते हैं।

API की पाने के लिए वर्कस्पेस बनाएँ, फिर इंटीग्रेशन → API और डॉक्स → नई कुंजी पर जाएँ। यही की Zapier और Make के लिए Manygent ऐप्स को जोड़ती है।

API संदर्भ

HTTPS पर REST API, JSON अंदर और बाहर। सब कुछ उस वर्कस्पेस तक सीमित है जिसकी की है।

बेस URL और साइन इन

https://app.manygent.com/api/public/v1

हर अनुरोध पर अपनी की Authorization: Bearer fg_live_… (या X-API-Key: fg_live_…) के रूप में भेजें। की इस वर्कस्पेस के एडमिन की तरह काम करती है: इसे अपने सर्वर पर रखें, कभी वेब पेज या ऐप में नहीं।

सीमाएँ और त्रुटियाँ

प्रति की प्रति मिनट 120 अनुरोध तक; इससे ज़्यादा पर जवाब 429 और Retry-After हेडर होता है। त्रुटियाँ { "statusCode": 400, "message": "…" } के रूप में आती हैं: मैसेज बताता है क्या बदलना है। 401 की नहीं है या रद्द, 404 इस वर्कस्पेस में नहीं मिला, 422 समझ आया पर संभव नहीं (जैसे ऐसे व्यक्ति को मैसेज जिसने मार्केटिंग की सहमति नहीं दी)। सूचियाँ पेजों में हैं: { data, page, limit, total, has_more }।

एंडपॉइंट

तरीक़ापाथक्या करता है
GET
/me

वह वर्कस्पेस जिसकी यह की है। की जाँचने के लिए इस्तेमाल करें।

GET
/contacts

संपर्कों की सूची। ?search, ?tag, ?channel, ?sort, ?page, ?limit (अधिकतम 100)।

GET
/contacts/{id}

एक संपर्क।

POST
/contacts

संपर्क बनाता है, या उसी फ़ोन या ईमेल वाले को अपडेट करता है। हमेशा नया बनाने के लिए "upsert": false भेजें।

PATCH
/contacts/{id}

नाम, फ़ोन, ईमेल, टैग (बदल देता है) या custom_fields (मिला देता है) बदलता है।

POST
/contacts/{id}/tags

टैग जोड़ता है: { "tag": "vip" }। “टैग जुड़े” वाले फ़्लो चलते हैं।

DELETE
/contacts/{id}/tags/{tag}

टैग हटाता है।

POST
/messages

WhatsApp टेम्पलेट, बातचीत में जवाब, ईमेल या SMS भेजता है।

GET
/messages

हाल के मैसेज, नए पहले। ?direction (inbound, outbound), ?contact_id, ?page, ?limit।

GET
/conversations

हाल की बातचीत, सबसे हाल में बदली पहले। ?status (open, closed…), ?page, ?limit।

GET
/orders

ऑर्डर की सूची। ?status, ?contact_id, ?page, ?limit।

GET
/orders/{id}

एक ऑर्डर उसकी चीज़ों के साथ।

GET
/products

प्रोडक्ट और स्टॉक की सूची। ?search, ?page, ?limit।

POST
/products/{sku}/waitlist

“मुझे बताएँ” फ़ॉर्म: { "phone" या "email" (या "contact_id"), "name", "kind": "stock" या "price" }। उन्हें आपका फिर स्टॉक में या क़ीमत गिरने का मैसेज मिलता है।

GET
/templates/whatsapp

स्वीकृत WhatsApp टेम्पलेट, हर एक अपने वेरिएबल के साथ। एक के लिए ?id।

GET
/templates/email

ईमेल टेम्पलेट।

GET
/flows

वर्कस्पेस के फ़्लो।

POST
/flows/{id}/start

किसी संपर्क के लिए फ़्लो शुरू करता है: { "contact_id": "…" }।

GET
/events

सभी वेबहुक इवेंट।

GET
/webhooks

वेबहुक एंडपॉइंट।

POST
/webhooks

URL सब्सक्राइब करता है: { "url", "events": [...] }। साइनिंग सीक्रेट लौटाता है।

DELETE
/webhooks/{id}

अनसब्सक्राइब करता है।

उदाहरण

संपर्क जोड़ें (या अपडेट करें)

curl -X POST https://app.manygent.com/api/public/v1/contacts \
  -H "Authorization: Bearer fg_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Sam Carter", "phone": "+14155550123", "tags": ["website"] }'

WhatsApp टेम्पलेट भेजें: कभी भी काम करता है, नए व्यक्ति को भी

curl -X POST https://app.manygent.com/api/public/v1/messages \
  -H "Authorization: Bearer fg_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "phone": "+14155550123",
    "template": { "name": "order_confirmation", "variables": { "1": "Sam", "2": "#1042" } }
  }'

उनकी बातचीत में जवाब दें: चैनल की 24 घंटे की विंडो के भीतर

curl -X POST https://app.manygent.com/api/public/v1/messages \
  -H "Authorization: Bearer fg_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "contact_id": "CONTACT_ID", "text": "Your order is on its way!" }'

ईमेल भेजें: बताएँ कि ट्रांज़ैक्शनल है या मार्केटिंग

curl -X POST https://app.manygent.com/api/public/v1/messages \
  -H "Authorization: Bearer fg_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "contact_id": "CONTACT_ID", "channel": "email", "email_template_id": "TEMPLATE_ID", "purpose": "transactional" }'

इवेंट सब्सक्राइब करें

curl -X POST https://app.manygent.com/api/public/v1/webhooks \
  -H "Authorization: Bearer fg_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/manygent", "events": ["order.paid", "message.received"] }'

वेबहुक: आपको क्या मिलता है

{ "id", "type", "created_at", "workspace_id", "data" } के साथ एक POST। 10 सेकंड में किसी भी 2xx से जवाब दें; नहीं तो लगभग दो घंटे तक बढ़ते अंतराल से उसी id के साथ फिर भेजा जाता है, इसलिए पहले संभाला id अनदेखा करें। हेडर: Manygent-Event, Manygent-Event-Id, Manygent-Delivery, Manygent-Signature।

जाँचें कि वेबहुक हमारी ओर से है

Manygent-Signature: t=<unix time>,v1=<hex>, जहाँ v1 आपके एंडपॉइंट के साइनिंग सीक्रेट के साथ t + "." + raw body का HMAC-SHA256 है। स्थिर समय में तुलना करें और पाँच मिनट से पुरानी कोई भी चीज़ अस्वीकार करें।

// Express: use the RAW body — re-serialised JSON will not match.
const crypto = require('crypto');

app.post('/manygent', express.raw({ type: 'application/json' }), (req, res) => {
  const header = req.get('Manygent-Signature') || '';            // t=1730000000,v1=abc…
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
  const expected = crypto.createHmac('sha256', process.env.MANYGENT_WEBHOOK_SECRET)
    .update(`${parts.t}.${req.body}`).digest('hex');
  const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300; // 5 minutes
  const ok = fresh && parts.v1 && crypto.timingSafeEqual(Buffer.from(parts.v1), Buffer.from(expected));
  if (!ok) return res.sendStatus(400);

  const event = JSON.parse(req.body);   // { id, type, created_at, data }
  // Ignore an event.id you have already handled — retries resend the same id.
  res.sendStatus(200);
});