Sample code for 30+ languages & platforms
Lua

MercadoLibre - Search Orders from a Buyer

See more MercadoLibre Examples

Search for orders from a buyer.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local http = chilkat.Http.new()

-- First get our previously obtained OAuth2 access token.
local jsonToken = chilkat.JsonObject.new()
local success = jsonToken:load_file("qa_data/tokens/mercadolibre.json")

-- Implements the following CURL command:

-- curl -X GET https://api.mercadolibre.com/orders/search?buyer=$BUYER_ID&access_token=$ACCESS_TOKEN

-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code

http:set_url_var("access_token", jsonToken:string_of("access_token"))
-- Use an actual buyer ID here..
http:set_url_var("buyer_id", "577815702")

local sbResponseBody = chilkat.StringBuilder.new()
success = http:quick_get_sb("https://api.mercadolibre.com/orders/search?buyer={$buyer_id}&access_token={$access_token}", sbResponseBody)
if not success then
    print(http.last_error_text)
    print("Response Header:")
    print(http.last_header)
    print("----")
    print("Response Body:")
    print(sbResponseBody:get_as_string())
    print("Failed.")
    return
end

local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(http.last_header)
    print("----")
    print("Response Body:")
    print(sbResponseBody:get_as_string())
    print("Failed.")
    return
end

-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)

-- {
--   "query": "2032217210",
--   "results": [
--     {
--       "seller": {
--         "phone": {
--           "number": "11971427863",
--           "extension": "",
--           "area_code": null,
--           "verified": false
--         },
--         "alternative_phone": {
--           "number": "",
--           "extension": "",
--           "area_code": ""
--         },
--         "nickname": "VENDASDKMB",
--         "last_name": "Cheracomo",
--         "id": 239432672,
--         "first_name": "Demétrio",
--         "email": "dcherac.8m6k0q+2-ogiydgmrsge3tenby@mail.mercadolivre.com"
--       },
--       "payments": [
--         {
--           "reason": "Kit Com 03 Adesivo Spray 3m 75 Cola Silk Sublimação 300g",
--           "status_code": null,
--           "total_paid_amount": 129.95,
--           "operation_type": "regular_payment",
--           "transaction_amount": 129.95,
--           "date_approved": "2019-05-22T03:51:07.000-04:00",
--           "collector": {
--             "id": 239432672
--           },
--           "coupon_id": null,
--           "installments": 1,
--           "authorization_code": "008877",
--           "taxes_amount": 0,
--           "id": 4792155710,
--           "date_last_modified": "2019-05-22T03:51:07.000-04:00",
--           "coupon_amount": 0,
--           "available_actions": [
--             "refund"
--           ],
--           "shipping_cost": 0,
--           "installment_amount": 129.95,
--           "date_created": "2019-05-22T03:51:05.000-04:00",
--           "activation_uri": null,
--           "overpaid_amount": 0,
--           "card_id": 203453778,
--           "status_detail": "accredited",
--           "issuer_id": "24",
--           "payment_method_id": "master",
--           "payment_type": "credit_card",
--           "deferred_period": null,
--           "atm_transfer_reference": {
--             "transaction_id": "135292",
--             "company_id": null
--           },
--           "site_id": "MLB",
--           "payer_id": 89660613,
--           "marketplace_fee": 14.290000000000001,
--           "order_id": 2032217210,
--           "currency_id": "BRL",
--           "status": "approved",
--           "transaction_order_id": null
--         }
--       ],
--       "fulfilled": true,
--       "buying_mode": "buy_equals_pay",
--       "taxes": {
--         "amount": null,
--         "currency_id": null
--       },
--       "order_request": {
--         "change": null,
--         "return": null
--       },
--       "expiration_date": "2019-06-19T03:51:07.000-04:00",
--       "feedback": {
--         "sale": null,
--         "purchase": null
--       },
--       "shipping": {
--         "id": 27968238880
--       },
--       "date_closed": "2019-05-22T03:51:07.000-04:00",
--       "id": 2032217210,
--       "manufacturing_ending_date": null,
--       "hidden_for_seller": false,
--       "order_items": [
--         {
--           "item": {
--             "seller_custom_field": null,
--             "condition": "new",
--             "category_id": "MLB33383",
--             "variation_id": null,
--             "variation_attributes": [
--             ],
--             "seller_sku": null,
--             "warranty": "Garantia de 1 ano fabricante",
--             "id": "MLB1054990648",
--             "title": "Kit Com 03 Adesivo Spray 3m 75 Cola Silk Sublimação 300g"
--           },
--           "quantity": 1,
--           "differential_pricing_id": null,
--           "sale_fee": 14.29,
--           "listing_type_id": "gold_special",
--           "base_currency_id": null,
--           "unit_price": 129.95,
--           "full_unit_price": 129.95,
--           "base_exchange_rate": null,
--           "currency_id": "BRL",
--           "manufacturing_days": null
--         }
--       ],
--       "date_last_updated": "2020-02-14T02:55:49.811Z",
--       "last_updated": "2019-05-28T15:16:04.000-04:00",
--       "comments": null,
--       "pack_id": null,
--       "coupon": {
--         "amount": 0,
--         "id": null
--       },
--       "shipping_cost": 0,
--       "date_created": "2019-05-22T03:51:05.000-04:00",
--       "application_id": "7092",
--       "pickup_id": null,
--       "status_detail": null,
--       "tags": [
--         "delivered",
--         "paid"
--       ],
--       "buyer": {
--         "billing_info": {
--           "doc_number": "02183212950",
--           "doc_type": "CPF"
--         },
--         "phone": {
--           "number": "99962663",
--           "extension": "",
--           "area_code": "41",
--           "verified": false
--         },
--         "alternative_phone": {
--           "number": "30576339",
--           "extension": "",
--           "area_code": "41"
--         },
--         "nickname": "S.VICTORHUGO",
--         "last_name": "Schemberger",
--         "id": 89660613,
--         "first_name": "Victor Hugo",
--         "email": "vschemb.y14cdz+2-ogiydgmrsge3tenbz@mail.mercadolivre.com"
--       },
--       "total_amount": 129.95,
--       "paid_amount": 129.95,
--       "mediations": [
--       ],
--       "currency_id": "BRL",
--       "status": "paid"
--     }
--   ],
--   "sort": {
--     "id": "date_asc",
--     "name": "Date ascending"
--   },
--   "available_sorts": [
--     {
--       "id": "date_desc",
--       "name": "Date descending"
--     }
--   ],
--   "filters": [
--   ],
--   "paging": {
--     "total": 1,
--     "offset": 0,
--     "limit": 50
--   },
--   "display": "complete"
-- }

