Sample code for 30+ languages & platforms
AutoIt

SII POST boleta.electronica.envio

See more SII Chile Examples

Almacenamiento de un conjunto de boletas en el SII

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

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

$oHttp = ObjCreate("Chilkat.Http")

; 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

$oReq = ObjCreate("Chilkat.HttpRequest")
$oReq.HttpVerb = "POST"
$oReq.Path = "/recursos/v1/boleta.electronica.envio"
$oReq.ContentType = "multipart/form-data"
$oReq.AddParam "rutSender","66666666"
$oReq.AddParam "dvSender","6"
$oReq.AddParam "rutCompany","60803000"
$oReq.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">
; ...
Local $sXmlStr = "..."
$bSuccess = $oReq.AddStringForUpload2("archivo","envioBoleta.xml",$sXmlStr,"ISO-8859-1","text/xml")

$oReq.AddHeader "Expect","100-continue"
$oReq.AddHeader "User-Agent","Mozilla/4.0 ( compatible; PROG 1.0; Windows NT)"
$oReq.AddHeader "Cookie","TOKEN=YZVQNQY4J5DT9"
$oReq.AddHeader "accept","application/json"
$oReq.AddHeader "Content-Type","multipart/form-data"

; For debugging, you can save the exact HTTP request sent and response received
; to a session log file:
$oHttp.SessionLogFilename = "someDir/sessionLog.txt"

; Use one of the following domains, depending on the environment:
; pangal.sii.cl  - Certification Environment
; rahue.sii.cl      - Production Environment
$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpSReq("pangal.sii.cl",443,True,$oReq,$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oResp.Header & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

; 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

Local $sRut_emisor = $oJResp.StringOf("rut_emisor")
Local $sRut_envia = $oJResp.StringOf("rut_envia")
Local $iTrackid = $oJResp.IntOf("trackid")
Local $sFecha_recepcion = $oJResp.StringOf("fecha_recepcion")
Local $sEstado = $oJResp.StringOf("estado")
Local $sFile = $oJResp.StringOf("file")