Zig
Zig
Magento Request with OAuth1.0a Authentication
See more Magento Examples
Demonstrates sending a Magento request with OAuth1.0a authentication. (Using the Magento 1.x REST API)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 requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
http.setOAuth1(true);
http.setOAuthVerifier("");
http.setOAuthConsumerKey("MAGENTO_CONSUMER_KEY");
http.setOAuthConsumerSecret("MAGENTO_CONSUMER_SECRET");
http.setOAuthToken("MAGENTO__TOKEN");
http.setOAuthTokenSecret("MAGENTO_TOKEN_SECRET");
http.setAccept("application/json");
const url = "http://www.inart.com/api/rest/products/store/2?limit=20&page=1";
const json_str = http.quickGetStr(alloc, url) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response status code = {d}\n", .{http.getLastStatus()});
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.load(json_str) catch {};
json.setEmitCompact(false);
std.debug.print("{s}\n", .{try json.emit(alloc)});
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
}