API guide: step by step
Everything you need to connect HelpWithDocument, with examples you can copy for the most common jobs. Every example is one request: send a file, get the finished file back.
Before you start
- Open the Business dashboard (sign up if you are new) and create an API key. New accounts get 2,500 free credits.
- Keep the key secret, like a password. Use it only on your own server or computer, never inside web page code that visitors can see.
- Want to see it work first? Try the API free with no sign-up.
Your first request
This turns a Word file into a PDF. Put your key in place of YOUR_API_KEY and your file name in place of letter.docx, then run it. The PDF is saved next to it.
curl -X POST "https://helpwithdocument.com/api/v1/run" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "operation=word-to-pdf" \
-F "files=@letter.docx" \
-o "letter.pdf"To use a different tool, change operation. The full list of tools shows each one and its credits.
Turn invoices into Excel
One invoice, PDF in, Excel out:
curl -X POST "https://helpwithdocument.com/api/v1/run" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "operation=pdf-to-excel" \
-F "files=@invoice.pdf" \
-o "invoice.xlsx"A whole folder at once: put your PDFs in a folder called invoices and run this. Each one gets an Excel file with the same name. Any that fail are skipped and cost nothing.
import pathlib
import requests
API_KEY = "YOUR_API_KEY"
folder = pathlib.Path("invoices")
for pdf in sorted(folder.glob("*.pdf")):
with open(pdf, "rb") as handle:
response = requests.post(
"https://helpwithdocument.com/api/v1/run",
headers={"Authorization": f"Bearer {API_KEY}"},
data={"operation": "pdf-to-excel"},
files={"files": handle},
)
if response.ok:
pdf.with_suffix(".xlsx").write_bytes(response.content)
print("Done:", pdf.name, "-", response.headers.get("X-Credits-Used"), "credits")
else:
print("Skipped:", pdf.name, "-", response.json()["error"]["message"])Convert files from your website
Let your visitors upload a file and get the converted version back. The page sends the file to your server, and your server asks HelpWithDocument. That way your key is never shown to visitors.
<!-- On your page: a normal upload form that posts to YOUR server -->
<form action="/convert.php" method="post" enctype="multipart/form-data">
<input type="file" name="document" accept=".doc,.docx" required>
<button type="submit">Convert to PDF</button>
</form><?php
// convert.php, on your own server. Your API key stays here, never in the page.
$upload = $_FILES["document"];
$ch = curl_init("https://helpwithdocument.com/api/v1/run");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("HWD_API_KEY")],
CURLOPT_POSTFIELDS => [
"operation" => "word-to-pdf",
"files" => new CURLFile($upload["tmp_name"], $upload["type"], $upload["name"]),
],
]);
$pdf = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
http_response_code(400);
exit(json_decode($pdf, true)["error"]["message"]);
}
header("Content-Type: application/pdf");
header('Content-Disposition: attachment; filename="converted.pdf"');
echo $pdf;// Node.js (Express) route on your own server
import express from "express";
import multer from "multer";
const app = express();
const upload = multer({ limits: { fileSize: 30 * 1024 * 1024 } });
app.post("/convert", upload.single("document"), async (req, res) => {
const form = new FormData();
form.append("operation", "word-to-pdf");
form.append("files", new Blob([req.file.buffer]), req.file.originalname);
const reply = await fetch("https://helpwithdocument.com/api/v1/run", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.HWD_API_KEY}` },
body: form,
});
if (!reply.ok) return res.status(400).send((await reply.json()).error.message);
res.attachment("converted.pdf").type("application/pdf");
res.send(Buffer.from(await reply.arrayBuffer()));
});
app.listen(3000);Store the key in a setting called HWD_API_KEY on your server rather than writing it in the code.
Make scans searchable
Scanned pages and photos become a PDF you can search and copy text from. OCR is charged per page.
curl -X POST "https://helpwithdocument.com/api/v1/run" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "operation=ocr-pdf" \
-F "files=@scan.pdf" \
-o "scan-searchable.pdf"Stamp documents
Add a watermark such as CONFIDENTIAL or DRAFT to every page:
curl -X POST "https://helpwithdocument.com/api/v1/run" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "operation=add-watermark" \
-F "files=@contract.pdf" \
-F "watermarkText=CONFIDENTIAL" \
-o "contract-confidential.pdf"For your own logo, page numbers in the stamp or saved designs, see Custom Watermark.
Check your credits
Every finished file tells you its cost in the X-Credits-Used header. To see what is left:
curl -H "Authorization: Bearer YOUR_API_KEY" "https://helpwithdocument.com/api/v1/usage"
# Answer:
# { "credits_included": 5000, "credits_used": 420, "credits_remaining": 4580, ... }You can also see it any time in the Business dashboard.
When something goes wrong
You get a short message instead of a file, always in the same form: {"error":{"code":"...","message":"..."}}. Failed requests are never charged.
| Message | What to do |
|---|---|
| The API key is missing or wrong | Check you copied the whole key, starting hwd_live_, and that it was not deleted in the dashboard. |
| Not enough credits | Top up or change plan in the Business dashboard. Nothing was charged for the failed request. |
| Wrong file type | Each tool takes certain files, for example Word to PDF takes .doc or .docx. The full list is in the reference. |
| File too large | One file can be up to 30 MB. For bigger or many files, use the send now, collect later way. |
| Could not be processed | The file may be damaged or password-protected. Open it on your computer to check. Nothing is charged. |
| Too many requests | Wait the number of seconds the message gives, then try again. |
