Zig
Zig
SII POST boleta.electronica.envio
See more SII Chile Examples
Almacenamiento de un conjunto de boletas en el SIIChilkat 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();
// Implements the following CURL command:
// curl -X POST "https://pangal.sii.cl/recursos/v1/boleta.electronica.envio" -H "accept: application/json"
// -H "User-Agent: Mozilla/4.0 ( compatible; PROG 1.0; Windows NT)"
// -H "Cookie: YZVQNQY4J5DT9" -H "Content-Type: multipart/form-data"
// -F "rutSender=1234" -F "dvSender=xyz" -F "rutCompany=9999" -F "dvCompany=abc"
// -F "archivo=@starfish20.jpg;type=image/jpeg"
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
const req = try chilkat.HttpRequest.init();
defer req.deinit();
req.setHttpVerb("POST");
req.setPath("/recursos/v1/boleta.electronica.envio");
req.setContentType("multipart/form-data");
req.addParam("rutSender", "66666666");
req.addParam("dvSender", "6");
req.addParam("rutCompany", "60803000");
req.addParam("dvCompany", "K");
// Add an XML file that contains something like this:
// <?xml version="1.0" encoding="ISO-8859-1"?>
// <EnvioBOLETA version="1.0" xmlns="http://www.sii.cl/SiiDte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioBOLETA_v11.xsd">
// <SetDTE ID="SetDocB0T39_20201103_131999">
// <Caratula version="1.0">
// ...
const xml_str = "...";
try req.addStringForUpload2("archivo", "envioBoleta.xml", xml_str, "ISO-8859-1", "text/xml");
req.addHeader("Expect", "100-continue");
req.addHeader("User-Agent", "Mozilla/4.0 ( compatible; PROG 1.0; Windows NT)");
req.addHeader("Cookie", "TOKEN=YZVQNQY4J5DT9");
req.addHeader("accept", "application/json");
req.addHeader("Content-Type", "multipart/form-data");
// For debugging, you can save the exact HTTP request sent and response received
// to a session log file:
http.setSessionLogFilename("someDir/sessionLog.txt");
// Use one of the following domains, depending on the environment:
// pangal.sii.cl - Certification Environment
// rahue.sii.cl - Production Environment
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpSReq("pangal.sii.cl", 443, true, req, resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
resp.getBodySb(sb_response_body) catch {};
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 = resp.getStatusCode();
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 resp.getHeader(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "rut_emisor": "45000054-K",
// "rut_envia": "83154595-0",
// "trackid": 1014,
// "fecha_recepcion": "2020-09-01 20:30:10",
// "estado": "REC",
// "file": "boleta-2020-09-01-001.xml"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
_ = try j_resp.stringOf(alloc, "rut_emisor");
_ = try j_resp.stringOf(alloc, "rut_envia");
_ = j_resp.intOf("trackid");
_ = try j_resp.stringOf(alloc, "fecha_recepcion");
_ = try j_resp.stringOf(alloc, "estado");
_ = try j_resp.stringOf(alloc, "file");
}