# Schnellstart

Eine erste authentifizierte Anfrage von Anfang bis Ende: einen Schlüssel holen, ein PDF senden, das zurückkommende Dokument speichern.

Der schnellste Weg von null zu einem verarbeiteten PDF: einen Schlüssel holen,
einen Aufruf machen, das Ergebnis speichern. Kein SDK, keine Einrichtung außer
einem API-Schlüssel und einem PDF auf der Festplatte.

<Steps>

<Step title="Einen API-Schlüssel holen">

Melden Sie sich beim [Dashboard](https://dashboard.pdfblocks.com) an und
erstellen Sie einen API-Schlüssel. Kopieren Sie ihn an einen sicheren Ort: Sie
senden ihn bei jeder Anfrage. Unter
[Authentifizierung](/docs/api/authentication) steht, wie Schlüssel funktionieren
und wie Sie sie sicher aufbewahren.

</Step>

<Step title="Einen Aufruf machen">

Legen Sie ein PDF namens `input.pdf` in Ihr Arbeitsverzeichnis, ersetzen Sie
`your_api_key` durch Ihren Schlüssel und führen Sie eines dieser Beispiele aus.
Jedes bringt ein Wasserzeichen auf das Dokument auf und schreibt das Ergebnis
nach `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="Ihr PDF öffnen">

Bei Erfolg antwortet die API mit `200 OK` und dem Dokument mit Wasserzeichen als
Antworttext:

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

Öffnen Sie `watermarked.pdf`: Es ist Ihre Eingabe, mit `CONFIDENTIAL` quer über
jeder Seite. Das ist der ganze Vertrag: Ein PDF ging hinein, ein PDF kam heraus,
und bei uns wurde nichts gespeichert.

</Step>

</Steps>

<Tip>
  Kein `200`? Ein fehlender oder falscher Schlüssel liefert `401`, ein
  unlesbares `file` liefert `400`, beide als `application/problem+json`. Den
  vollständigen Katalog der Statuscodes finden Sie unter
  [Fehler](/docs/api/errors).
</Tip>

## Nächste Schritte

<CardGroup cols={2}>

<Card title="Authentifizierung" href="/docs/api/authentication">
  Schlüssel verwalten, rotieren und aus der Versionsverwaltung heraushalten.
</Card>

<Card title="Übersicht der Aktionen" href="/docs/api/actions-overview">
  Alle 17 Aktionen durchsehen und sehen, wie sie sich zusammensetzen.
</Card>

<Card title="Anfragen und Antworten" href="/docs/api/requests-and-responses">
  Die einheitliche Form von Anfrage und Antwort, die jede Aktion teilt.
</Card>

</CardGroup>
