Lua
Lua
MercadoLibre - Create Test User
See more MercadoLibre Examples
Crea un usuario de testChilkat Lua Downloads
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 POST -H "Content-Type: application/json" -d
-- '{
-- "site_id":"MLA"
-- }'
-- https://api.mercadolibre.com/users/test_user?access_token=MY_ACCESS_TOKEN
-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code
-- Use this online tool to generate code from sample JSON:
-- Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "site_id": "MLA"
-- }
local json = chilkat.JsonObject.new()
json:update_string("site_id", "MLA")
http:set_request_header("Content-Type", "application/json")
http:set_url_var("access_token", jsonToken:string_of("access_token"))
local resp = chilkat.HttpResponse.new()
success = http:http_json("POST", "https://api.mercadolibre.com/users/test_user?access_token={$access_token}", json, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
-- A response status code of 201 indicates success.
local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(resp.header)
print("Failed.")
return
end
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "id": 577815702,
-- "nickname": "TETE5320415",
-- "password": "qatest4890",
-- "site_status": "active",
-- "email": "test_user_80450945@testuser.com"
-- }
-- 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 id = jResp:int_of("id")
local nickname = jResp:string_of("nickname")
local password = jResp:string_of("password")
local site_status = jResp:string_of("site_status")