← Back to documentation

Sending Data to an Endpoint

Copy-pasteable examples for every common language and CI workflow to POST data to a PayloadRelay relay URL.

10 min read

A PayloadRelay endpoint is a public HTTPS URL that accepts HTTP requests and forwards them to your configured targets. This guide shows how to send data from any language or environment.

Endpoint URL format

Code Example
https://<api-host>/relay/<endpoint-id>

The exact URL is shown on your endpoint's edit page. Copy it from there.

Authentication

Each endpoint can be configured with one of the following inbound auth modes:

Auth typeHeader added
NONENo auth header required
BASICAuthorization: Basic <base64(USERNAME:PASSWORD)>
BEARERAuthorization: Bearer YOUR_TOKEN
API_KEY<configured-header-name>: YOUR_API_KEY

If the endpoint also requires specific headers, include those in every request as well.


curl

No auth

Code Example
curl -X POST \
  'https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID' \
  -H 'Content-Type: application/json' \
  -d '{"event":"test","timestamp":"2024-01-01T00:00:00Z","data":{"id":123}}'

Bearer auth

Code Example
curl -X POST \
  'https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -d '{"event":"test","timestamp":"2024-01-01T00:00:00Z","data":{"id":123}}'

With a required header

Code Example
curl -X POST \
  'https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'X-Tenant-Id: acme-corp' \
  -d '{"event":"test","timestamp":"2024-01-01T00:00:00Z","data":{"id":123}}'

Form-urlencoded

Code Example
curl -X POST \
  'https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'event=test&id=123'

Multipart form data

Code Example
curl -X POST \
  'https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID' \
  -F 'event=test' \
  -F 'file=@/path/to/file.pdf'

Node.js (fetch)

No auth

Code Example
const response = await fetch('https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ event: 'test', timestamp: '2024-01-01T00:00:00Z', data: { id: 123 } }),
});
const result = await response.json();
console.log(result);

Bearer auth

Code Example
const response = await fetch('https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_TOKEN',
  },
  body: JSON.stringify({ event: 'test', timestamp: '2024-01-01T00:00:00Z', data: { id: 123 } }),
});

With a required header

Code Example
const response = await fetch('https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_TOKEN',
    'X-Tenant-Id': 'acme-corp',
  },
  body: JSON.stringify({ event: 'test', timestamp: '2024-01-01T00:00:00Z', data: { id: 123 } }),
});

Python (requests)

No auth

Code Example
import requests

response = requests.post(
    'https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID',
    json={'event': 'test', 'timestamp': '2024-01-01T00:00:00Z', 'data': {'id': 123}},
)
print(response.status_code, response.json())

Bearer auth

Code Example
import requests

headers = {
    'Authorization': 'Bearer YOUR_TOKEN',
}
response = requests.post(
    'https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID',
    json={'event': 'test', 'timestamp': '2024-01-01T00:00:00Z', 'data': {'id': 123}},
    headers=headers,
)

With a required header

Code Example
headers = {
    'Authorization': 'Bearer YOUR_TOKEN',
    'X-Tenant-Id': 'acme-corp',
}
response = requests.post(url, json=payload, headers=headers)

Go (net/http)

No auth

Code Example
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    payload := map[string]interface{}{
        "event":     "test",
        "timestamp": "2024-01-01T00:00:00Z",
        "data":      map[string]int{"id": 123},
    }
    body, _ := json.Marshal(payload)

    req, _ := http.NewRequest("POST", "https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID", bytes.NewBuffer(body))
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    fmt.Println("Status:", resp.Status)
}

Bearer auth

Code Example
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")

With a required header

Code Example
req.Header.Set("X-Tenant-Id", "acme-corp")

PHP (curl)

No auth

Code Example
<?php
$ch = curl_init('https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'event' => 'test',
    'timestamp' => '2024-01-01T00:00:00Z',
    'data' => ['id' => 123],
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
curl_close($ch);
echo $response;

Bearer auth

Code Example
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer YOUR_TOKEN',
]);

With a required header

Code Example
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer YOUR_TOKEN',
    'X-Tenant-Id: acme-corp',
]);

Ruby (Net::HTTP)

No auth

Code Example
require 'net/http'
require 'uri'
require 'json'

uri = URI('https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri.path)
request['Content-Type'] = 'application/json'
request.body = { event: 'test', timestamp: '2024-01-01T00:00:00Z', data: { id: 123 } }.to_json

response = http.request(request)
puts "Status: #{response.code}"
puts response.body

Bearer auth

Code Example
request['Authorization'] = 'Bearer YOUR_TOKEN'

With a required header

Code Example
request['X-Tenant-Id'] = 'acme-corp'

C# (HttpClient)

No auth

Code Example
using System.Net.Http;
using System.Net.Http.Json;

var client = new HttpClient();
var payload = new { @event = "test", timestamp = "2024-01-01T00:00:00Z", data = new { id = 123 } };
var response = await client.PostAsJsonAsync("https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID", payload);
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status: {(int)response.StatusCode}");
Console.WriteLine(body);

Bearer auth

Code Example
client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_TOKEN");

With a required header

Code Example
client.DefaultRequestHeaders.Add("X-Tenant-Id", "acme-corp");

Java (HttpClient — Java 11+)

No auth

Code Example
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String body = "{\"event\":\"test\",\"timestamp\":\"2024-01-01T00:00:00Z\",\"data\":{\"id\":123}}";

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID"))
            .POST(HttpRequest.BodyPublishers.ofString(body))
            .header("Content-Type", "application/json")
            .build();

        var client = HttpClient.newHttpClient();
        var response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println("Status: " + response.statusCode());
        System.out.println(response.body());
    }
}

Bearer auth

Code Example
.header("Authorization", "Bearer YOUR_TOKEN")

With a required header

Code Example
.header("X-Tenant-Id", "acme-corp")

GitHub Actions

Use this to fire an event from a GitHub Actions workflow, for example after a deployment.

No auth

Code Example
- name: Send event to PayloadRelay
  run: |
    curl -X POST \
      'https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID' \
      -H 'Content-Type: application/json' \
      -d '{"event":"deploy","ref":"${{ github.ref }}","sha":"${{ github.sha }}"}'

Bearer auth

Code Example
- name: Send event to PayloadRelay
  env:
    RELAY_TOKEN: ${{ secrets.RELAY_TOKEN }}
  run: |
    curl -X POST \
      'https://api.payloadrelay.com/relay/YOUR_ENDPOINT_ID' \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $RELAY_TOKEN" \
      -d '{"event":"deploy","ref":"${{ github.ref }}","sha":"${{ github.sha }}"}'

Store your token as a GitHub Actions secret — never hard-code it in the workflow file.

With a required header

Code Example
-H 'X-Tenant-Id: acme-corp' \

Live code samples in the app

When you open an endpoint's edit page in the PayloadRelay dashboard, a "Send to this endpoint — code samples" panel appears directly on the page. It:

  • Pre-fills the real relay URL.
  • Pre-fills auth headers based on the endpoint's configured auth type.
  • Includes any required headers you've defined.
  • Updates live as you change auth type or required headers in the editor.
  • Has a one-click Copy button on each tab.

Next steps