Entrada API de AIDA
AIDA permite cargar un documento directamente a través de la entrada API.
La integración se realiza con la clave de integración <integration_key> generada por AIDA.
Envía el documento con una solicitud POST multipart/form-data, con el archivo en el campo file.
Opcionalmente, puedes pasar un mapa de claves/valores con los valores de las propiedades que AIDA leerá. Cada "clave" del mapa puede ser el nombre de la propiedad o el Nombre del campo en las integraciones configurado en la configuración de la propiedad.
AIDA responde con el estado HTTP 200 cuando acepta el documento, 400 cuando falta el campo file y 403 cuando la clave de integración es incorrecta o el input está desactivado.
Los siguientes ejemplos cargan un archivo con dos valores de propiedad:
- Batch
- PowerShell
- Shell
- C#
- Java
- Python
- PHP
- Node.js
@echo off
rem curl.exe is included in Windows 10 (1803+), Windows 11 and Windows Server 2019+
rem Integration key: copy it from the Input page of the document type in AIDA
set "INTEGRATION_KEY=<integration_key>"
curl.exe -sS --fail ^
-F "file=@C:\path\to\your\file.pdf" ^
-F "sampleLabel1=sampleValue1" ^
-F "sampleLabel2=sampleValue2" ^
"https://api.aidacloud.com/api/v1/upload/direct/%INTEGRATION_KEY%"
exit /b %errorlevel%
# Works with Windows PowerShell 5.1 and PowerShell 7+
Add-Type -AssemblyName System.Net.Http
# Enables TLS 1.2 on older Windows and .NET Framework versions
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
# Integration key: copy it from the Input page of the document type in AIDA
$integrationKey = "<integration_key>"
$url = "https://api.aidacloud.com/api/v1/upload/direct/$integrationKey"
$filePath = "C:\path\to\your\file.pdf"
$client = New-Object System.Net.Http.HttpClient
$form = New-Object System.Net.Http.MultipartFormDataContent
$fileStream = [System.IO.File]::OpenRead($filePath)
try {
$form.Add((New-Object System.Net.Http.StreamContent($fileStream)), "file", [System.IO.Path]::GetFileName($filePath))
$form.Add((New-Object System.Net.Http.StringContent("sampleValue1")), "sampleLabel1")
$form.Add((New-Object System.Net.Http.StringContent("sampleValue2")), "sampleLabel2")
$response = $client.PostAsync($url, $form).Result
Write-Output "HTTP $([int]$response.StatusCode)"
}
finally {
$fileStream.Dispose()
$client.Dispose()
}
#!/bin/sh
# Linux and macOS
# Integration key: copy it from the Input page of the document type in AIDA
INTEGRATION_KEY="<integration_key>"
curl -sS --fail \
-F "file=@/path/to/your/file.pdf" \
-F "sampleLabel1=sampleValue1" \
-F "sampleLabel2=sampleValue2" \
"https://api.aidacloud.com/api/v1/upload/direct/$INTEGRATION_KEY"
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
// Integration key: copy it from the Input page of the document type in AIDA
var integrationKey = "<integration_key>";
var url = $"https://api.aidacloud.com/api/v1/upload/direct/{integrationKey}";
var filePath = @"C:\path\to\your\file.pdf";
using (var client = new HttpClient())
using (var form = new MultipartFormDataContent())
using (var fileStream = File.OpenRead(filePath))
{
form.Add(new StreamContent(fileStream), "file", Path.GetFileName(filePath));
form.Add(new StringContent("sampleValue1"), "sampleLabel1");
form.Add(new StringContent("sampleValue2"), "sampleLabel2");
var response = await client.PostAsync(url, form);
Console.WriteLine($"HTTP {(int)response.StatusCode}");
}
}
}
// Java 11+, no external dependencies
import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.UUID;
public class AidaUpload {
public static void main(String[] args) throws Exception {
// Integration key: copy it from the Input page of the document type in AIDA
String integrationKey = "<integration_key>";
String url = "https://api.aidacloud.com/api/v1/upload/direct/" + integrationKey;
Path file = Path.of("/path/to/your/file.pdf");
Map<String, String> values = Map.of(
"sampleLabel1", "sampleValue1",
"sampleLabel2", "sampleValue2");
String boundary = UUID.randomUUID().toString();
ByteArrayOutputStream body = new ByteArrayOutputStream();
for (Map.Entry<String, String> value : values.entrySet()) {
body.write(("--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"" + value.getKey() + "\"\r\n\r\n"
+ value.getValue() + "\r\n").getBytes(StandardCharsets.UTF_8));
}
body.write(("--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getFileName() + "\"\r\n"
+ "Content-Type: application/octet-stream\r\n\r\n").getBytes(StandardCharsets.UTF_8));
body.write(Files.readAllBytes(file));
body.write(("\r\n--" + boundary + "--\r\n").getBytes(StandardCharsets.UTF_8));
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.POST(HttpRequest.BodyPublishers.ofByteArray(body.toByteArray()))
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("HTTP " + response.statusCode());
}
}
# pip install requests
import requests
# Integration key: copy it from the Input page of the document type in AIDA
integration_key = "<integration_key>"
url = f"https://api.aidacloud.com/api/v1/upload/direct/{integration_key}"
values = {"sampleLabel1": "sampleValue1", "sampleLabel2": "sampleValue2"}
with open("/path/to/your/file.pdf", "rb") as file:
response = requests.post(url, files={"file": file}, data=values)
print(f"HTTP {response.status_code}")
<?php
// Integration key: copy it from the Input page of the document type in AIDA
$integrationKey = '<integration_key>';
$filePath = '/path/to/your/file.pdf';
$curl = curl_init('https://api.aidacloud.com/api/v1/upload/direct/' . $integrationKey);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, [
'file' => new CURLFile($filePath, null, basename($filePath)),
'sampleLabel1' => 'sampleValue1',
'sampleLabel2' => 'sampleValue2',
]);
curl_exec($curl);
echo 'HTTP ' . curl_getinfo($curl, CURLINFO_HTTP_CODE) . PHP_EOL;
// Node.js 18+, no external dependencies
const fs = require('fs');
const path = require('path');
// Integration key: copy it from the Input page of the document type in AIDA
const integrationKey = '<integration_key>';
async function uploadFile(filePath) {
const formData = new FormData();
formData.append('file', new Blob([fs.readFileSync(filePath)]), path.basename(filePath));
formData.append('sampleLabel1', 'sampleValue1');
formData.append('sampleLabel2', 'sampleValue2');
const response = await fetch(`https://api.aidacloud.com/api/v1/upload/direct/${integrationKey}`, {
method: 'POST',
body: formData
});
console.log(`HTTP ${response.status}`);
}
uploadFile('/path/to/your/file.pdf');