# Generate Config Files using API and NMCTL

Power users may wish to bulk-create and manage WireGuard config files for their network. For this, we recommend using the API or NMCTL.

## Generating Clients via API

Static client configurations can be generated using the createExtClient endpoint of the netmaker API. Authorization to the API is required to access relevant endpoints.

{% stepper %}
{% step %}

### Authenticate and get a JWT

Generate and grab a JWT token from the authenticate API endpoint using the following curl command (<https://openapi.netmaker.io/#tag/authenticate/operation/authenticateUser>):

{% code title="Authenticate and get JWT" %}

```bash
curl -X POST --location 'https://api.netmaker.example.com/api/users/adm/authenticate' \
  --header 'Content-Type: application/json' \
  --data '{ "username":"<netmaker username>", "password":"<netmaker password>" }'
```

{% endcode %}

Copy the JWT token printed to the terminal to use for subsequent API requests.

![](/files/a19fa3d977ad49585cf4308a9beca1185269b140)
{% endstep %}

{% step %}

### Identify the Remote Access Gateway (Host Network ID)

The createExtClient endpoint requires the netmaker network name and the Remote Access Gateway’s Host Network ID (also referred to as Device Network ID). To get the Host Network ID, navigate to the netmaker network and click the host name to reveal the id.

![](https://docs.netmaker.io/Base64-Image-Removed)
{% endstep %}

{% step %}

### Create a static client via API

Use the extclients endpoint to generate a static client configuration. The endpoint documentation: <https://openapi.netmaker.io/#tag/ext\\_client/operation/createExtClient>

Replace , , and in the command below:

{% code title="Create static client" %}

```bash
curl -X POST -L "https://api.netmaker.example.com/api/extclients/<network name>/<host network id>" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <AuthToken>" \
  --data '{"clientid":"SiteC"}'
```

{% endcode %}

On successful execution, the POST request returns no body or error. To list all static client configurations for a network:

{% code title="List static clients" %}

```bash
curl -X GET -L "https://api.netmaker.example.com/api/extclients/<network name>" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <AuthToken>"
```

{% endcode %}

To retrieve the WireGuard config for a specific static client:

{% code title="Get WireGuard config for static client" %}

```bash
curl -X GET -L "https://api.netmaker.example.com/api/extclients/<network name>/<static client id>/file" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <AuthToken>"
```

{% endcode %}

The extclients API endpoint can be used to generate, delete, and remotely manage static client configurations in bulk and can be integrated into automation systems.
{% endstep %}
{% endstepper %}

***

## Create Clients via NMCTL

NMCTL is a CLI utility for interacting with the netmaker server. It authenticates and makes API calls to the netmaker server via a CLI.

### Setup NMCTL

{% stepper %}
{% step %}

1. Download the latest NMCTL tool from: <https://github.com/gravitl/netmaker/releases/latest>

Make sure to download the build that matches your CPU and OS architecture.
{% endstep %}

{% step %}
2\. Ensure the nmctl binary is executable (set executable permissions) after downloading.
{% endstep %}

{% step %}
3\. Authenticate and add the netmaker server to the CLI context.

Run the following to set a context (replace placeholders):

{% code title="Set context" %}

```bash
nmctl context set <context name> --endpoint=https://api.netmaker.example.com --username=<username> --password=<password>
```

{% endcode %}

Then use the context:

{% code title="Use context" %}

```bash
nmctl context use <context name>
```

{% endcode %}

The context name should be unique to identify and manage multiple netmaker servers via nmctl.
{% endstep %}
{% endstepper %}

### Create Client

{% stepper %}
{% step %}
Identify two pieces of information:

* The netmaker network name where the gateway resides and where static clients will be created.
* The Host Network ID of the Remote Access Gateway (Device Network ID). To obtain it, navigate to the netmaker network and click the host name to reveal the id.

![](/files/roWI0abVoU2MtJqNmCJj)
{% endstep %}

{% step %}
Generate a static client configuration:

{% code title="Create static client with nmctl" %}

```bash
nmctl ext_client create <network name> <host network id> --id <static client id>
```

{% endcode %}

The static client id must be unique to identify and manage different client configurations.
{% endstep %}

{% step %}
If the command responds with "Success", the static client was created successfully.
{% endstep %}
{% endstepper %}

### Get Client

Retrieve the static client configuration created above:

{% code title="Retrieve static client config" %}

```bash
nmctl ext_client config <network name> <static client id>
```

{% endcode %}

This will return the WireGuard configuration file for the static client, usable for setting up the WireGuard plugin on the device.

![](/files/6118a6a958c9948cb72ac3286fed3b9a178249e6)

### Other Options with NMCTL

NMCTL provides options to delete and update static clients. To view available ext\_client commands:

{% code title="nmctl ext\_client help" %}

```bash
nmctl ext_client --help
```

{% endcode %}

![](/files/98f961123bd7b13745807a701578b181a16b5cf9)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.netmaker.io/how-to-guides/generate-config-files-using-api-and-nmctl.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
