Getting started overview

This guide provides a structured approach to initiating your work with Api2Convert, focusing on the essential steps required to get your first file conversion operational. The process covers account creation, obtaining necessary API credentials, and executing a basic conversion request. Api2Convert specializes in automating various file format conversions, including documents, images, and archives, and offers an OCR API for text extraction from images.

The service offers a free tier with 50 conversions per month, allowing developers to test functionality before committing to a paid plan. Supported programming languages include PHP, Node.js, Python, .NET, Go, Ruby, and Java, with comprehensive documentation available for each.

Here's a quick reference table outlining the getting started process:

Step What to do Where
1. Create Account Register for a new Api2Convert account. Api2Convert Signup Page
2. Get API Key Locate and copy your unique API key from the dashboard. Api2Convert Dashboard
3. Prepare Environment Install a cURL client or an Api2Convert SDK for your chosen language. cURL Installation Guide or Api2Convert SDKs
4. Make Request Send a conversion request using your API key and a source file. Api2Convert Documentation Examples
5. Handle Response Process the API response to retrieve the converted file or status. Api2Convert Response Handling

Create an account and get keys

To begin using Api2Convert, you must first create an account. This process allows you to access the developer dashboard, where your unique API key is generated and managed.

  1. Sign Up: Navigate to the Api2Convert signup page. Provide the required information, typically an email address and a password, to create your account.
  2. Access Dashboard: Once registered and logged in, you will be redirected to your Api2Convert dashboard.
  3. Locate API Key: On the dashboard, your API key will be prominently displayed. This key is a unique string of characters that authenticates your requests to the Api2Convert API. It is crucial for securing your API calls and should be treated as a sensitive credential.
  4. Copy API Key: Copy your API key to a secure location. You will need to include this key in the header or parameters of every API request you make.

Api2Convert employs API keys for authentication. This method is a common practice for identifying the calling application or user and ensuring that only authorized entities can interact with the API. For example, similar authentication methods are used by services like Stripe for their API keys or Cloudflare for their API tokens. Always safeguard your API key to prevent unauthorized usage.

Your first request

After obtaining your API key, you can make your first conversion request. This example demonstrates converting a PDF file to a DOCX document using cURL. Api2Convert supports various input and output formats, which are detailed in their file format documentation.

Using cURL

The following cURL command illustrates a basic conversion request. Replace YOUR_API_KEY with your actual API key and ensure input.pdf is a valid path to your source file.

curl -X POST \
  "https://api2convert.com/v1/convert" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@/path/to/input.pdf" \
  -F "target_format=docx" \
  -o "output.docx"

In this command:

  • -X POST specifies the HTTP method.
  • "https://api2convert.com/v1/convert" is the API endpoint for conversions.
  • -H "Authorization: Bearer YOUR_API_KEY" includes your API key in the Authorization header, following the Bearer token scheme.
  • -F "file=@/path/to/input.pdf" uploads your input file. The @ prefix tells cURL to read the file from the specified path.
  • -F "target_format=docx" specifies the desired output format.
  • -o "output.docx" saves the API response (the converted file) to a local file named output.docx.

Using Node.js SDK

For Node.js developers, Api2Convert provides an official SDK. First, install the SDK:

npm install api2convert

Then, use the following code to perform a conversion:

const Api2Convert = require('api2convert');
const fs = require('fs');

const apiKey = 'YOUR_API_KEY';
const api2convert = new Api2Convert(apiKey);

async function convertFile() {
  try {
    const filePath = './input.pdf';
    const targetFormat = 'docx';

    // Assuming you have an 'input.pdf' file in the same directory
    const response = await api2convert.convert({
      file: fs.createReadStream(filePath),
      target_format: targetFormat,
    });

    if (response.status === 'success') {
      const downloadUrl = response.data.download_url;
      console.log('Conversion successful. Download URL:', downloadUrl);
      // You can then download the file from the downloadUrl
      // For example, using axios or another HTTP client
      // const axios = require('axios');
      // const writer = fs.createWriteStream('./output.docx');
      // const responseFile = await axios({ url: downloadUrl, method: 'GET', responseType: 'stream' });
      // responseFile.data.pipe(writer);
      // return new Promise((resolve, reject) => {
      //   writer.on('finish', resolve);
      //   writer.on('error', reject);
      // });

    } else {
      console.error('Conversion failed:', response.message);
    }
  } catch (error) {
    console.error('Error during conversion:', error.message);
  }
}