-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON

local date_closed = chilkat.DtObj.new()
local date_last_updated = chilkat.DtObj.new()
local date_created = chilkat.DtObj.new()
local date_approved = chilkat.DtObj.new()
local date_last_modified = chilkat.DtObj.new()
local sellerPhoneNumber = ""
local sellerPhoneExtension = ""
local sellerPhoneArea_code = ""
local sellerPhoneVerified = false
local sellerAlternative_phoneNumber = ""
local sellerAlternative_phoneExtension = ""
local sellerAlternative_phoneArea_code = ""
local sellerNickname = ""
local sellerLast_name = ""
local sellerId = 0
local sellerFirst_name = ""
local sellerEmail = ""
local fulfilled = false
local buying_mode = ""
local taxesAmount = ""
local taxesCurrency_id = ""
local order_requestChange = ""
local order_requestReturn = ""
local expiration_date = ""
local feedbackSale = ""
local feedbackPurchase = ""
local shippingId = 0
local id = 0
local manufacturing_ending_date = ""
local hidden_for_seller = false
local last_updated = ""
local comments = ""
local pack_id = ""
local couponAmount = 0
local couponId = ""
local shipping_cost = 0
local application_id = ""
local pickup_id = ""
local status_detail = ""
local buyerBilling_infoDoc_number = ""
local buyerBilling_infoDoc_type = ""
local buyerPhoneNumber = ""
local buyerPhoneExtension = ""
local buyerPhoneArea_code = ""
local buyerPhoneVerified = false
local buyerAlternative_phoneNumber = ""
local buyerAlternative_phoneExtension = ""
local buyerAlternative_phoneArea_code = ""
local buyerNickname = ""
local buyerLast_name = ""
local buyerId = 0
local buyerFirst_name = ""
local buyerEmail = ""
local total_amount = ""
local paid_amount = ""
local currency_id = ""
local status = ""
local j = 0
local count_j = 0
local reason = ""
local status_code = ""
local total_paid_amount = ""
local operation_type = ""
local transaction_amount = ""
local collectorId = 0
local paymentCoupon_id = ""
local installments = 0
local authorization_code = ""
local paymentTaxes_amount = 0
local paymentCoupon_amount = 0
local installment_amount = ""
local activation_uri = ""
local overpaid_amount = 0
local card_id = 0
local issuer_id = ""
local payment_method_id = ""
local payment_type = ""
local deferred_period = ""
local atm_transfer_referenceTransaction_id = ""
local atm_transfer_referenceCompany_id = ""
local site_id = ""
local payer_id = 0
local marketplace_fee = ""
local order_id = 0
local transaction_order_id = ""
local k = 0
local count_k = 0
local strVal = ""
local itemSeller_custom_field = ""
local itemCondition = ""
local itemCategory_id = ""
local itemVariation_id = ""
local itemSeller_sku = ""
local itemWarranty = ""
local itemId = ""
local itemTitle = ""
local quantity = 0
local differential_pricing_id = ""
local sale_fee = ""
local listing_type_id = ""
local base_currency_id = ""
local unit_price = ""
local full_unit_price = ""
local base_exchange_rate = ""
local manufacturing_days = ""
local id_str = ""
local name = ""

