---
title: Customizing requests from the Journey module in JavaScript
description: PingOne Advanced Identity Cloud PingAM JavaScript
component: orchsdks
page_id: orchsdks:journey:customization/requests/javascript-request-interceptors
canonical_url: https://developer.pingidentity.com/orchsdks/journey/customization/requests/javascript-request-interceptors.html
revdate: Fri, 24 Apr 2026 12:04:51 +0000
section_ids:
  step_1_creating_request_middleware_instances: Step 1. Creating request middleware instances
  examples: Examples
  step_2_configuring_the_journey_module_to_use_middleware: Step 2. Configuring the Journey module to use middleware
---

# Customizing requests from the Journey module in JavaScript

[icon: circle-check, set=far]PingOne Advanced Identity Cloud [icon: circle-check, set=far]PingAM [icon: js, set=fab]JavaScript

The Orchestration SDK for JavaScript supports the **RequestMiddleware** type for adding custom logic to network requests.

You can use this request middleware to modify requests before they're sent.

For example, you can add or customize:

* Query parameters

* Headers

* Body data

|   |                                                                                                                                                                                                                                                                      |
| - | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|   | You can add the commonly-used `forceAuth` and `noSession` query parameters when starting a journey, without creating middleware.Learn more in [Starting an authentication journey in JavaScript](../../usage/javascript/04-starting-an-authentication-journey.html). |

## Step 1. Creating request middleware instances

To customize network requests, create one or more `RequestMiddleware` instance:

Creating a RequestMiddleware instance in JavaScript

```javascript
const loggingMiddleware = (req, action, next) => {
  switch (action.type) {
    case 'JOURNEY_START':
      console.log(`Starting auth journey: ${req.url}`);
      break;
  }
  next();
}
```

Request middleware has the following inputs:

* *Request object*

  Represents the original request, and has information about the body, method type, parameters, and more.

* *Action object*

  Represents the type of operation the request performs. You can check `action.type` to only apply customizations to certain requests.

  Available action types are as follows:

  | Value               | Description                                    |
  | ------------------- | ---------------------------------------------- |
  | `JOURNEY_START`     | Initial call to an authentication tree         |
  | `JOURNEY_NEXT`      | Proceeding through an authentication tree flow |
  | `JOURNEY_TERMINATE` | Terminate a session                            |

* *Next method*

  Proceeds to the next middleware, if configured.

### Examples

To customize requests, create middleware that alters requests with your own values.

* Headers

* Query parameters

* Body data

Customizing headers using request middleware

```javascript
const customHeaderMiddleware = (req, action, next) => {
  req.headers.set('X-User-Agent', 'MyApp/1.0');
  next();
}
```

|   |                                                                                                                                                                                                                                                         |
| - | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|   | Update the **Accepted Headers (optional)** property in your CORS configuration to include any new headers you add in your middleware.Learn more in [Allow cross-domain requests with CORS](https://docs.pingidentity.com/pingoneaic/tenants/cors.html). |

Customizing query parameters using request middleware

```javascript
const customParamMiddleware = (req, action, next) => {
  req.url.searchParams.set('lang', 'en-UK');
  req.url.searchParams.set('brand', 'example.co.uk');
  next();
}
```

Customizing body data using request middleware

```javascript
const customJSONPost = (req, action, next) => {
  // Add JSON body data to a POST request
  req.body = (JSON.stringify({ name: 'Babs Jensen', "email": "babs@example.com" }));
  req.method = "POST";
  next();
}

const customJSONPut = (req, action, next) => {
  // Add JSON body data to a PUT request
  req.body = (JSON.stringify({ name: 'Updated Name', email: "updated@example.com" }));
  req.method = "PUT";
  next();
}

const customFormPost = (req, action, next) => {
  // Add form-encoded body data to a POST request
  const formData = new FormData();
  formData.append('name', 'Babs Jensen');
  formData.append('email', 'babs@example.com');

  req.body = formData;
  req.method = "POST";
  next();
}
```

## Step 2. Configuring the Journey module to use middleware

Pass the names of your custom middleware to the **Journey** module in the `requestMiddleware` parameter in the configuration:

Configuring the `journey` module

```javascript
const journeyClient = await journey({
  // Custom middleware
  requestMiddleware: [
    customHeaderMiddleware,
    customParamMiddleware,
    customFormPost
  ],
  // Other configuration
  config: {
    serverConfig: {
        wellknown: 'https://openam-forgerock-sdks.forgeblocks.com/am/oauth2/realms/alpha/.well-known/openid-configuration',
    },
  },
});
```
