Skip to main content

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

Alvaro Vargas avatar
Written by Alvaro Vargas
Updated over a week ago

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

  1. Go to Platform → Tools → Create Tool.

  2. Tool name: Create Payment Link.

  3. When to use: e.g., use this tool to generate a checkout link for the customer.

  4. Select Custom Tool as the Tool type.

2) Configure the API connection

API Request

  • Method: POST

  • URL: https://api.mercadopago.com/checkout/preferences

HTTP Headers

Key

Value

Authorization

Bearer YOUR_ACCESS_TOKEN

Content-Type

application/json

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_id puede ser UYU, 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 #1234

  • quantity (Number) – e.g., 1

  • unit_price (Number) – e.g., 1500

  • payer_email (Text) – e.g., [email protected]

  • external_reference (Text) – e.g., ORDER-1234


▶️ Test the tool

  1. Click Test Response.

  2. A successful response returns 201 Created and 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" }
  1. Share init_point (or sandbox_init_point for 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_reference to 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., unit_price not a number).

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.

Did this answer your question?