Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) SII POST boleta.electronica.envioAlmacenamiento de un conjunto de boletas en el SII For more information, see https://www4c.sii.cl/bolcoreinternetui/api/
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkHttpRequest.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; 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 req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpRequest::setCkHttpVerb(req, "POST") CkHttpRequest::setCkPath(req, "/recursos/v1/boleta.electronica.envio") CkHttpRequest::setCkContentType(req, "multipart/form-data") CkHttpRequest::ckAddParam(req,"rutSender","66666666") CkHttpRequest::ckAddParam(req,"dvSender","6") CkHttpRequest::ckAddParam(req,"rutCompany","60803000") CkHttpRequest::ckAddParam(req,"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"> ; ... xmlStr.s = "..." success = CkHttpRequest::ckAddStringForUpload2(req,"archivo","envioBoleta.xml",xmlStr,"ISO-8859-1","text/xml") CkHttpRequest::ckAddHeader(req,"Expect","100-continue") CkHttpRequest::ckAddHeader(req,"User-Agent","Mozilla/4.0 ( compatible; PROG 1.0; Windows NT)") CkHttpRequest::ckAddHeader(req,"Cookie","TOKEN=YZVQNQY4J5DT9") CkHttpRequest::ckAddHeader(req,"accept","application/json") CkHttpRequest::ckAddHeader(req,"Content-Type","multipart/form-data") ; For debugging, you can save the exact HTTP request sent and response received ; to a session log file: CkHttp::setCkSessionLogFilename(http, "someDir/sessionLog.txt") ; Use one of the following domains, depending on the environment: ; pangal.sii.cl - Certification Environment ; rahue.sii.cl - Production Environment resp.i = CkHttp::ckSynchronousRequest(http,"pangal.sii.cl",443,1,req) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; 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 rut_emisor.s = CkJsonObject::ckStringOf(jResp,"rut_emisor") rut_envia.s = CkJsonObject::ckStringOf(jResp,"rut_envia") trackid.i = CkJsonObject::ckIntOf(jResp,"trackid") fecha_recepcion.s = CkJsonObject::ckStringOf(jResp,"fecha_recepcion") estado.s = CkJsonObject::ckStringOf(jResp,"estado") file.s = CkJsonObject::ckStringOf(jResp,"file") CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.