Zig
Zig
MercadoLibre - Search Orders from a Buyer
See more MercadoLibre Examples
Search for orders from a buyer.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// First get our previously obtained OAuth2 access token.
const json_token = try chilkat.JsonObject.init();
defer json_token.deinit();
try json_token.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
http.setUrlVar("access_token", try json_token.stringOf(alloc, "access_token")) catch {};
// Use an actual buyer ID here..
http.setUrlVar("buyer_id", "577815702") catch {};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
http.quickGetSb("https://api.mercadolibre.com/orders/search?buyer={$buyer_id}&access_token={$access_token}", sb_response_body) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try http.getLastHeader(alloc)});
std.debug.print("----\n", .{});
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try sb_response_body.getAsString(alloc)});
std.debug.print("Failed.\n", .{});
return;
};
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.loadSb(sb_response_body) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
const resp_status_code = http.getLastStatus();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try http.getLastHeader(alloc)});
std.debug.print("----\n", .{});
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try sb_response_body.getAsString(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// 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
const date_closed = try chilkat.DtObj.init();
defer date_closed.deinit();
const date_last_updated = try chilkat.DtObj.init();
defer date_last_updated.deinit();
const date_created = try chilkat.DtObj.init();
defer date_created.deinit();
const date_approved = try chilkat.DtObj.init();
defer date_approved.deinit();
const date_last_modified = try chilkat.DtObj.init();
defer date_last_modified.deinit();
var seller_phone_number: [:0]const u8 = "";
var seller_phone_extension: [:0]const u8 = "";
var seller_phone_area_code: [:0]const u8 = "";
var seller_phone_verified: bool = false;
var seller_alternative_phone_number: [:0]const u8 = "";
var seller_alternative_phone_extension: [:0]const u8 = "";
var seller_alternative_phone_area_code: [:0]const u8 = "";
var seller_nickname: [:0]const u8 = "";
var seller_last_name: [:0]const u8 = "";
var seller_id: i32 = 0;
var seller_first_name: [:0]const u8 = "";
var seller_email: [:0]const u8 = "";
var fulfilled: bool = false;
var buying_mode: [:0]const u8 = "";
var taxes_amount: [:0]const u8 = "";
var taxes_currency_id: [:0]const u8 = "";
var order_request_change: [:0]const u8 = "";
var order_request_return: [:0]const u8 = "";
var expiration_date: [:0]const u8 = "";
var feedback_sale: [:0]const u8 = "";
var feedback_purchase: [:0]const u8 = "";
var shipping_id: i32 = 0;
var id: i32 = 0;
var manufacturing_ending_date: [:0]const u8 = "";
var hidden_for_seller: bool = false;
var last_updated: [:0]const u8 = "";
var comments: [:0]const u8 = "";
var pack_id: [:0]const u8 = "";
var coupon_amount: i32 = 0;
var coupon_id: [:0]const u8 = "";
var shipping_cost: i32 = 0;
var application_id: [:0]const u8 = "";
var pickup_id: [:0]const u8 = "";
var status_detail: [:0]const u8 = "";
var buyer_billing_info_doc_number: [:0]const u8 = "";
var buyer_billing_info_doc_type: [:0]const u8 = "";
var buyer_phone_number: [:0]const u8 = "";
var buyer_phone_extension: [:0]const u8 = "";
var buyer_phone_area_code: [:0]const u8 = "";
var buyer_phone_verified: bool = false;
var buyer_alternative_phone_number: [:0]const u8 = "";
var buyer_alternative_phone_extension: [:0]const u8 = "";
var buyer_alternative_phone_area_code: [:0]const u8 = "";
var buyer_nickname: [:0]const u8 = "";
var buyer_last_name: [:0]const u8 = "";
var buyer_id: i32 = 0;
var buyer_first_name: [:0]const u8 = "";
var buyer_email: [:0]const u8 = "";
var total_amount: [:0]const u8 = "";
var paid_amount: [:0]const u8 = "";
var currency_id: [:0]const u8 = "";
var status: [:0]const u8 = "";
var j: i32 = 0;
var count_j: i32 = 0;
var reason: [:0]const u8 = "";
var status_code: [:0]const u8 = "";
var total_paid_amount: [:0]const u8 = "";
var operation_type: [:0]const u8 = "";
var transaction_amount: [:0]const u8 = "";
var collector_id: i32 = 0;
var payment_coupon_id: [:0]const u8 = "";
var installments: i32 = 0;
var authorization_code: [:0]const u8 = "";
var payment_taxes_amount: i32 = 0;
var payment_coupon_amount: i32 = 0;
var installment_amount: [:0]const u8 = "";
var activation_uri: [:0]const u8 = "";
var overpaid_amount: i32 = 0;
var card_id: i32 = 0;
var issuer_id: [:0]const u8 = "";
var payment_method_id: [:0]const u8 = "";
var payment_type: [:0]const u8 = "";
var deferred_period: [:0]const u8 = "";
var atm_transfer_reference_transaction_id: [:0]const u8 = "";
var atm_transfer_reference_company_id: [:0]const u8 = "";
var site_id: [:0]const u8 = "";
var payer_id: i32 = 0;
var marketplace_fee: [:0]const u8 = "";
var order_id: i32 = 0;
var transaction_order_id: [:0]const u8 = "";
var k: i32 = 0;
var count_k: i32 = 0;
var str_val: [:0]const u8 = "";
var item_seller_custom_field: [:0]const u8 = "";
var item_condition: [:0]const u8 = "";
var item_category_id: [:0]const u8 = "";
var item_variation_id: [:0]const u8 = "";
var item_seller_sku: [:0]const u8 = "";
var item_warranty: [:0]const u8 = "";
var item_id: [:0]const u8 = "";
var item_title: [:0]const u8 = "";
var quantity: i32 = 0;
var differential_pricing_id: [:0]const u8 = "";
var sale_fee: [:0]const u8 = "";
var listing_type_id: [:0]const u8 = "";
var base_currency_id: [:0]const u8 = "";
var unit_price: [:0]const u8 = "";
var full_unit_price: [:0]const u8 = "";
var base_exchange_rate: [:0]const u8 = "";
var manufacturing_days: [:0]const u8 = "";
var id_str: [:0]const u8 = "";
var name: [:0]const u8 = "";
_ = try j_resp.stringOf(alloc, "query");
_ = try j_resp.stringOf(alloc, "sort.id");
_ = try j_resp.stringOf(alloc, "sort.name");
_ = j_resp.intOf("paging.total");
_ = j_resp.intOf("paging.offset");
_ = j_resp.intOf("paging.limit");
_ = try j_resp.stringOf(alloc, "display");
var i: i32 = 0;
var count_i: i32 = j_resp.sizeOfArray("results");
while (i < count_i) {
j_resp.setI(i);
seller_phone_number = try j_resp.stringOf(alloc, "results[i].seller.phone.number");
seller_phone_extension = try j_resp.stringOf(alloc, "results[i].seller.phone.extension");
seller_phone_area_code = try j_resp.stringOf(alloc, "results[i].seller.phone.area_code");
seller_phone_verified = j_resp.boolOf("results[i].seller.phone.verified");
seller_alternative_phone_number = try j_resp.stringOf(alloc, "results[i].seller.alternative_phone.number");
seller_alternative_phone_extension = try j_resp.stringOf(alloc, "results[i].seller.alternative_phone.extension");
seller_alternative_phone_area_code = try j_resp.stringOf(alloc, "results[i].seller.alternative_phone.area_code");
seller_nickname = try j_resp.stringOf(alloc, "results[i].seller.nickname");
seller_last_name = try j_resp.stringOf(alloc, "results[i].seller.last_name");
seller_id = j_resp.intOf("results[i].seller.id");
seller_first_name = try j_resp.stringOf(alloc, "results[i].seller.first_name");
seller_email = try j_resp.stringOf(alloc, "results[i].seller.email");
fulfilled = j_resp.boolOf("results[i].fulfilled");
buying_mode = try j_resp.stringOf(alloc, "results[i].buying_mode");
taxes_amount = try j_resp.stringOf(alloc, "results[i].taxes.amount");
taxes_currency_id = try j_resp.stringOf(alloc, "results[i].taxes.currency_id");
order_request_change = try j_resp.stringOf(alloc, "results[i].order_request.change");
order_request_return = try j_resp.stringOf(alloc, "results[i].order_request.return");
expiration_date = try j_resp.stringOf(alloc, "results[i].expiration_date");
feedback_sale = try j_resp.stringOf(alloc, "results[i].feedback.sale");
feedback_purchase = try j_resp.stringOf(alloc, "results[i].feedback.purchase");
shipping_id = j_resp.intOf("results[i].shipping.id");
j_resp.dtOf("results[i].date_closed", false, date_closed) catch {};
id = j_resp.intOf("results[i].id");
manufacturing_ending_date = try j_resp.stringOf(alloc, "results[i].manufacturing_ending_date");
hidden_for_seller = j_resp.boolOf("results[i].hidden_for_seller");
j_resp.dtOf("results[i].date_last_updated", false, date_last_updated) catch {};
last_updated = try j_resp.stringOf(alloc, "results[i].last_updated");
comments = try j_resp.stringOf(alloc, "results[i].comments");
pack_id = try j_resp.stringOf(alloc, "results[i].pack_id");
coupon_amount = j_resp.intOf("results[i].coupon.amount");
coupon_id = try j_resp.stringOf(alloc, "results[i].coupon.id");
shipping_cost = j_resp.intOf("results[i].shipping_cost");
j_resp.dtOf("results[i].date_created", false, date_created) catch {};
application_id = try j_resp.stringOf(alloc, "results[i].application_id");
pickup_id = try j_resp.stringOf(alloc, "results[i].pickup_id");
status_detail = try j_resp.stringOf(alloc, "results[i].status_detail");
buyer_billing_info_doc_number = try j_resp.stringOf(alloc, "results[i].buyer.billing_info.doc_number");
buyer_billing_info_doc_type = try j_resp.stringOf(alloc, "results[i].buyer.billing_info.doc_type");
buyer_phone_number = try j_resp.stringOf(alloc, "results[i].buyer.phone.number");
buyer_phone_extension = try j_resp.stringOf(alloc, "results[i].buyer.phone.extension");
buyer_phone_area_code = try j_resp.stringOf(alloc, "results[i].buyer.phone.area_code");
buyer_phone_verified = j_resp.boolOf("results[i].buyer.phone.verified");
buyer_alternative_phone_number = try j_resp.stringOf(alloc, "results[i].buyer.alternative_phone.number");
buyer_alternative_phone_extension = try j_resp.stringOf(alloc, "results[i].buyer.alternative_phone.extension");
buyer_alternative_phone_area_code = try j_resp.stringOf(alloc, "results[i].buyer.alternative_phone.area_code");
buyer_nickname = try j_resp.stringOf(alloc, "results[i].buyer.nickname");
buyer_last_name = try j_resp.stringOf(alloc, "results[i].buyer.last_name");
buyer_id = j_resp.intOf("results[i].buyer.id");
buyer_first_name = try j_resp.stringOf(alloc, "results[i].buyer.first_name");
buyer_email = try j_resp.stringOf(alloc, "results[i].buyer.email");
total_amount = try j_resp.stringOf(alloc, "results[i].total_amount");
paid_amount = try j_resp.stringOf(alloc, "results[i].paid_amount");
currency_id = try j_resp.stringOf(alloc, "results[i].currency_id");
status = try j_resp.stringOf(alloc, "results[i].status");
j = 0;
count_j = j_resp.sizeOfArray("results[i].payments");
while (j < count_j) {
j_resp.setJ(j);
reason = try j_resp.stringOf(alloc, "results[i].payments[j].reason");
status_code = try j_resp.stringOf(alloc, "results[i].payments[j].status_code");
total_paid_amount = try j_resp.stringOf(alloc, "results[i].payments[j].total_paid_amount");
operation_type = try j_resp.stringOf(alloc, "results[i].payments[j].operation_type");
transaction_amount = try j_resp.stringOf(alloc, "results[i].payments[j].transaction_amount");
j_resp.dtOf("results[i].payments[j].date_approved", false, date_approved) catch {};
collector_id = j_resp.intOf("results[i].payments[j].collector.id");
payment_coupon_id = try j_resp.stringOf(alloc, "results[i].payments[j].coupon_id");
installments = j_resp.intOf("results[i].payments[j].installments");
authorization_code = try j_resp.stringOf(alloc, "results[i].payments[j].authorization_code");
payment_taxes_amount = j_resp.intOf("results[i].payments[j].taxes_amount");
id = j_resp.intOf("results[i].payments[j].id");
j_resp.dtOf("results[i].payments[j].date_last_modified", false, date_last_modified) catch {};
payment_coupon_amount = j_resp.intOf("results[i].payments[j].coupon_amount");
shipping_cost = j_resp.intOf("results[i].payments[j].shipping_cost");
installment_amount = try j_resp.stringOf(alloc, "results[i].payments[j].installment_amount");
j_resp.dtOf("results[i].payments[j].date_created", false, date_created) catch {};
activation_uri = try j_resp.stringOf(alloc, "results[i].payments[j].activation_uri");
overpaid_amount = j_resp.intOf("results[i].payments[j].overpaid_amount");
card_id = j_resp.intOf("results[i].payments[j].card_id");
status_detail = try j_resp.stringOf(alloc, "results[i].payments[j].status_detail");
issuer_id = try j_resp.stringOf(alloc, "results[i].payments[j].issuer_id");
payment_method_id = try j_resp.stringOf(alloc, "results[i].payments[j].payment_method_id");
payment_type = try j_resp.stringOf(alloc, "results[i].payments[j].payment_type");
deferred_period = try j_resp.stringOf(alloc, "results[i].payments[j].deferred_period");
atm_transfer_reference_transaction_id = try j_resp.stringOf(alloc, "results[i].payments[j].atm_transfer_reference.transaction_id");
atm_transfer_reference_company_id = try j_resp.stringOf(alloc, "results[i].payments[j].atm_transfer_reference.company_id");
site_id = try j_resp.stringOf(alloc, "results[i].payments[j].site_id");
payer_id = j_resp.intOf("results[i].payments[j].payer_id");
marketplace_fee = try j_resp.stringOf(alloc, "results[i].payments[j].marketplace_fee");
order_id = j_resp.intOf("results[i].payments[j].order_id");
currency_id = try j_resp.stringOf(alloc, "results[i].payments[j].currency_id");
status = try j_resp.stringOf(alloc, "results[i].payments[j].status");
transaction_order_id = try j_resp.stringOf(alloc, "results[i].payments[j].transaction_order_id");
k = 0;
count_k = j_resp.sizeOfArray("results[i].payments[j].available_actions");
while (k < count_k) {
j_resp.setK(k);
str_val = try j_resp.stringOf(alloc, "results[i].payments[j].available_actions[k]");
k = k + 1;
}
j = j + 1;
}
j = 0;
count_j = j_resp.sizeOfArray("results[i].order_items");
while (j < count_j) {
j_resp.setJ(j);
item_seller_custom_field = try j_resp.stringOf(alloc, "results[i].order_items[j].item.seller_custom_field");
item_condition = try j_resp.stringOf(alloc, "results[i].order_items[j].item.condition");
item_category_id = try j_resp.stringOf(alloc, "results[i].order_items[j].item.category_id");
item_variation_id = try j_resp.stringOf(alloc, "results[i].order_items[j].item.variation_id");
item_seller_sku = try j_resp.stringOf(alloc, "results[i].order_items[j].item.seller_sku");
item_warranty = try j_resp.stringOf(alloc, "results[i].order_items[j].item.warranty");
item_id = try j_resp.stringOf(alloc, "results[i].order_items[j].item.id");
item_title = try j_resp.stringOf(alloc, "results[i].order_items[j].item.title");
quantity = j_resp.intOf("results[i].order_items[j].quantity");
differential_pricing_id = try j_resp.stringOf(alloc, "results[i].order_items[j].differential_pricing_id");
sale_fee = try j_resp.stringOf(alloc, "results[i].order_items[j].sale_fee");
listing_type_id = try j_resp.stringOf(alloc, "results[i].order_items[j].listing_type_id");
base_currency_id = try j_resp.stringOf(alloc, "results[i].order_items[j].base_currency_id");
unit_price = try j_resp.stringOf(alloc, "results[i].order_items[j].unit_price");
full_unit_price = try j_resp.stringOf(alloc, "results[i].order_items[j].full_unit_price");
base_exchange_rate = try j_resp.stringOf(alloc, "results[i].order_items[j].base_exchange_rate");
currency_id = try j_resp.stringOf(alloc, "results[i].order_items[j].currency_id");
manufacturing_days = try j_resp.stringOf(alloc, "results[i].order_items[j].manufacturing_days");
k = 0;
count_k = j_resp.sizeOfArray("results[i].order_items[j].item.variation_attributes");
while (k < count_k) {
j_resp.setK(k);
k = k + 1;
}
j = j + 1;
}
j = 0;
count_j = j_resp.sizeOfArray("results[i].tags");
while (j < count_j) {
j_resp.setJ(j);
str_val = try j_resp.stringOf(alloc, "results[i].tags[j]");
j = j + 1;
}
j = 0;
count_j = j_resp.sizeOfArray("results[i].mediations");
while (j < count_j) {
j_resp.setJ(j);
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = j_resp.sizeOfArray("available_sorts");
while (i < count_i) {
j_resp.setI(i);
id_str = try j_resp.stringOf(alloc, "available_sorts[i].id");
name = try j_resp.stringOf(alloc, "available_sorts[i].name");
i = i + 1;
}
i = 0;
count_i = j_resp.sizeOfArray("filters");
while (i < count_i) {
j_resp.setI(i);
i = i + 1;
}
}