Sample code for 30+ languages & platforms
Lianja

MercadoLibre - Search Orders from a Buyer

See more MercadoLibre Examples

Search for orders from a buyer.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

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

loHttp = createobject("CkHttp")

// First get our previously obtained OAuth2 access token.
loJsonToken = createobject("CkJsonObject")
llSuccess = loJsonToken.LoadFile("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

loHttp.SetUrlVar("access_token",loJsonToken.StringOf("access_token"))
// Use an actual buyer ID here..
loHttp.SetUrlVar("buyer_id","577815702")

loSbResponseBody = createobject("CkStringBuilder")
llSuccess = loHttp.QuickGetSb("https://api.mercadolibre.com/orders/search?buyer={$buyer_id}&access_token={$access_token}",loSbResponseBody)
if (llSuccess = .F.) then
    ? loHttp.LastErrorText
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "----"
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    ? "Failed."
    release loHttp
    release loJsonToken
    release loSbResponseBody
    return
endif

loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "----"
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    ? "Failed."
    release loHttp
    release loJsonToken
    release loSbResponseBody
    release loJResp
    return
endif

// 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

loDate_closed = createobject("CkDtObj")
loDate_last_updated = createobject("CkDtObj")
loDate_created = createobject("CkDtObj")
loDate_approved = createobject("CkDtObj")
loDate_last_modified = createobject("CkDtObj")

lcQuery = loJResp.StringOf("query")
lcSortId = loJResp.StringOf("sort.id")
lcSortName = loJResp.StringOf("sort.name")
lnPagingTotal = loJResp.IntOf("paging.total")
lnPagingOffset = loJResp.IntOf("paging.offset")
lnPagingLimit = loJResp.IntOf("paging.limit")
lcDisplay = loJResp.StringOf("display")
i = 0
lnCount_i = loJResp.SizeOfArray("results")
do while i < lnCount_i
    loJResp.I = i
    lcSellerPhoneNumber = loJResp.StringOf("results[i].seller.phone.number")
    lcSellerPhoneExtension = loJResp.StringOf("results[i].seller.phone.extension")
    lcSellerPhoneArea_code = loJResp.StringOf("results[i].seller.phone.area_code")
    llSellerPhoneVerified = loJResp.BoolOf("results[i].seller.phone.verified")
    lcSellerAlternative_phoneNumber = loJResp.StringOf("results[i].seller.alternative_phone.number")
    lcSellerAlternative_phoneExtension = loJResp.StringOf("results[i].seller.alternative_phone.extension")
    lcSellerAlternative_phoneArea_code = loJResp.StringOf("results[i].seller.alternative_phone.area_code")
    lcSellerNickname = loJResp.StringOf("results[i].seller.nickname")
    lcSellerLast_name = loJResp.StringOf("results[i].seller.last_name")
    lnSellerId = loJResp.IntOf("results[i].seller.id")
    lcSellerFirst_name = loJResp.StringOf("results[i].seller.first_name")
    lcSellerEmail = loJResp.StringOf("results[i].seller.email")
    llFulfilled = loJResp.BoolOf("results[i].fulfilled")
    lcBuying_mode = loJResp.StringOf("results[i].buying_mode")
    lcTaxesAmount = loJResp.StringOf("results[i].taxes.amount")
    lcTaxesCurrency_id = loJResp.StringOf("results[i].taxes.currency_id")
    lcOrder_requestChange = loJResp.StringOf("results[i].order_request.change")
    lcOrder_requestReturn = loJResp.StringOf("results[i].order_request.return")
    lcExpiration_date = loJResp.StringOf("results[i].expiration_date")
    lcFeedbackSale = loJResp.StringOf("results[i].feedback.sale")
    lcFeedbackPurchase = loJResp.StringOf("results[i].feedback.purchase")
    lnShippingId = loJResp.IntOf("results[i].shipping.id")
    loJResp.DtOf("results[i].date_closed",.F.,loDate_closed)
    lnId = loJResp.IntOf("results[i].id")
    lcManufacturing_ending_date = loJResp.StringOf("results[i].manufacturing_ending_date")
    llHidden_for_seller = loJResp.BoolOf("results[i].hidden_for_seller")
    loJResp.DtOf("results[i].date_last_updated",.F.,loDate_last_updated)
    lcLast_updated = loJResp.StringOf("results[i].last_updated")
    lcComments = loJResp.StringOf("results[i].comments")
    lcPack_id = loJResp.StringOf("results[i].pack_id")
    lnCouponAmount = loJResp.IntOf("results[i].coupon.amount")
    lcCouponId = loJResp.StringOf("results[i].coupon.id")
    lnShipping_cost = loJResp.IntOf("results[i].shipping_cost")
    loJResp.DtOf("results[i].date_created",.F.,loDate_created)
    lcApplication_id = loJResp.StringOf("results[i].application_id")
    lcPickup_id = loJResp.StringOf("results[i].pickup_id")
    lcStatus_detail = loJResp.StringOf("results[i].status_detail")
    lcBuyerBilling_infoDoc_number = loJResp.StringOf("results[i].buyer.billing_info.doc_number")
    lcBuyerBilling_infoDoc_type = loJResp.StringOf("results[i].buyer.billing_info.doc_type")
    lcBuyerPhoneNumber = loJResp.StringOf("results[i].buyer.phone.number")
    lcBuyerPhoneExtension = loJResp.StringOf("results[i].buyer.phone.extension")
    lcBuyerPhoneArea_code = loJResp.StringOf("results[i].buyer.phone.area_code")
    llBuyerPhoneVerified = loJResp.BoolOf("results[i].buyer.phone.verified")
    lcBuyerAlternative_phoneNumber = loJResp.StringOf("results[i].buyer.alternative_phone.number")
    lcBuyerAlternative_phoneExtension = loJResp.StringOf("results[i].buyer.alternative_phone.extension")
    lcBuyerAlternative_phoneArea_code = loJResp.StringOf("results[i].buyer.alternative_phone.area_code")
    lcBuyerNickname = loJResp.StringOf("results[i].buyer.nickname")
    lcBuyerLast_name = loJResp.StringOf("results[i].buyer.last_name")
    lnBuyerId = loJResp.IntOf("results[i].buyer.id")
    lcBuyerFirst_name = loJResp.StringOf("results[i].buyer.first_name")
    lcBuyerEmail = loJResp.StringOf("results[i].buyer.email")
    lcTotal_amount = loJResp.StringOf("results[i].total_amount")
    lcPaid_amount = loJResp.StringOf("results[i].paid_amount")
    lcCurrency_id = loJResp.StringOf("results[i].currency_id")
    lcStatus = loJResp.StringOf("results[i].status")
    j = 0
    lnCount_j = loJResp.SizeOfArray("results[i].payments")
    do while j < lnCount_j
        loJResp.J = j
        lcReason = loJResp.StringOf("results[i].payments[j].reason")
        lcStatus_code = loJResp.StringOf("results[i].payments[j].status_code")
        lcTotal_paid_amount = loJResp.StringOf("results[i].payments[j].total_paid_amount")
        lcOperation_type = loJResp.StringOf("results[i].payments[j].operation_type")
        lcTransaction_amount = loJResp.StringOf("results[i].payments[j].transaction_amount")
        loJResp.DtOf("results[i].payments[j].date_approved",.F.,loDate_approved)
        lnCollectorId = loJResp.IntOf("results[i].payments[j].collector.id")
        lcCoupon_id = loJResp.StringOf("results[i].payments[j].coupon_id")
        lnInstallments = loJResp.IntOf("results[i].payments[j].installments")
        lcAuthorization_code = loJResp.StringOf("results[i].payments[j].authorization_code")
        lnTaxes_amount = loJResp.IntOf("results[i].payments[j].taxes_amount")
        lnId = loJResp.IntOf("results[i].payments[j].id")
        loJResp.DtOf("results[i].payments[j].date_last_modified",.F.,loDate_last_modified)
        lnCoupon_amount = loJResp.IntOf("results[i].payments[j].coupon_amount")
        lnShipping_cost = loJResp.IntOf("results[i].payments[j].shipping_cost")
        lcInstallment_amount = loJResp.StringOf("results[i].payments[j].installment_amount")
        loJResp.DtOf("results[i].payments[j].date_created",.F.,loDate_created)
        lcActivation_uri = loJResp.StringOf("results[i].payments[j].activation_uri")
        lnOverpaid_amount = loJResp.IntOf("results[i].payments[j].overpaid_amount")
        lnCard_id = loJResp.IntOf("results[i].payments[j].card_id")
        lcStatus_detail = loJResp.StringOf("results[i].payments[j].status_detail")
        lcIssuer_id = loJResp.StringOf("results[i].payments[j].issuer_id")
        lcPayment_method_id = loJResp.StringOf("results[i].payments[j].payment_method_id")
        lcPayment_type = loJResp.StringOf("results[i].payments[j].payment_type")
        lcDeferred_period = loJResp.StringOf("results[i].payments[j].deferred_period")
        lcAtm_transfer_referenceTransaction_id = loJResp.StringOf("results[i].payments[j].atm_transfer_reference.transaction_id")
        lcAtm_transfer_referenceCompany_id = loJResp.StringOf("results[i].payments[j].atm_transfer_reference.company_id")
        lcSite_id = loJResp.StringOf("results[i].payments[j].site_id")
        lnPayer_id = loJResp.IntOf("results[i].payments[j].payer_id")
        lcMarketplace_fee = loJResp.StringOf("results[i].payments[j].marketplace_fee")
        lnOrder_id = loJResp.IntOf("results[i].payments[j].order_id")
        lcCurrency_id = loJResp.StringOf("results[i].payments[j].currency_id")
        lcStatus = loJResp.StringOf("results[i].payments[j].status")
        lcTransaction_order_id = loJResp.StringOf("results[i].payments[j].transaction_order_id")
        k = 0
        lnCount_k = loJResp.SizeOfArray("results[i].payments[j].available_actions")
        do while k < lnCount_k
            loJResp.K = k
            lcStrVal = loJResp.StringOf("results[i].payments[j].available_actions[k]")
            k = k + 1
        enddo
        j = j + 1
    enddo
    j = 0
    lnCount_j = loJResp.SizeOfArray("results[i].order_items")
    do while j < lnCount_j
        loJResp.J = j
        lcItemSeller_custom_field = loJResp.StringOf("results[i].order_items[j].item.seller_custom_field")
        lcItemCondition = loJResp.StringOf("results[i].order_items[j].item.condition")
        lcItemCategory_id = loJResp.StringOf("results[i].order_items[j].item.category_id")
        lcItemVariation_id = loJResp.StringOf("results[i].order_items[j].item.variation_id")
        lcItemSeller_sku = loJResp.StringOf("results[i].order_items[j].item.seller_sku")
        lcItemWarranty = loJResp.StringOf("results[i].order_items[j].item.warranty")
        lcItemId = loJResp.StringOf("results[i].order_items[j].item.id")
        lcItemTitle = loJResp.StringOf("results[i].order_items[j].item.title")
        lnQuantity = loJResp.IntOf("results[i].order_items[j].quantity")
        lcDifferential_pricing_id = loJResp.StringOf("results[i].order_items[j].differential_pricing_id")
        lcSale_fee = loJResp.StringOf("results[i].order_items[j].sale_fee")
        lcListing_type_id = loJResp.StringOf("results[i].order_items[j].listing_type_id")
        lcBase_currency_id = loJResp.StringOf("results[i].order_items[j].base_currency_id")
        lcUnit_price = loJResp.StringOf("results[i].order_items[j].unit_price")
        lcFull_unit_price = loJResp.StringOf("results[i].order_items[j].full_unit_price")
        lcBase_exchange_rate = loJResp.StringOf("results[i].order_items[j].base_exchange_rate")
        lcCurrency_id = loJResp.StringOf("results[i].order_items[j].currency_id")
        lcManufacturing_days = loJResp.StringOf("results[i].order_items[j].manufacturing_days")
        k = 0
        lnCount_k = loJResp.SizeOfArray("results[i].order_items[j].item.variation_attributes")
        do while k < lnCount_k
            loJResp.K = k
            k = k + 1
        enddo
        j = j + 1
    enddo
    j = 0
    lnCount_j = loJResp.SizeOfArray("results[i].tags")
    do while j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("results[i].tags[j]")
        j = j + 1
    enddo
    j = 0
    lnCount_j = loJResp.SizeOfArray("results[i].mediations")
    do while j < lnCount_j
        loJResp.J = j
        j = j + 1
    enddo
    i = i + 1
enddo
i = 0
lnCount_i = loJResp.SizeOfArray("available_sorts")
do while i < lnCount_i
    loJResp.I = i
    lcId_str = loJResp.StringOf("available_sorts[i].id")
    lcName = loJResp.StringOf("available_sorts[i].name")
    i = i + 1
enddo
i = 0
lnCount_i = loJResp.SizeOfArray("filters")
do while i < lnCount_i
    loJResp.I = i
    i = i + 1
enddo


release loHttp
release loJsonToken
release loSbResponseBody
release loJResp
release loDate_closed
release loDate_last_updated
release loDate_created
release loDate_approved
release loDate_last_modified