> ## Documentation Index
> Fetch the complete documentation index at: https://docs.slm.m1amdocs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AutoBill.fetchInvoice

The `fetchInvoice` method generates and returns an Invoice, for the given `invoiceId`, as plain text or as a PDF. (It does not fetch a previously sent Invoice.)

## Input

*srd*: sparse response description, a SOAP string (which must be a JSON object), in which you specify the elements you want returned.This parameter enables the calling system to constrain a `method` call to return only components you specify. This gives you greater control over returned content, and improves response time within the Vindicia platform by reducing the processing needed for the call.

Some fields are required, either practically or in the WSDL, and will be returned regardless of the *srd*. A null *srd* returns the complete response.

*autobill*: the `AutoBill` for the requested invoice.

*invoiceId*: the ID of the invoice.

*asPDF*: a Boolean flag, which, if set to `true`, returns the object as a PDF. Default is `false`.

*statementTemplateId*: the Merchant Identifier for a pre-defined statement template. If `null`, the template defined by the `AutoBill` will be used. (Note that use of the forward slash character (/) in merchant identifiers is not allowed. See [Merchant Identifiers](Merchant_Identifiers) for more information.)

*dunningIndex*: the index number of the requested invoice. (If the invoice was the first issued to the customer, its `dunningIndex` is 0.)

For more information, see Working with Invoices in the Subscribe Programming Guide.

*language*: the language of the invoice.

## Output

*return*: an object of type `Return` that indicates the success or failure of the call.

*invoice*: the specified invoice, rendered as a PDF or as plain text. This field encodes both plain text and PDF as xsd:base64Binary.

## Returns

In addition to those listed in [The Return Object](The_Return_Object), this call returns:

| Return Code | Return String |
| - | - |
| `400` | One of the following: - `Unable to load AutoBill: No match.` - `Unable to load TransactionBilling: *error-description*.` - `Unable to load AutoBill: *error-description*.` - `Unable to load StatementTemplate: *error-description*.` - `Failed to render invoice: *error-description*.` |

## Example

```

$autobill = new AutoBill();
$autobill->set($abID); // for some $abID
$response = $autobill->fetchInvoice(
   'inv-bac',
   true, // PDF, please
   null,
   0,
   'de-AT' // German in Austria
);
if ($response['returnCode'] == 200) {
   $pdf = $response['data']->invoice;
}
```

**Parent topic:**[AutoBill Methods](../topics/AutoBill_Methods)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.