# Payloads

A `Payload` represents an attempt by EasyPost to send an `Event` to a `Webhook`.
An `Event` can have multiple `Payloads`.
For instance, if there is a failure to deliver a `Webhook`, an `Event` would have multiple payloads, one for each attempt to deliver the `Event` to the `Webhook`.
`Payload` can be useful for debugging webhook delivery and when initially setting up EasyPost webhooks.

---

## Payload object

| Property | Type | Description |
|----------|------|-------------|
| object | string | "Payload" |
| mode | string | "test" or "production" |
| request_url | string | The URL that the request was sent to (the Webhook URL) |
| request_body | string | The body included in the request to the configured Webhook |
| request_headers | object | The headers included in the request to the configured Webhook |
| response_code | int | The status code returned by the webhook server |
| response_body | string | The body returned by the webhook server |
| response_headers | object | The headers returned by the webhook server |
| total_time | int | How long the request to the configured Webhook took to complete |
| created_at | datetime | When the Payload was created |
| updated_at | datetime | When the Payload was last updated |

Example Object:

```json
{
  "payloads": [
    {
      "id": "payload_734d47163d0711ecb29421da38a2f124",
      "object": "Payload",
      "created_at": "2021-11-04T00:37:55Z",
      "updated_at": "2021-11-04T01:14:18Z",
      "request_url": "https://api.example.com/webhook",
      "request_headers": {
        "Accept": "application/json",
        "Content-Type": "application/json",
        "User-Agent": "Go-http-client/1.1"
      },
      "request_body": "{\"key\":\"value\"}",
      "response_code": 200,
      "response_headers": {
        "Content-Type": "application/json; charset=utf-8",
        "Date": "Tue, 02 Nov 2021 23:37:55 GMT",
        "Server": "nginx/1.19.6",
        "X-Content-Type-Options": "nosniff",
        "X-Frame-Options": "SAMEORIGIN",
        "X-Request-Id": "a1b2c3d4e5f6g7h8i9j0",
        "X-Runtime": "0.001000",
        "X-Xss-Protection": "1; mode=block"
      },
      "total_time": 34
    },
    {
      "id": "payload_734d47163d0711ecb29421da38a2f414",
      "object": "Payload",
      "created_at": "2021-11-04T00:37:55Z",
      "updated_at": "2021-11-04T01:14:18Z",
      "request_url": "https://api.example.com/webhook",
      "request_headers": {
        "Accept": "application/json",
        "Content-Type": "application/json",
        "User-Agent": "Go-http-client/1.1"
      },
      "request_body": "{\"key\":\"value\"}",
      "response_code": 404,
      "response_headers": {
        "Content-Type": "application/json; charset=utf-8",
        "Date": "Tue, 02 Nov 2021 23:37:55 GMT",
        "Server": "nginx/1.19.6",
        "X-Content-Type-Options": "nosniff",
        "X-Frame-Options": "SAMEORIGIN",
        "X-Request-Id": "a1b2c3d4e5f6g7h8i9j0",
        "X-Runtime": "0.001000",
        "X-Xss-Protection": "1; mode=block"
      },
      "total_time": 122
    }
  ]
}
```

---

## Retrieve all Payloads

### Example: GET /events/:event_id/payloads

#### cURL

```shell
curl -X GET https://api.easypost.com/v2/events/evt_.../payloads/payload_... \
  -u "EASYPOST_API_KEY":
```

#### Go

```go
package example

import (
	"fmt"

	"github.com/EasyPost/easypost-go/v5"
)

func retrieve() {
	client := easypost.New("EASYPOST_API_KEY")

	payload, _ := client.GetEventPayload("evt_...", "payload_...")

	fmt.Println(payload)
}
```

#### Java

```java
package events;

import com.easypost.exception.EasyPostException;
import com.easypost.model.Payload;
import com.easypost.service.EasyPostClient;

public class RetrievePayload {
    public static void main(String[] args) throws EasyPostException {
        EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

        Payload payload = client.event.retrievePayload("evt_...", "payload_...");

        System.out.println(payload);
    }
}
```

#### C#

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost;
using Newtonsoft.Json;

namespace EasyPostExamples
{
    public class Examples
    {
        public static async Task Main()
        {
            var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY"));

            EasyPost.Models.API.Payload payload = await client.Event.RetrievePayload("evt_...", "payload_...");

            Console.WriteLine(JsonConvert.SerializeObject(payload, Formatting.Indented));
        }
    }
}
```

#### Node.js

```javascript
const EasyPostClient = require('@easypost/api');

const client = new EasyPostClient('EASYPOST_API_KEY');

(async () => {
  const payload = await client.Event.retrievePayload('evt_...', 'payload_...');

  console.log(payload);
})();
```

#### PHP

```php
<?php

$client = new \EasyPost\EasyPostClient('EASYPOST_API_KEY');

$payload = $client->event->retrievePayload('evt_...', 'payload_...');

echo $payload;
```

#### Python

```python
import easypost

client = easypost.EasyPostClient("EASYPOST_API_KEY")

payload = client.event.retrieve_payload("evt_...", "payload_...")

print(payload)
```

#### Ruby

```ruby
require 'easypost'

client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY')

payload = client.event.retrieve_payload('evt_...', 'payload_...')

puts payload
```

Retrieve all `Payloads` by `Event` ID.

---

## Retrieve a Payload

### Example: GET /events/:event_id/payloads/:payload_id

#### cURL

```shell
curl -X GET https://api.easypost.com/v2/events/evt_.../payloads/payload_... \
  -u "EASYPOST_API_KEY":
```

#### Go

```go
package example

import (
	"fmt"

	"github.com/EasyPost/easypost-go/v5"
)

func retrieve() {
	client := easypost.New("EASYPOST_API_KEY")

	payload, _ := client.GetEventPayload("evt_...", "payload_...")

	fmt.Println(payload)
}
```

#### Java

```java
package events;

import com.easypost.exception.EasyPostException;
import com.easypost.model.Payload;
import com.easypost.service.EasyPostClient;

public class RetrievePayload {
    public static void main(String[] args) throws EasyPostException {
        EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY");

        Payload payload = client.event.retrievePayload("evt_...", "payload_...");

        System.out.println(payload);
    }
}
```

#### C#

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyPost;
using Newtonsoft.Json;

namespace EasyPostExamples
{
    public class Examples
    {
        public static async Task Main()
        {
            var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY"));

            EasyPost.Models.API.Payload payload = await client.Event.RetrievePayload("evt_...", "payload_...");

            Console.WriteLine(JsonConvert.SerializeObject(payload, Formatting.Indented));
        }
    }
}
```

#### Node.js

```javascript
const EasyPostClient = require('@easypost/api');

const client = new EasyPostClient('EASYPOST_API_KEY');

(async () => {
  const payload = await client.Event.retrievePayload('evt_...', 'payload_...');

  console.log(payload);
})();
```

#### PHP

```php
<?php

$client = new \EasyPost\EasyPostClient('EASYPOST_API_KEY');

$payload = $client->event->retrievePayload('evt_...', 'payload_...');

echo $payload;
```

#### Python

```python
import easypost

client = easypost.EasyPostClient("EASYPOST_API_KEY")

payload = client.event.retrieve_payload("evt_...", "payload_...")

print(payload)
```

#### Ruby

```ruby
require 'easypost'

client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY')

payload = client.event.retrieve_payload('evt_...', 'payload_...')

puts payload
```

A `Payload` must be retrieved with both an `Event` ID and `Payload` ID.