---
source: https://carbone.io/documentation/developer/api-sdks/php.html
title: "Generate documents and reports with PHP SDK"
description: "Generate report with PHP"
generated_at: "2026-07-13"
---

# PHP SDK

Generate report with PHP

PHP SDK to generate documents (PDF DOCX ODT XLSX ODS XML ...) through the Carbone Cloud API

The source code is available on Github: [https://github.com/carboneio/carbone-sdk-php](https://github.com/carboneio/carbone-sdk-php)

## Install

```bash
composer require carboneio/carbone-sdk-php
```

## Constructor

Start creating a new instance of the Carbone class and provide your private API key. Get your API key on your Carbone account: [https://account.carbone.io/](https://account.carbone.io/).

```php
use Carboneio\SDK\Carbone;

$carbone = new Carbone('YOUR_API_KEY');
```

To use this SDK with Carbone on premise :

```php
use Carboneio\SDK\Carbone;

$carbone = new Carbone('YOUR_API_KEY', 'https://your_carbone_URL');
```

## Generate a report

You can generate a document using the `render` method. This method takes the `template Id` and the data as parameters. A `render ID` is returned and must be used to download the generated document.

```php
$response = $carbone->renders()->render($templateId, $data);

$renderId = $response->getRenderId();
```

Example to [render a template](https://github.com/carboneio/carbone-sdk-php/blob/7d3937839eb9aef035d7cbc0677d1cef32f2b696/examples/render_report.php)

## Upload a template

You can upload a template to Carbone using the `upload` method. This method takes the content of the template as base64. The method returns a `template ID` used to render a template.

```php
$response = $carbone->templates()->upload($contentBase64);

$templateId = $response->getTemplateId();
```

Example to [upload a template](https://github.com/carboneio/carbone-sdk-php/blob/7d3937839eb9aef035d7cbc0677d1cef32f2b696/examples/upload_template.php)

## Download reports

You can download a rendered template using the `download` method. This method takes the `render ID` as a parameter.

```php
$response = $carbone->renders()->download($renderId);

// Save the contents of the file yourself on your filesystem
$content = $response->getContent();
```

Example to [download a rendered document](https://github.com/carboneio/carbone-sdk-php/blob/7d3937839eb9aef035d7cbc0677d1cef32f2b696/examples/download_report.php)

## Delete a template

You can delete a template using the `delete` method. This method takes the `template Id` as a parameter.

```php
$response = $carbone->templates()->delete($templateId);
```

Example to [delete a template](https://github.com/carboneio/carbone-sdk-php/blob/7d3937839eb9aef035d7cbc0677d1cef32f2b696/examples/delete_template.php)

## Download a template

You can download a template using the `download` method. This method takes the `template Id` as a parameter.

```php
$response = $carbone->templates()->download($templateId);
```

Example to [download a template](https://github.com/carboneio/carbone-sdk-php/blob/7d3937839eb9aef035d7cbc0677d1cef32f2b696/examples/download_template.php)

## Add custom headers

Set custom headers, such as "carbone-version" to select a specific [Carbone version](/documentation/developer/http-api/introduction.md#api-version). By default, the SDK requests version 4 of Carbone.

```php
$carbone->setHeaders([
  "carbone-version" => 4,
  /** Uncomment to delete automatically templates after a specific time */
  // "carbone-template-delete-after" => 86400 // 86400s = 1 day
]);
```

## Get API Status

```php
$response = $carbone->getStatus();
$json = $response->json();

echo "Status : " . $response->status() . "\n";
echo "Success: " . $json['success'] . "\n";
echo "Version: " . $json['version'] . "\n";
echo "Message: " . $json['message'] . "\n";
```

## Related topics

- [Rust SDK](/documentation/developer/api-sdks/rust.md)
- [Python SDK](/documentation/developer/api-sdks/python.md)
- [NodeJS SDK](/documentation/developer/api-sdks/nodejs.md)
- [Javascript SDK](/documentation/developer/api-sdks/javascript.md)
- [Java SDK](/documentation/developer/api-sdks/java.md)
- [Go SDK](/documentation/developer/api-sdks/go.md)
