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

# nsc ingress generate-access-token

Generate a scoped access token that can be used to access a preview programmatically.

`ingress generate-access-token` generates an access token. Using this token, you can access your Namespace previews programmatically.
By default, the token is scoped to the entire workspace. You can restrict the token to only grant access to a single instance though.

## Usage

```bash theme={null}
nsc ingress generate-access-token [--instance <instance-id>]
```

### Example

The following example starts a new ephemeral environment, running nginx. The `nginx`
container image has nginx, an http reverse proxy, listening on port 80. We
export that port to a public endpoint, using `-p 80`.

Then, we generate an access token and query the exposed application with `curl`.

<Steps titleSize="h4">
  <Step title="Start nginx">
    Start nginx and expose port 80 through a public endpoint:

    ```bash theme={null}
    nsc run --image nginx -p 80
    ```

    ```text nocopy Output theme={null}
    Created new ephemeral environment! (id: 85a32emcg99ii).
    More at: https://cloud.namespace.so/01gr490qvbntkjn9jwypnd4g04/instance/85a32emcg99ii
    Running "nginx-t082s"
      Exported 80/tcp as https://4bi2reg-85a32emcg99ii.fra1.namespaced.app
    ```
  </Step>

  <Step title="Generate an access token">
    Generate an access token for the instance:

    ```bash theme={null}
    export TOKEN=`nsc ingress generate-access-token --instance=85a32emcg99ii`
    ```
  </Step>

  <Step title="Query the application">
    Query the exposed application using the access token:

    ```bash theme={null}
    curl -H "x-nsc-ingress-auth: Bearer $TOKEN" 'https://4bi2reg-85a32emcg99ii.fra1.namespaced.app'
    ```

    ```text nocopy Output theme={null}
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    ...
    ```
  </Step>
</Steps>

## Options

<h3 id="--instance-instance-id">
  \--instance \<instance-id>
</h3>

If set, the generated access token will be limited to this instance.

<h3 id="--output_to-path">
  \--output\_to \<path>
</h3>

Write the generated access token to this path. If file already exists, it will get overwritten.
