Sample code for 30+ languages & platforms
DataFlex

SII POST boleta.electronica.envio

See more SII Chile Examples

Almacenamiento de un conjunto de boletas en el SII

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vReq
    Handle hoReq
    String sXmlStr
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sRut_emisor
    String sRut_envia
    Integer iTrackid
    String sFecha_recepcion
    String sEstado
    String sFile
    String sTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // 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

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Set ComHttpVerb Of hoReq To "POST"
    Set ComPath Of hoReq To "/recursos/v1/boleta.electronica.envio"
    Set ComContentType Of hoReq To "multipart/form-data"
    Send ComAddParam To hoReq "rutSender" "66666666"
    Send ComAddParam To hoReq "dvSender" "6"
    Send ComAddParam To hoReq "rutCompany" "60803000"
    Send ComAddParam To hoReq "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">
    // ...
    Move "..." To sXmlStr
    Get ComAddStringForUpload2 Of hoReq "archivo" "envioBoleta.xml" sXmlStr "ISO-8859-1" "text/xml" To iSuccess

    Send ComAddHeader To hoReq "Expect" "100-continue"
    Send ComAddHeader To hoReq "User-Agent" "Mozilla/4.0 ( compatible; PROG 1.0; Windows NT)"
    Send ComAddHeader To hoReq "Cookie" "TOKEN=YZVQNQY4J5DT9"
    Send ComAddHeader To hoReq "accept" "application/json"
    Send ComAddHeader To hoReq "Content-Type" "multipart/form-data"

    // For debugging, you can save the exact HTTP request sent and response received
    // to a session log file:
    Set ComSessionLogFilename Of hoHttp To "someDir/sessionLog.txt"

    // Use one of the following domains, depending on the environment:
    // pangal.sii.cl  - Certification Environment
    // rahue.sii.cl      - Production Environment
    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get pvComObject of hoReq to vReq
    Get pvComObject of hoResp to vResp
    Get ComHttpSReq Of hoHttp "pangal.sii.cl" 443 True vReq vResp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

    // 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

    Get ComStringOf Of hoJResp "rut_emisor" To sRut_emisor
    Get ComStringOf Of hoJResp "rut_envia" To sRut_envia
    Get ComIntOf Of hoJResp "trackid" To iTrackid
    Get ComStringOf Of hoJResp "fecha_recepcion" To sFecha_recepcion
    Get ComStringOf Of hoJResp "estado" To sEstado
    Get ComStringOf Of hoJResp "file" To sFile


End_Procedure