# getRecordingId

Canonical: <https://test-proxy-recorder.dev/docs/reference/api/functions/getrecordingid/>
Docs index: <https://test-proxy-recorder.dev/docs/> · All docs as one file: <https://test-proxy-recorder.dev/llms-full.txt>

---

> **getRecordingId**(`requestHeaders`): `string` \| `null`

Defined in: [nextjs/middleware.ts:81](https://github.com/asmyshlyaev177/test-proxy-recorder/blob/d1bacb3b39a3cf6f7f5a5391a8201868e4629861/packages/test-proxy-recorder/src/nextjs/middleware.ts#L81)

Get the recording ID from the request if present
Useful for manually adding the header to fetch requests in Next.js

## Parameters

### requestHeaders

`Headers` \| `NextJSRequest`

Next.js headers object or NextRequest from next/server

## Returns

`string` \| `null`

The recording ID if present, null otherwise

## Example

```ts
// In your API route or server component
import { getRecordingId } from 'test-proxy-recorder/nextjs';
import { headers } from 'next/headers';

export async function GET() {
  const recordingId = getRecordingId(headers());

  const response = await fetch('http://localhost:8100/api/data', {
    headers: {
      ...(recordingId && { 'x-test-rcrd-id': recordingId })
    }
  });

  return Response.json(await response.json());
}
```
