Invoices
Ecart Pay simplifies business invoicing by providing an integrated solution for creating, managing, and downloading electronic invoices while complying with international tax regulations.
In this documentation, we will explore how Ecart Pay enables businesses to efficiently manage their invoicing processes in compliance with the tax regulations of various countries. We will cover the key concepts surrounding invoices, their importance, the standard processes for their generation, and how Ecart Pay optimizes these workflows, including handling Digital Tax Receipts over the Internet (CFDI). Additionally, we will present the benefits and specific use cases of this solution.
What Are Invoices?
Invoices are legal documents that detail a commercial transaction between a seller and a buyer. They include information such as the total amount payable, the products or services provided, applicable taxes, and relevant dates.
In the context of Ecart Pay, invoices are digital documents generated and managed in compliance with each country’s tax regulations, ensuring legal and accounting validity.
Why Are Invoices Important?
Invoices are essential for recording commercial transactions, meeting tax obligations, and ensuring transparency in business operations. Additionally, they serve as vital tools for:
- Tax Compliance: Avoiding penalties or fines by adhering to local laws.
- Financial Control: Aiding in income and expense planning and recording.
- Transparency: Providing clarity to both sellers and buyers regarding transaction details.
GET Client Billing Invoices
This endpoint retrieves a list of invoices associated with registered clients.
Endpoint
GET {{baseURL}}/api/invoices
Headers
Authorization: {token}
Query Parameters
Parameter | Description |
---|---|
year | Year of the invoices (e.g., 2023). |
month | Month of the invoices (e.g., August). |
page | Page number for pagination (default: 1). |
limit | Number of invoices per page (default: 20). |
Example Request
curl --location 'https://sandbox.ecartpay.com/api/invoices?year=2023&month=August' \
--header 'Authorization: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A' \
--header 'Cookie: lang=en' \
--data ''
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://sandbox.ecartpay.com/api/invoices?year=2023&month=August"
method := "GET"
payload := strings.NewReader(``)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A")
req.Header.Add("Cookie", "lang=en")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
GET /api/invoices?year=2023&month=August HTTP/1.1
Host: sandbox.ecartpay.com
Authorization: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A
Cookie: lang=en
// OkHttp
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://sandbox.ecartpay.com/api/invoices?year=2023&month=August")
.method("GET", body)
.addHeader("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A")
.addHeader("Cookie", "lang=en")
.build();
Response response = client.newCall(request).execute();
// -------------------------------------------------------------
// Unirest
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.get("https://sandbox.ecartpay.com/api/invoices?year=2023&month=August")
.header("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A")
.header("Cookie", "lang=en")
.body("")
.asString();
// Fetch
const myHeaders = new Headers();
myHeaders.append("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A");
myHeaders.append("Cookie", "lang=en");
const raw = "";
const requestOptions = {
method: "GET",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch("https://sandbox.ecartpay.com/api/invoices?year=2023&month=August", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
// -------------------------------------------------------------
// jQuery
var settings = {
"url": "https://sandbox.ecartpay.com/api/invoices?year=2023&month=August",
"method": "GET",
"timeout": 0,
"headers": {
"Authorization": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A",
"Cookie": "lang=en"
},
};
$.ajax(settings).done(function (response) {
console.log(response);
});
// -------------------------------------------------------------
// XHR
// WARNING: For GET requests, body is set to null by browsers.
var data = "";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://sandbox.ecartpay.com/api/invoices?year=2023&month=August");
xhr.setRequestHeader("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A");
// WARNING: Cookies will be stripped away by the browser before sending the request.
xhr.setRequestHeader("Cookie", "lang=en");
xhr.send(data);
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "https://sandbox.ecartpay.com/api/invoices?year=2023&month=August");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Authorization: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A");
headers = curl_slist_append(headers, "Cookie: lang=en");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
// Axios
const axios = require('axios');
let data = '';
let config = {
method: 'get',
maxBodyLength: Infinity,
url: 'https://sandbox.ecartpay.com/api/invoices?year=2023&month=August',
headers: {
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie': 'lang=en'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
// -------------------------------------------------------------
// Native
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'GET',
'hostname': 'sandbox.ecartpay.com',
'path': '/api/invoices?year=2023&month=August',
'headers': {
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie': 'lang=en'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
req.end();
// -------------------------------------------------------------
// Request
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://sandbox.ecartpay.com/api/invoices?year=2023&month=August',
'headers': {
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie': 'lang=en'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
// -------------------------------------------------------------
// Unirest
var unirest = require('unirest');
var req = unirest('GET', 'https://sandbox.ecartpay.com/api/invoices?year=2023&month=August')
.headers({
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie': 'lang=en'
})
.send("")
.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.raw_body);
});
#import <Foundation/Foundation.h>
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://sandbox.ecartpay.com/api/invoices?year=2023&month=August"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"Authorization": @"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A",
@"Cookie": @"lang=en"
};
[request setAllHTTPHeaderFields:headers];
NSData *postData = [[NSData alloc] initWithData:[@"" dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postData];
[request setHTTPMethod:@"GET"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
dispatch_semaphore_signal(sema);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"%@",responseDictionary);
dispatch_semaphore_signal(sema);
}
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
open Lwt
open Cohttp
open Cohttp_lwt_unix
let reqBody =
let uri = Uri.of_string "https://sandbox.ecartpay.com/api/invoices?year=2023&month=August" in
let headers = Header.init ()
|> fun h -> Header.add h "Authorization" "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A"
|> fun h -> Header.add h "Cookie" "lang=en"
in
Client.call ~headers `GET uri >>= fun (_resp, body) ->
body |> Cohttp_lwt.Body.to_string >|= fun body -> body
let () =
let respBody = Lwt_main.run reqBody in
print_endline (respBody)
// cURL
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://sandbox.ecartpay.com/api/invoices?year=2023&month=August',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie: lang=en'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
// -------------------------------------------------------------
// Guzzle
<?php
$client = new Client();
$headers = [
'Authorization' => 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie' => 'lang=en'
];
$body = '';
$request = new Request('GET', 'https://sandbox.ecartpay.com/api/invoices?year=2023&month=August', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
// -------------------------------------------------------------
// HTTP_Request2
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://sandbox.ecartpay.com/api/invoices?year=2023&month=August');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie' => 'lang=en'
));
$request->setBody('');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
// -------------------------------------------------------------
// pecl_http
<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://sandbox.ecartpay.com/api/invoices?year=2023&month=August');
$request->setRequestMethod('GET');
$body = new http\Message\Body;
$request->setBody($body);
$request->setOptions(array());
$request->setHeaders(array(
'Authorization' => 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie' => 'lang=en'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A")
$headers.Add("Cookie", "lang=en")
$body = @"
"@
$response = Invoke-RestMethod 'https://sandbox.ecartpay.com/api/invoices?year=2023&month=August' -Method 'GET' -Headers $headers -Body $body
$response | ConvertTo-Json
# http.client
import http.client
conn = http.client.HTTPSConnection("sandbox.ecartpay.com")
payload = ''
headers = {
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie': 'lang=en'
}
conn.request("GET", "/api/invoices?year=2023&month=August", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
// -------------------------------------------------------------
# Requests
import requests
url = "https://sandbox.ecartpay.com/api/invoices?year=2023&month=August"
payload = ""
headers = {
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie': 'lang=en'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
# httr
library(httr)
headers = c(
'Authorization' = 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A',
'Cookie' = 'lang=en'
)
body = ""
res <- VERB("GET", url = "https://sandbox.ecartpay.com/api/invoices?year=2023&month=August", body = body, add_headers(headers))
cat(content(res, 'text'))
// -------------------------------------------------------------
# RCurl
library(RCurl)
headers = c(
"Authorization" = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A",
"Cookie" = "lang=en"
)
params = ""
res <- getURL("https://sandbox.ecartpay.com/api/invoices?year=2023&month=August", .opts=list(httpheader = headers, followlocation = TRUE))
cat(res)
require "uri"
require "net/http"
url = URI("https://sandbox.ecartpay.com/api/invoices?year=2023&month=August")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A"
request["Cookie"] = "lang=en"
response = https.request(request)
puts response.read_body
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::builder()
.build()?;
let mut headers = reqwest::header::HeaderMap::new();
headers.insert("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A".parse()?);
headers.insert("Cookie", "lang=en".parse()?);
let data = "";
let request = client.request(reqwest::Method::GET, "https://sandbox.ecartpay.com/api/invoices?year=2023&month=August")
.headers(headers)
.body(data);
let response = request.send().await?;
let body = response.text().await?;
println!("{}", body);
Ok(())
}
# Httpie
http --follow --timeout 3600 GET 'https://sandbox.ecartpay.com/api/invoices?year=2023&month=August' \
Authorization:'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A' \
Cookie:'lang=en'
// -------------------------------------------------------------
# wget
wget --no-check-certificate --quiet \
--method GET \
--timeout=0 \
--header 'Authorization: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A' \
--header 'Cookie: lang=en' \
'https://sandbox.ecartpay.com/api/invoices?year=2023&month=August'
var request = URLRequest(url: URL(string: "https://sandbox.ecartpay.com/api/invoices?year=2023&month=August")!,timeoutInterval: Double.infinity)
request.addValue("eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg2OTA5NDQsImV4cCI6MTczODY5NDU0NH0.eJ7LOLmSwZBVcdol6_7trjeNQBQKjF0IGnJnWrqwpi80Fm5OlezbV2V0rhKmrFA5kW8o7REniUSWEVCIQcrb4A", forHTTPHeaderField: "Authorization")
request.addValue("lang=en", forHTTPHeaderField: "Cookie")
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
Example Response
{
"count": 0,
"pages": 0,
"docs": []
}
Typical Workflow for Generating an Invoice
- Gather Basic Data: Collect customer information and transaction details.
- Configure Taxes: Apply the relevant taxes as per local regulations.
- Generate the Invoice: Create the electronic document in the required format (XML, PDF, etc.).
- Validate and Register: Validate the document with the respective tax authorities, such as the SAT in Mexico.
- Distribute: Send the invoice to the client and store it for audit and accounting purposes.
What Is CFDI and Its Relation to Invoices?
The CFDI (Comprobante Fiscal Digital por Internet) is a type of electronic invoice required in Mexico that complies with the tax standards set by the SAT (Tax Administration Service). An invoice becomes a CFDI through a certification process, ensuring its legal and fiscal validity.
GET Client Billing Invoices
This endpoint allows downloading a CFDI for a specific invoice.
Endpoint
GET {{baseURL}}/api/invoices/cfdi/download/:id
Headers
Authorization: {token}
Referer
: Base URL (e.g.,{baseUrl}
).
Path Variable
id
: Unique identifier of the invoice (e.g.,658b47f407f38aeb09e22173
).
Example Request
curl --location 'https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173' \
--header 'Authorization: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g' \
--header 'Referer: https://sandbox.ecartpay.com' \
--header 'Cookie: lang=en'
package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173"
method := "GET"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g")
req.Header.Add("Referer", "https://sandbox.ecartpay.com")
req.Header.Add("Cookie", "lang=en")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
GET /api/invoices/cfdi/download/658b47f407f38aeb09e22173 HTTP/1.1
Host: sandbox.ecartpay.com
Authorization: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g
Referer: https://sandbox.ecartpay.com
Cookie: lang=en
// OkHttp
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173")
.method("GET", body)
.addHeader("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g")
.addHeader("Referer", "https://sandbox.ecartpay.com")
.addHeader("Cookie", "lang=en")
.build();
Response response = client.newCall(request).execute();
// -------------------------------------------------------------
// Unirest
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.get("https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173")
.header("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g")
.header("Referer", "https://sandbox.ecartpay.com")
.header("Cookie", "lang=en")
.asString();
// Fetch
const myHeaders = new Headers();
myHeaders.append("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g");
myHeaders.append("Referer", "https://sandbox.ecartpay.com");
myHeaders.append("Cookie", "lang=en");
const requestOptions = {
method: "GET",
headers: myHeaders,
redirect: "follow"
};
fetch("https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
// -------------------------------------------------------------
// jQuery
var settings = {
"url": "https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173",
"method": "GET",
"timeout": 0,
"headers": {
"Authorization": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g",
"Referer": "https://sandbox.ecartpay.com",
"Cookie": "lang=en"
},
};
$.ajax(settings).done(function (response) {
console.log(response);
});
// -------------------------------------------------------------
// XHR
// WARNING: For GET requests, body is set to null by browsers.
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173");
xhr.setRequestHeader("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g");
xhr.setRequestHeader("Referer", "https://sandbox.ecartpay.com");
// WARNING: Cookies will be stripped away by the browser before sending the request.
xhr.setRequestHeader("Cookie", "lang=en");
xhr.send();
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Authorization: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g");
headers = curl_slist_append(headers, "Referer: https://sandbox.ecartpay.com");
headers = curl_slist_append(headers, "Cookie: lang=en");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
}
curl_easy_cleanup(curl);
// Axios
const axios = require('axios');
let config = {
method: 'get',
maxBodyLength: Infinity,
url: 'https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173',
headers: {
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer': 'https://sandbox.ecartpay.com',
'Cookie': 'lang=en'
}
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
// -------------------------------------------------------------
// Native
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'GET',
'hostname': 'sandbox.ecartpay.com',
'path': '/api/invoices/cfdi/download/658b47f407f38aeb09e22173',
'headers': {
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer': 'https://sandbox.ecartpay.com',
'Cookie': 'lang=en'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
req.end();
// -------------------------------------------------------------
// Request
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173',
'headers': {
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer': 'https://sandbox.ecartpay.com',
'Cookie': 'lang=en'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
// -------------------------------------------------------------
// Unirest
var unirest = require('unirest');
var req = unirest('GET', 'https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173')
.headers({
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer': 'https://sandbox.ecartpay.com',
'Cookie': 'lang=en'
})
.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.raw_body);
});
#import <Foundation/Foundation.h>
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"Authorization": @"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g",
@"Referer": @"https://sandbox.ecartpay.com",
@"Cookie": @"lang=en"
};
[request setAllHTTPHeaderFields:headers];
[request setHTTPMethod:@"GET"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
dispatch_semaphore_signal(sema);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"%@",responseDictionary);
dispatch_semaphore_signal(sema);
}
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
open Lwt
open Cohttp
open Cohttp_lwt_unix
let reqBody =
let uri = Uri.of_string "https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173" in
let headers = Header.init ()
|> fun h -> Header.add h "Authorization" "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g"
|> fun h -> Header.add h "Referer" "https://sandbox.ecartpay.com"
|> fun h -> Header.add h "Cookie" "lang=en"
in
Client.call ~headers `GET uri >>= fun (_resp, body) ->
body |> Cohttp_lwt.Body.to_string >|= fun body -> body
let () =
let respBody = Lwt_main.run reqBody in
print_endline (respBody)
// cURL
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer: https://sandbox.ecartpay.com',
'Cookie: lang=en'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
// -------------------------------------------------------------
// Guzzle
<?php
$client = new Client();
$headers = [
'Authorization' => 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer' => 'https://sandbox.ecartpay.com',
'Cookie' => 'lang=en'
];
$request = new Request('GET', 'https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173', $headers);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
// -------------------------------------------------------------
// HTTP_Request2
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Authorization' => 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer' => 'https://sandbox.ecartpay.com',
'Cookie' => 'lang=en'
));
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
// -------------------------------------------------------------
// pecl_http
<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173');
$request->setRequestMethod('GET');
$request->setOptions(array());
$request->setHeaders(array(
'Authorization' => 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer' => 'https://sandbox.ecartpay.com',
'Cookie' => 'lang=en'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g")
$headers.Add("Referer", "https://sandbox.ecartpay.com")
$headers.Add("Cookie", "lang=en")
$response = Invoke-RestMethod 'https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
# http.client
import http.client
conn = http.client.HTTPSConnection("sandbox.ecartpay.com")
payload = ''
headers = {
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer': 'https://sandbox.ecartpay.com',
'Cookie': 'lang=en'
}
conn.request("GET", "/api/invoices/cfdi/download/658b47f407f38aeb09e22173", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
// -------------------------------------------------------------
# Requests
import requests
url = "https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173"
payload = {}
headers = {
'Authorization': 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer': 'https://sandbox.ecartpay.com',
'Cookie': 'lang=en'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
# httr
library(httr)
headers = c(
'Authorization' = 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g',
'Referer' = 'https://sandbox.ecartpay.com',
'Cookie' = 'lang=en'
)
res <- VERB("GET", url = "https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173", add_headers(headers))
cat(content(res, 'text'))
// -------------------------------------------------------------
# RCurl
library(RCurl)
headers = c(
"Authorization" = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g",
"Referer" = "https://sandbox.ecartpay.com",
"Cookie" = "lang=en"
)
res <- getURL("https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173", .opts=list(httpheader = headers, followlocation = TRUE))
cat(res)
require "uri"
require "net/http"
url = URI("https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g"
request["Referer"] = "https://sandbox.ecartpay.com"
request["Cookie"] = "lang=en"
response = https.request(request)
puts response.read_body
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::builder()
.build()?;
let mut headers = reqwest::header::HeaderMap::new();
headers.insert("Authorization", "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g".parse()?);
headers.insert("Referer", "https://sandbox.ecartpay.com".parse()?);
headers.insert("Cookie", "lang=en".parse()?);
let request = client.request(reqwest::Method::GET, "https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173")
.headers(headers);
let response = request.send().await?;
let body = response.text().await?;
println!("{}", body);
Ok(())
}
# Httpie
http --follow --timeout 3600 GET 'https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173' \
Authorization:'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g' \
Referer:'https://sandbox.ecartpay.com' \
Cookie:'lang=en'
// -------------------------------------------------------------
# wget
wget --no-check-certificate --quiet \
--method GET \
--timeout=0 \
--header 'Authorization: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g' \
--header 'Referer: https://sandbox.ecartpay.com' \
--header 'Cookie: lang=en' \
'https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173'
var request = URLRequest(url: URL(string: "https://sandbox.ecartpay.com/api/invoices/cfdi/download/658b47f407f38aeb09e22173")!,timeoutInterval: Double.infinity)
request.addValue("eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY3MmE4NTAzNzFiZTBlY2Y1NTRkMDUxNiIsImFjY291bnRfaWQiOiI2NzJhODUwMzcxYmUwZWNmNTU0ZDA1MGMiLCJpYXQiOjE3Mzg3NzM1NTUsImV4cCI6MTczODc3NzE1NX0.oksy5FrkEvpJ21yCS5rgE2nEDhb_1xWNbG4q66bjGdjN6dnCwmVEueybWHuQBfqIcASwpCmP0cB0BYVYT63y3g", forHTTPHeaderField: "Authorization")
request.addValue("https://sandbox.ecartpay.com", forHTTPHeaderField: "Referer")
request.addValue("lang=en", forHTTPHeaderField: "Cookie")
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
Example Response
The response body contains the CFDI in XML or PDF format, depending on the request. Headers may include details of the downloaded file.
Benefits of Ecart Pay
- International Tax Compliance: Manage invoices in compliance with regulations across multiple countries.
- Process Optimization: Automate invoice generation, validation, and distribution.
- Seamless Integration: Flexible API facilitates integration with existing enterprise systems.
- Expanded Support: Current and future coverage in various countries.
Use Cases
- Multinational Companies: Centralize invoicing on a single platform.
- Growing SMEs: Scale operations without worrying about meeting diverse tax regulations.
- Freelancers or Contractors: Issue valid invoices in Mexico and other countries for international clients.
Conclusion
Ecart Pay is a versatile and robust solution for businesses seeking to efficiently and securely comply with tax regulations. With features like invoice generation and CFDI downloading, it simplifies accounting and tax management, allowing businesses to focus on growth.
Updated about 2 months ago