Skip to content

Examples: use the converters the API spec documents - #73

Merged
tomasr78 merged 1 commit into
mainfrom
examples-documented-converters
Nov 9, 2026
Merged

tomasr78 merged 1 commit into
mainfrom
examples-documented-converters

Conversation

@tomasr78

@tomasr78 tomasr78 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Three examples call converters that the production API spec (https://v2.convertapi.com/info/openapi, 332 paths on 2026-11-09) does not list. Developers copy these examples and the how-to guides on convertapi.com reuse them, so they should call documented converters. This is the PHP part of what ConvertAPI/convertapi-library-dotnet#86 does for .NET.

Example Before After
convert_url_to_pdf.php web -> pdf, comment links /web-to-pdf html -> pdf (parameters), same Url and FileName; comment links https://www.convertapi.com/html-to-pdf
conversions_chaining.php any -> zip file -> zip (parameters), same Files
error_handling.php docx -> svg, which the API rejects as an unsupported conversion pdf -> split with files/test.docx, which the API rejects because the file is not a PDF (the .NET ExceptionHandling example does the same)

https://www.convertapi.com/web-to-pdf is not in the site's sitemap; https://www.convertapi.com/html-to-pdf is. The other examples already call documented converters; the pdf -> extract step of create_pdf_thumbnail.php goes away with #72.

Verified against production (2026-11-09)

PHP 8.4.27 in Docker (php:8.4-cli): php -l passes for the three files. Each example ran with php <name>.php from examples/, once on main (8874aff) and once on this branch, with the token in CONVERT_API_SECRET and TMPDIR=/out.

conversions_chaining.php, same output before and after:

Converting PDF to JPG and compressing result files with ZIP
Conversions done. Cost: 1. Total files created: 6
Conversions done. Cost: 1. Total files created: 1
File saved to
Array
(
    [0] => /out/test.zip
)

Both runs saved a 775,249-byte test.zip with test.jpg to test-6.jpg; the JPGs are byte-identical before and after.

convert_url_to_pdf.php, same output before and after:

The web page PDF saved to
Array
(
    [0] => /out/web-example.pdf
)

The PDF text: on this branch the PDF is the article (3 pages, 1,925 words, title "Data conversion"). On main, Wikimedia answered ConvertAPI's renderer with its "Too many requests" page (1 page, 62 words); that rate limiting comes and goes for both converters and is being looked at separately.

error_handling.php, before:

Got API error code: 4000
Parameter validation error. Code: 4000 {"SourceFormat, DestinationFormat":["Unsupported conversion docx -> svg"]}

after:

Got API error code: 4000
Parameter validation error. Code: 4000 {"File":["File must be a file with one of the following extensions: .pdf."]}

Seen, not changed: the library itself sends url as the source format when the parameters have a Url and no source format is given (lib/ConvertApi/Task.php, DEFAULT_URL_FORMAT); url is not in the spec. The URL example passes its source format, so it does not depend on it.

Same change in the other SDKs

🤖 Generated with Claude Code

The production API spec (https://v2.convertapi.com/info/openapi) has no
web -> pdf, any -> zip or docx -> svg converter.

- convert_url_to_pdf.php converts the URL with html -> pdf (same Url and
  FileName parameters) and links the html-to-pdf page.
- conversions_chaining.php zips the JPG results with file -> zip.
- error_handling.php gets its API error from pdf -> split with a DOCX
  file (code 4000, the file must be a .pdf) instead of the unsupported
  docx -> svg conversion (also code 4000).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the PHP example updates aligning converter usage with the production API specification.

No open issues 🎉

What changed in this PR

Updates three PHP examples to use converters listed in the production API specification, without changing library behavior.

Changes:

  • Uses html -> pdf for URL conversion and updates the documentation link.
  • Uses file -> zip to archive chained conversion results.
  • Demonstrates error handling with a documented pdf -> split converter and an intentionally invalid DOCX input.
File Description
examples/​error_handling.php Triggers a file-validation error using PDF split with a DOCX input.
examples/​convert_url_to_pdf.php Sets the source format to html and links to HTML-to-PDF documentation.
examples/​conversions_chaining.php Sets the ZIP conversion source format to file.

Review effort: Balanced

@tomasr78
tomasr78 merged commit a9c3927 into main Nov 9, 2026
9 checks passed
@tomasr78
tomasr78 deleted the examples-documented-converters branch November 9, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants