Authentication method
Facturama uses HTTP Basic Authentication. Every request must include anAuthorization header with your credentials encoded in Base64.
Authorization: Basic base64(username:password)
Sandbox vs Production credentials
| Environment | URL | URL API |
|---|---|---|
| Sandbox | dev.facturama.mx | https://apisandbox.facturama.mx |
| Producción | app.facturama.mx | https://api.facturama.mx |
Sandbox and Production use different credentials. Never use your production credentials in test environments.
Code examples
curl --location 'https://apisandbox.facturama.mx/api/Client' \
--header 'Authorization: Basic dHVfdXN1YXJpbzp0dV9jb250cmFzZcOxYQ=='
import requests
import base64
User = "UserName"
password = "Password"
credentials = base64.b64encode(f"{User}:{Password}".encode()).decode()
headers = {
"Authorization": f"Basic {credentials}",
"Content-Type": "application/json"
}
response = requests.get(
"https://apisandbox.facturama.mx/api/client",
headers=headers
)
print(response.json())
<?php
$user = "UserName";
$password = "Password";
$credentials = base64_encode("$user:$Password");
$ch = curl_init("https://apisandbox.facturama.mx/api/clients");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Basic $credentials",
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
const axios = require('axios');
const user = 'UserName';
const password = 'Password';
const credentials = Buffer.from(`${user}:${password}`).toString('base64');
axios.get('https://apisandbox.facturama.mx/api/clients', {
headers: {
Authorization: `Basic ${credentials}`,
'Content-Type': 'application/json'
}
}).then(res => console.log(res.data));
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args)
throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(
"https://apisandbox.facturama.mx/api/Client"
))
.header(
"Authorization",
"Basic dHVfdXN1YXJpbzp0dV9jb250cmFzZcOxYQ=="
)
.GET()
.build();
HttpResponse<String> response = client.send(
request,
HttpResponse.BodyHandlers.ofString()
);
System.out.println("Status: " + response.statusCode());
System.out.println(response.body());
}
}
require 'net/http'
require 'uri'
url = URI.parse(
'https://apisandbox.facturama.mx/api/Client'
)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url.request_uri)
request['Authorization'] =
'Basic dHVfdXN1YXJpbzp0dV9jb250cmFzZcOxYQ=='
response = http.request(request)
puts "Status: #{response.code}"
puts response.body
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add(
"Authorization",
"Basic dHVfdXN1YXJpbzp0dV9jb250cmFzZcOxYQ=="
);
var response = await client.GetAsync(
"https://apisandbox.facturama.mx/api/Client"
);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status: {(int)response.StatusCode}");
Console.WriteLine(content);
}
}
Manual Base64 encoding
If you need to build the header manually:echo -n "UserName:Password" | base64
# Resultado: ddHVfdXN1YXJpbzp0dV9jb250cmFzZcOxYQ==
[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("UserName:Password"))
# Resultado: ddHVfdXN1YXJpbzp0dV9jb250cmFzZcOxYQ==
The colon
: between username and password is part of the encoding. Do not add extra spaces.Authentication errors
| Code | Description |
|---|---|
401 Unauthorized | Incorrect or missing credentials |