Sample code for 30+ languages & platforms
Rust

hacienda.go.cr Recepción de comprobantes electrónicos y respuestas del receptor.

See more hacienda.go.cr Examples

Comprobantes Electrónicos API version v1 -- Recepción de comprobantes electrónicos y respuestas del receptor.

Chilkat Rust Downloads

Rust

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

let http = chilkat::Http::new();

// Implements the following CURL command:

// curl -X POST -H "Content-Type: application / json" \
//   -H 'authorization: Bearer {access_token}' \
//   -d '{
//   "clave": "50601011600310112345600100010100000000011999999999",
//   "fecha": "2016-01-01T00:00:00-0600",
//   "emisor": {
//     "tipoIdentificacion": "02",
//     "numeroIdentificacion": "003101123456"
//   },
//   "receptor": {
//     "tipoIdentificacion": "02",
//     "numeroIdentificacion": "003101123456"
//   },
//   "comprobanteXml": "PD94..."
// }' https://api.comprobanteselectronicos.go.cr/recepcion/v1/recepcion

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "clave": "50601011600310112345600100010100000000011999999999",
//   "fecha": "2016-01-01T00:00:00-0600",
//   "emisor": {
//     "tipoIdentificacion": "02",
//     "numeroIdentificacion": "003101123456"
//   },
//   "receptor": {
//     "tipoIdentificacion": "02",
//     "numeroIdentificacion": "003101123456"
//   },
//   "comprobanteXml": "PD94b..."
// }

// Load the previously signed XML.
let bd_signed_xml = chilkat::BinData::new();
if bd_signed_xml.load_file("someDir/signed.xml").is_err() {
    println!("Failed to load the XAdES signed XML.");
    return;
}

let json = chilkat::JsonObject::new();
let _ = json.update_string("clave", "50601011600310112345600100010100000000011999999999");
let _ = json.update_string("fecha", "2016-01-01T00:00:00-0600");
let _ = json.update_string("emisor.tipoIdentificacion", "02");
let _ = json.update_string("emisor.numeroIdentificacion", "003101123456");
let _ = json.update_string("receptor.tipoIdentificacion", "02");
let _ = json.update_string("receptor.numeroIdentificacion", "003101123456");
// Add the base64 encoded representation of the signed XML.
let _ = json.update_string("comprobanteXml", &bd_signed_xml.get_encoded("base64").unwrap_or_default());

// Load our previously obtained OAuth2 access token.
let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/hacienda_cr.json").is_err() {
    println!("Failed to load constantContact.json");
    return;
}

// Adds the "Authorization: Bearer {access_token}" header.
http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());

http.set_request_header("Content-Type", "application / json");

let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://api.comprobanteselectronicos.go.cr/recepcion/v1/recepcion", &json, "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

// A 201 status code indicates success.
println!("Response status code: {}", resp.status_code());

println!("Response body:");
println!("{}", resp.body_str());