convertFile();

This Node.js example demonstrates instantiating the SDK with your API key, providing the input file as a readable stream, and specifying the target format. The API response will include a download URL for the converted file.

Using PHP SDK

For PHP developers, install the SDK via Composer:

composer require api2convert/api2convert-php

Then, use the following code:

<?php

require 'vendor/autoload.php';

use Api2Convert\Api2Convert;

$apiKey = 'YOUR_API_KEY';
$api2convert = new Api2Convert($apiKey);

try {
    $filePath = './input.pdf';
    $targetFormat = 'docx';

    $response = $api2convert->convert([
        'file' => fopen($filePath, 'r'), // Pass file resource
        'target_format' => $targetFormat,
    ]);

    if ($response['status'] === 'success') {
        $downloadUrl = $response['data']['download_url'];
        echo "Conversion successful. Download URL: " . $downloadUrl . "\n";
        // You can then download the file from the downloadUrl
        // For example, using file_get_contents or a Guzzle client
        // file_put_contents('output.docx', file_get_contents($downloadUrl));

    } else {
        echo "Conversion failed: " . $response['message'] . "\n";
    }
} catch (\Exception $e) {
    echo "Error during conversion: " . $e->getMessage() . "\n";
}

?>

This PHP example similarly initializes the Api2Convert client with your key, uses fopen to provide the input file, and retrieves the download URL from the successful response.

Common next steps

Once you have successfully performed your first conversion, consider these next steps to further integrate Api2Convert into your applications:

  • Explore More Formats: Review the Api2Convert documentation on supported formats to understand the full range of conversion possibilities, including image, audio, and video formats if applicable, beyond basic documents.
  • Advanced Conversion Options: Investigate advanced features such as specifying conversion quality, resolution, or other parameters relevant to specific file types. The API parameters section provides details.
  • Error Handling: Implement robust error handling in your application to gracefully manage failed conversions, API rate limits, or invalid inputs. The API responses include status codes and messages to help diagnose issues, as described in the Api2Convert error codes documentation.
  • Webhooks: For asynchronous conversions, explore using webhooks. This allows Api2Convert to notify your application when a conversion is complete, rather than requiring you to poll the API for status updates. This is a common pattern for long-running processes, as detailed in general webhook guides like Twilio's webhook usage documentation.
  • SDK Integration: If you used cURL for your first request, consider integrating one of the official Api2Convert SDKs (PHP, Node.js, Python, .NET, Go, Ruby, Java) for a more streamlined development experience.
  • Monitor Usage: Regularly check your API usage on the Api2Convert dashboard to stay within your plan limits and anticipate when an upgrade might be necessary.
  • Security Best Practices: Ensure your API key is stored securely and not exposed in client-side code or public repositories. Use environment variables or a secrets management service.

Troubleshooting the first call

Encountering issues during your initial API call is common. Here are some troubleshooting steps and common problems:

  • Invalid API Key: Double-check that you have copied your API key correctly from your Api2Convert dashboard. An incorrect key will result in an authentication error (e.g., HTTP 401 Unauthorized). The authorization header format is crucial; ensure it's Authorization: Bearer YOUR_API_KEY.
  • File Path Errors: Verify that the path to your input file (e.g., /path/to/input.pdf) is correct and that the file exists and is readable by the process making the API call. Incorrect file paths often lead to HTTP 400 Bad Request errors.
  • Unsupported Format: Ensure that both your input file's format and the specified target_format are supported by Api2Convert. Refer to the list of supported formats. Requesting an unsupported conversion will result in an error response.
  • Network Issues: Check your internet connection and any firewall settings that might be blocking outbound requests to api2convert.com.
  • Rate Limiting: If you are making many requests in a short period, you might hit API rate limits. Api2Convert's API documentation will specify these limits and the appropriate HTTP status codes (e.g., 429 Too Many Requests) to expect. Implement retry logic with exponential backoff if you anticipate hitting these limits, a common strategy for Google Cloud API requests.
  • Check API Response: Always inspect the full API response, including HTTP status codes and the JSON body. Api2Convert's API typically returns descriptive error messages in the JSON response body that can help pinpoint the exact issue, as detailed in their error handling guide.
  • Consult Documentation: If you're still stuck, refer to the comprehensive Api2Convert documentation. It provides detailed explanations of endpoints, parameters, and error codes.