# List email logs for a customer

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Eventually Consistent](/docs/api/read-consistency)

Retrieves the emails sent for a [customer](/docs/api/customers), newest first.

Use this operation to inspect delivery status, recipient, and template for emails Chargebee sent to a customer, including those triggered by [send invoice email](/docs/api/invoices#send_invoice_email), [send credit note email](/docs/api/credit_notes#send_credit_note_email), and [send payment request email](/docs/api/customers#send_payment_request_email).

### Prerequisites & Constraints

-   Email Engage V2 must be enabled for the site.

### Implementation Notes

-   Results are sorted by `sent_on` descending, so the most recent emails appear first.
-   If you omit `sent_on`, the response includes emails from the last 24 hours.
-   Any `sent_on` filter must fall within the last 7 days.
-   `sent_on[between]` and combined `sent_on[after]` / `sent_on[before]` can span at most 24 hours.
-   `sent_on[after]` alone returns the following 24 hours from that timestamp.
-   `sent_on[before]` alone returns the preceding 24 hours from that timestamp.
-   Pass `business_entity_id` only when Multi Business Entity is enabled. Pass `brand_id` only when Multi Brand is enabled. Otherwise the API returns an `invalid_request` error.

## Sample Request

#### Chargebee CLI

```bash
chargebee email-log email-logs-for-customer __test__8aswXTV3cHBBk \
    -d limit=2
```

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/customers/__test__8aswXTV3cHBBk/email_logs \
     -G  \
     -u {site_api_key}:\
     --data-urlencode limit=2
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
ListResult result = EmailLog.EmailLogsForCustomer("__test__8aswXTV3cHBBk")
		.Limit(2)
		.Request();

foreach (var listItem in result.List){
  EmailLog emailLog = listItem.EmailLog;
}
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    emaillogAction "github.com/chargebee/chargebee-go/v3/actions/emaillog"
    "github.com/chargebee/chargebee-go/v3/models/emaillog"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := emaillogAction.EmailLogsForCustomer("__test__8aswXTV3cHBBk", &emaillog.EmailLogsForCustomerRequestParams{
        Limit : chargebee.Int32(2),
    }).ListRequest()
    if err != nil {
        fmt.Println(err)
    } else {
        for idx := 0; idx < len(res.List); idx++ {
            EmailLog := res.List[idx].EmailLog
        }
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.EmailLogEmailLogsForCustomerRequest{
    Limit : chargebee.Int32(2),
}
  res, err := client.EmailLog.EmailLogsForCustomer("__test__8aswXTV3cHBBk", req)
      if err != nil {
        fmt.Println(err)
    } else {
        for idx := 0; idx < len(res.List); idx++ {
            EmailLog := res.List[idx].EmailLog
        }
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;
import java.util.List;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        ListResult result = EmailLog.emailLogsForCustomer("__test__8aswXTV3cHBBk")
            .limit(2)
            .request();

        for (ListResult.Entry entry : result) {
            EmailLog emailLog = entry.emailLog();
        }
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.emailLog.EmailLog;
import com.chargebee.v4.models.emailLog.params.EmailLogsForCustomerParams;
import com.chargebee.v4.models.emailLog.responses.EmailLogsForCustomerResponse;
import java.util.List;

public class EmailLogsForCustomer {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        EmailLogsForCustomerParams params = EmailLogsForCustomerParams.builder()
            .limit(2)
            .build();

        EmailLogsForCustomerResponse response = client
            .emailLogs()
            .emailLogsForCustomer("__test__8aswXTV3cHBBk", params);
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.emailLog.emailLogsForCustomer("__test__8aswXTV3cHBBk", {
        limit: 2
    });
    result.list.forEach((entry) => {
        console.log(entry);
        const emailLog = entry.email_log;
    });
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->emailLog()->emailLogsForCustomer("__test__8aswXTV3cHBBk", [
    "limit" => 2
]);
foreach($result->list as $entry) {
    $emailLog = $entry->email_log;
}
```

#### Python

```python
from chargebee import Chargebee, Filters

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
entries = cb_client.EmailLog.email_logs_for_customer("__test__8aswXTV3cHBBk",
    cb_client.EmailLog.EmailLogsForCustomerParams(
        limit=2
    )
)
for entry in entries.list:
    email_log = entry.email_log
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

list = ChargeBee::EmailLog.email_logs_for_customer("__test__8aswXTV3cHBBk",{
  :limit => 2
})

list.each do |entry|
  email_log = entry.email_log
end
```

## Sample Response

```json
{
  "list": [
    {
      "email_log": {
        "id": "__test__8asukSOX7flkT",
        "object": "email_log",
        "template_name": "Send Invoice Email",
        "from_address": "billing@acmeinc.com",
        "to_address": "john@user.com",
        "subject": "Invoice from Acme Inc.",
        "status": "succeeded",
        "sent_on": 1517505963,
        "customer_id": "__test__8aswXTV3cHBBk",
        "site_id": "cb_site___test__KyVnHhSBWm4Rv2rk"
      }
    },
    {..}
  ]
}
```

## URL Format

**GET** https://[site].chargebee.com/api/v2/customers/{customer-id}/email_logs

## Input Parameters

- `limit` (optional, integer, default=10, min=1, max=100)
  The number of resources to be returned.

- `offset` (optional, string, max chars=1000)
  Determines your position in the list for pagination. To ensure that the next page is retrieved correctly, always set `offset` to the value of `next_offset` obtained in the previous iteration of the API call.

## Returns

- `next_offset` (optional, string, max chars=1000)
  This attribute is returned only if more resources are present. To fetch the next set of resources use this value for the input parameter `offset`.

- `email_log` (Email log object)
  Resource object representing email log
