> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Copying Value Coming in Body to Header Field

> Retrieving access_token value from request body with Groovy script and adding it to Authorization header as Bearer token

## Groovy Script

```groovy theme={null}
import java.lang.String

int start=requestBodyTextFromClient.indexOf("access_token")+16
int end=requestBodyTextFromClient.indexOf("\"",start+1)
String token=requestBodyTextFromClient.substring(start,end)
requestHeaderMapToTargetAPI.put("Authorization", "Bearer " + token)
```

## Explanation

This script performs the following operations:

1. **Finding Token**: Finds the `access_token` field from request body
2. **Extracting Token**: Extracts the token value
3. **Adding Header**: Adds it to Authorization header as Bearer token

<Note>
  This script should be run on the request line (Request Policy) because it uses the `requestBodyTextFromClient` and `requestHeaderMapToTargetAPI` variables.
</Note>
