Example: Create Payment Link (Mercado Pago)
This article shows how to create a Custom Tool in Frontline that generates a checkout link using the Mercado Pago API. Your AI Agent can then share the link with the customer (e.g., via WhatsApp) so they can complete the payment.
⚙️ What you’ll need
A Mercado Pago account with API access.
A Test or Production Access Token (Bearer token).
(Optional) A unique external_reference to match the order in your system.
Tip: Start with test credentials and switch to production once everything works.
🚀 Step-by-step setup
1) Create the Custom Tool
Go to Platform → Tools → Create Tool.
Tool name: Create Payment Link.
When to use: e.g., use this tool to generate a checkout link for the customer.
Select Custom Tool as the Tool type.
2) Configure the API connection
API Request
Method:
POSTURL:
https://api.mercadopago.com/checkout/preferences
HTTP Headers
Key | Value |
|
|
|
|
Request Body (example)
{ "items": [ { "title": "{title}", "quantity": {quantity}, "currency_id": "UYU", "unit_price": {unit_price} } ], "payer": { "email": "{payer_email}" }, "external_reference": "{external_reference}", "back_urls": { "success": "https://yourapp.com/payments/success", "failure": "https://yourapp.com/payments/failure", "pending": "https://yourapp.com/payments/pending" }, "auto_return": "approved", "notification_url": "https://yourapp.com/webhooks/mercadopago" }Notes:
currency_idpuede serUYU,ARS,USD, etc. según tu cuenta.notification_url(webhook) es opcional pero recomendado para confirmar pagos automáticamente.
Data inputs
Add these inputs so your Agent can fill them dynamically:
title(Text) – e.g., Order #1234quantity(Number) – e.g.,1unit_price(Number) – e.g.,1500payer_email(Text) – e.g.,[email protected]external_reference(Text) – e.g.,ORDER-1234
▶️ Test the tool
Click Test Response.
A successful response returns
201 Createdand a JSON with the checkout URLs. Example:
{ "id": "PREF-123456789", "init_point": "https://www.mercadopago.com/checkout/v1/redirect?pref_id=PREF-123456789", "sandbox_init_point": "https://sandbox.mercadopago.com/checkout/v1/redirect?pref_id=PREF-123456789" }Share
init_point(orsandbox_init_pointfor testing) with the customer.
🧠 How it works
Your AI Agent triggers this tool, Mercado Pago creates a preference, and returns the checkout link. You can send the link in the same conversation (e.g., via WhatsApp message or Template).
✅ Best practices
Use
external_referenceto reconcile payments with your orders.Add a webhook (
notification_url) to capture payment updates in real time.Validate and sanitize price/quantity before sending the API request.
Keep tokens secure and rotate them periodically.
🔍 Troubleshooting
Issue | Possible cause |
401 Unauthorized | Invalid/expired token or wrong environment (test vs. prod). |
400 Bad Request | Missing/invalid fields (e.g., |
Link opens but payment not confirmed | Webhook not configured; check status later with Check Payment Status tool. |
🔗 Related
Example: Check Payment Status (Mercado Pago) — verify if a payment is approved/pending/rejected using the search endpoint.
Still have questions?
Reach out through the Help button in Frontline or contact your CSM for assistance.
