# Avvio rapido

Una prima richiesta autenticata dall’inizio alla fine: ottenere una chiave, inviare un PDF, salvare il documento che torna indietro.

Il percorso più rapido da zero a un PDF elaborato: ottenere una chiave, fare una
chiamata, salvare il risultato. Nessun SDK e nessuna configurazione oltre a una
chiave API e a un PDF sul disco.

<Steps>

<Step title="Ottenere una chiave API">

Accedere alla [dashboard](https://dashboard.pdfblocks.com) e creare una chiave
API. Copiarla in un posto sicuro: va inviata a ogni richiesta. Vedere
[Autenticazione](/docs/api/authentication) per il funzionamento delle chiavi e
per come tenerle al sicuro.

</Step>

<Step title="Fare una chiamata">

Mettere un PDF di nome `input.pdf` nella directory di lavoro, sostituire
`your_api_key` con la propria chiave ed eseguire uno di questi esempi. Ognuno
appone una filigrana sul documento e scrive il risultato in `watermarked.pdf`.

<CodeGroup>

```bash title="cURL"
curl https://api.pdfblocks.com/v1/add_text_watermark \
  -H 'X-API-Key: your_api_key' \
  -F file=@input.pdf \
  -F line_1='CONFIDENTIAL' \
  -o watermarked.pdf
```

```python title="Python"
# pip install requests
import requests

with open('input.pdf', 'rb') as file:
    response = requests.post(
        'https://api.pdfblocks.com/v1/add_text_watermark',
        headers={'X-API-Key': 'your_api_key'},
        files={'file': file},
        data={'line_1': 'CONFIDENTIAL'},
    )

response.raise_for_status()
with open('watermarked.pdf', 'wb') as output:
    output.write(response.content)
```

```javascript title="Node.js"
// Node.js 18+
import { readFile, writeFile } from 'node:fs/promises';

const body = new FormData();
body.set('file', new Blob([await readFile('input.pdf')]), 'input.pdf');
body.set('line_1', 'CONFIDENTIAL');

const response = await fetch('https://api.pdfblocks.com/v1/add_text_watermark', {
  method: 'POST',
  headers: { 'X-API-Key': 'your_api_key' },
  body,
});

if (!response.ok) throw new Error(`Request failed: ${response.status}`);
await writeFile('watermarked.pdf', Buffer.from(await response.arrayBuffer()));
```

```php title="PHP"
<?php
$ch = curl_init('https://api.pdfblocks.com/v1/add_text_watermark');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['X-API-Key: your_api_key'],
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => [
        'file' => new CURLFile('input.pdf', 'application/pdf'),
        'line_1' => 'CONFIDENTIAL',
    ],
]);

$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) {
    file_put_contents('watermarked.pdf', $pdf);
}
```

```ruby title="Ruby"
# gem install http
require 'http'

response = HTTP
  .headers('X-API-Key' => 'your_api_key')
  .post('https://api.pdfblocks.com/v1/add_text_watermark', form: {
    file: HTTP::FormData::File.new('input.pdf'),
    line_1: 'CONFIDENTIAL',
  })

File.write('watermarked.pdf', response.body) if response.status.success?
```

```go title="Go"
package main

import (
	"bytes"
	"io"
	"mime/multipart"
	"net/http"
	"os"
)

func main() {
	var buf bytes.Buffer
	form := multipart.NewWriter(&buf)

	file, _ := os.Open("input.pdf")
	defer file.Close()
	part, _ := form.CreateFormFile("file", "input.pdf")
	io.Copy(part, file)

	form.WriteField("line_1", "CONFIDENTIAL")
	form.Close()

	req, _ := http.NewRequest("POST", "https://api.pdfblocks.com/v1/add_text_watermark", &buf)
	req.Header.Set("Content-Type", form.FormDataContentType())
	req.Header.Set("X-API-Key", "your_api_key")

	res, _ := http.DefaultClient.Do(req)
	defer res.Body.Close()

	out, _ := os.Create("watermarked.pdf")
	defer out.Close()
	io.Copy(out, res.Body)
}
```

```csharp title="C#"
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", "your_api_key");

using var form = new MultipartFormDataContent
{
    { new ByteArrayContent(File.ReadAllBytes("input.pdf")), "file", "input.pdf" },
    { new StringContent("CONFIDENTIAL"), "line_1" },
};

var response = await client.PostAsync(
    "https://api.pdfblocks.com/v1/add_text_watermark", form);
response.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync(
    "watermarked.pdf", await response.Content.ReadAsByteArrayAsync());
```

</CodeGroup>

</Step>

<Step title="Aprire il PDF">

In caso di successo l’API risponde `200 OK` con il documento filigranato come
corpo:

```http
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Length: 48213
```

Aprire `watermarked.pdf`: è il file di partenza con `CONFIDENTIAL` apposto su
ogni pagina. Il contratto è tutto qui: è entrato un PDF, è uscito un PDF e da
parte nostra non è stato memorizzato nulla.

</Step>

</Steps>

<Tip>
  Nessun `200`? Una chiave mancante o errata restituisce `401` e un `file`
  illeggibile restituisce `400`, entrambi come `application/problem+json`.
  Vedere [Errori](/docs/api/errors) per il catalogo completo dei codici di
  stato.
</Tip>

## Passaggi successivi

<CardGroup cols={2}>

<Card title="Autenticazione" href="/docs/api/authentication">
  Gestire le chiavi, ruotarle e tenerle fuori dal controllo di versione.
</Card>

<Card title="Panoramica delle azioni" href="/docs/api/actions-overview">
  Sfogliare tutte le 17 azioni e vedere come si compongono.
</Card>

<Card title="Richieste e risposte" href="/docs/api/requests-and-responses">
  La forma uniforme di richiesta e risposta condivisa da ogni azione.
</Card>

</CardGroup>