local query = jResp:string_of("query")
local sortId = jResp:string_of("sort.id")
local sortName = jResp:string_of("sort.name")
local pagingTotal = jResp:int_of("paging.total")
local pagingOffset = jResp:int_of("paging.offset")
local pagingLimit = jResp:int_of("paging.limit")
local display = jResp:string_of("display")
local i = 0
local count_i = jResp:size_of_array("results")
while i < count_i do
    jResp.i = i
    sellerPhoneNumber = jResp:string_of("results[i].seller.phone.number")
    sellerPhoneExtension = jResp:string_of("results[i].seller.phone.extension")
    sellerPhoneArea_code = jResp:string_of("results[i].seller.phone.area_code")
    sellerPhoneVerified = jResp:bool_of("results[i].seller.phone.verified")
    sellerAlternative_phoneNumber = jResp:string_of("results[i].seller.alternative_phone.number")
    sellerAlternative_phoneExtension = jResp:string_of("results[i].seller.alternative_phone.extension")
    sellerAlternative_phoneArea_code = jResp:string_of("results[i].seller.alternative_phone.area_code")
    sellerNickname = jResp:string_of("results[i].seller.nickname")
    sellerLast_name = jResp:string_of("results[i].seller.last_name")
    sellerId = jResp:int_of("results[i].seller.id")
    sellerFirst_name = jResp:string_of("results[i].seller.first_name")
    sellerEmail = jResp:string_of("results[i].seller.email")
    fulfilled = jResp:bool_of("results[i].fulfilled")
    buying_mode = jResp:string_of("results[i].buying_mode")
    taxesAmount = jResp:string_of("results[i].taxes.amount")
    taxesCurrency_id = jResp:string_of("results[i].taxes.currency_id")
    order_requestChange = jResp:string_of("results[i].order_request.change")
    order_requestReturn = jResp:string_of("results[i].order_request.return")
    expiration_date = jResp:string_of("results[i].expiration_date")
    feedbackSale = jResp:string_of("results[i].feedback.sale")
    feedbackPurchase = jResp:string_of("results[i].feedback.purchase")
    shippingId = jResp:int_of("results[i].shipping.id")
    jResp:dt_of("results[i].date_closed", false, date_closed)
    id = jResp:int_of("results[i].id")
    manufacturing_ending_date = jResp:string_of("results[i].manufacturing_ending_date")
    hidden_for_seller = jResp:bool_of("results[i].hidden_for_seller")
    jResp:dt_of("results[i].date_last_updated", false, date_last_updated)
    last_updated = jResp:string_of("results[i].last_updated")
    comments = jResp:string_of("results[i].comments")
    pack_id = jResp:string_of("results[i].pack_id")
    couponAmount = jResp:int_of("results[i].coupon.amount")
    couponId = jResp:string_of("results[i].coupon.id")
    shipping_cost = jResp:int_of("results[i].shipping_cost")
    jResp:dt_of("results[i].date_created", false, date_created)
    application_id = jResp:string_of("results[i].application_id")
    pickup_id = jResp:string_of("results[i].pickup_id")
    status_detail = jResp:string_of("results[i].status_detail")
    buyerBilling_infoDoc_number = jResp:string_of("results[i].buyer.billing_info.doc_number")
    buyerBilling_infoDoc_type = jResp:string_of("results[i].buyer.billing_info.doc_type")
    buyerPhoneNumber = jResp:string_of("results[i].buyer.phone.number")
    buyerPhoneExtension = jResp:string_of("results[i].buyer.phone.extension")
    buyerPhoneArea_code = jResp:string_of("results[i].buyer.phone.area_code")
    buyerPhoneVerified = jResp:bool_of("results[i].buyer.phone.verified")
    buyerAlternative_phoneNumber = jResp:string_of("results[i].buyer.alternative_phone.number")
    buyerAlternative_phoneExtension = jResp:string_of("results[i].buyer.alternative_phone.extension")
    buyerAlternative_phoneArea_code = jResp:string_of("results[i].buyer.alternative_phone.area_code")
    buyerNickname = jResp:string_of("results[i].buyer.nickname")
    buyerLast_name = jResp:string_of("results[i].buyer.last_name")
    buyerId = jResp:int_of("results[i].buyer.id")
    buyerFirst_name = jResp:string_of("results[i].buyer.first_name")
    buyerEmail = jResp:string_of("results[i].buyer.email")
    total_amount = jResp:string_of("results[i].total_amount")
    paid_amount = jResp:string_of("results[i].paid_amount")
    currency_id = jResp:string_of("results[i].currency_id")
    status = jResp:string_of("results[i].status")
    j = 0
    count_j = jResp:size_of_array("results[i].payments")
    while j < count_j do
        jResp.j = j
        reason = jResp:string_of("results[i].payments[j].reason")
        status_code = jResp:string_of("results[i].payments[j].status_code")
        total_paid_amount = jResp:string_of("results[i].payments[j].total_paid_amount")
        operation_type = jResp:string_of("results[i].payments[j].operation_type")
        transaction_amount = jResp:string_of("results[i].payments[j].transaction_amount")
        jResp:dt_of("results[i].payments[j].date_approved", false, date_approved)
        collectorId = jResp:int_of("results[i].payments[j].collector.id")
        paymentCoupon_id = jResp:string_of("results[i].payments[j].coupon_id")
        installments = jResp:int_of("results[i].payments[j].installments")
        authorization_code = jResp:string_of("results[i].payments[j].authorization_code")
        paymentTaxes_amount = jResp:int_of("results[i].payments[j].taxes_amount")
        id = jResp:int_of("results[i].payments[j].id")
        jResp:dt_of("results[i].payments[j].date_last_modified", false, date_last_modified)
        paymentCoupon_amount = jResp:int_of("results[i].payments[j].coupon_amount")
        shipping_cost = jResp:int_of("results[i].payments[j].shipping_cost")
        installment_amount = jResp:string_of("results[i].payments[j].installment_amount")
        jResp:dt_of("results[i].payments[j].date_created", false, date_created)
        activation_uri = jResp:string_of("results[i].payments[j].activation_uri")
        overpaid_amount = jResp:int_of("results[i].payments[j].overpaid_amount")
        card_id = jResp:int_of("results[i].payments[j].card_id")
        status_detail = jResp:string_of("results[i].payments[j].status_detail")
        issuer_id = jResp:string_of("results[i].payments[j].issuer_id")
        payment_method_id = jResp:string_of("results[i].payments[j].payment_method_id")
        payment_type = jResp:string_of("results[i].payments[j].payment_type")
        deferred_period = jResp:string_of("results[i].payments[j].deferred_period")
        atm_transfer_referenceTransaction_id = jResp:string_of("results[i].payments[j].atm_transfer_reference.transaction_id")
        atm_transfer_referenceCompany_id = jResp:string_of("results[i].payments[j].atm_transfer_reference.company_id")
        site_id = jResp:string_of("results[i].payments[j].site_id")
        payer_id = jResp:int_of("results[i].payments[j].payer_id")
        marketplace_fee = jResp:string_of("results[i].payments[j].marketplace_fee")
        order_id = jResp:int_of("results[i].payments[j].order_id")
        currency_id = jResp:string_of("results[i].payments[j].currency_id")
        status = jResp:string_of("results[i].payments[j].status")
        transaction_order_id = jResp:string_of("results[i].payments[j].transaction_order_id")
        k = 0
        count_k = jResp:size_of_array("results[i].payments[j].available_actions")
        while k < count_k do
            jResp.k = k
            strVal = jResp:string_of("results[i].payments[j].available_actions[k]")
            k = k + 1
        end

        j = j + 1
    end

    j = 0
    count_j = jResp:size_of_array("results[i].order_items")
    while j < count_j do
        jResp.j = j
        itemSeller_custom_field = jResp:string_of("results[i].order_items[j].item.seller_custom_field")
        itemCondition = jResp:string_of("results[i].order_items[j].item.condition")
        itemCategory_id = jResp:string_of("results[i].order_items[j].item.category_id")
        itemVariation_id = jResp:string_of("results[i].order_items[j].item.variation_id")
        itemSeller_sku = jResp:string_of("results[i].order_items[j].item.seller_sku")
        itemWarranty = jResp:string_of("results[i].order_items[j].item.warranty")
        itemId = jResp:string_of("results[i].order_items[j].item.id")
        itemTitle = jResp:string_of("results[i].order_items[j].item.title")
        quantity = jResp:int_of("results[i].order_items[j].quantity")
        differential_pricing_id = jResp:string_of("results[i].order_items[j].differential_pricing_id")
        sale_fee = jResp:string_of("results[i].order_items[j].sale_fee")
        listing_type_id = jResp:string_of("results[i].order_items[j].listing_type_id")
        base_currency_id = jResp:string_of("results[i].order_items[j].base_currency_id")
        unit_price = jResp:string_of("results[i].order_items[j].unit_price")
        full_unit_price = jResp:string_of("results[i].order_items[j].full_unit_price")
        base_exchange_rate = jResp:string_of("results[i].order_items[j].base_exchange_rate")
        currency_id = jResp:string_of("results[i].order_items[j].currency_id")
        manufacturing_days = jResp:string_of("results[i].order_items[j].manufacturing_days")
        k = 0
        count_k = jResp:size_of_array("results[i].order_items[j].item.variation_attributes")
        while k < count_k do
            jResp.k = k
            k = k + 1
        end

        j = j + 1
    end

    j = 0
    count_j = jResp:size_of_array("results[i].tags")
    while j < count_j do
        jResp.j = j
        strVal = jResp:string_of("results[i].tags[j]")
        j = j + 1
    end

    j = 0
    count_j = jResp:size_of_array("results[i].mediations")
    while j < count_j do
        jResp.j = j
        j = j + 1
    end

    i = i + 1
end

i = 0
count_i = jResp:size_of_array("available_sorts")
while i < count_i do
    jResp.i = i
    id_str = jResp:string_of("available_sorts[i].id")
    name = jResp:string_of("available_sorts[i].name")
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("filters")
while i < count_i do
    jResp.i = i
    i = i + 1
end