# Change primary domains and manage SFTP access with Kinsta API

**URL:** https://community.kinsta.com/t/change-primary-domains-and-manage-sftp-access-with-kinsta-api/5209
**Category:** News and Announcements
**Created:** [June 24, 2025, 4:30pm UTC](https://community.kinsta.com/t/change-primary-domains-and-manage-sftp-access-with-kinsta-api/5209 "2025-06-24T16:30:46Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jeff](https://sea2.discourse-cdn.com/flex020/user_avatar/community.kinsta.com/jeff/32/16_2.png) [@jeff](https://community.kinsta.com/u/jeff)
#### Post date: [June 24, 2025, 4:30pm UTC](https://community.kinsta.com/t/change-primary-domains-and-manage-sftp-access-with-kinsta-api/5209/1 "2025-06-24T16:30:46Z")

</div>

We’ve expanded the [Kinsta API](https://kinsta.com/docs/kinsta-api/)&nbsp;with new domain and user management capabilities, giving teams even more control over their environments, without needing to log in to [MyKinsta](https://kinsta.com/mykinsta/).

With these updates, you can now programmatically change the primary domain of a WordPress environment and fully manage additional SFTP accounts via the Kinsta API.

### Info

You need a valid API key to use Kinsta API endpoints. You can [create or manage your API keys](https://kinsta.com/blog/kinsta-api-key/)&nbsp;in MyKinsta.

## Change the primary domain of an environment

Previously, the Kinsta API allowed you to [add](https://api-docs.kinsta.com/tag/WordPress-Site-Domains#operation/addSiteDomain)&nbsp;or [remove domains](https://api-docs.kinsta.com/tag/WordPress-Site-Domains#operation/deleteSiteDomain)&nbsp;from your site, which was great for setup and cleanup. But you couldn’t change which domain was set as primary for an environment.

With this new release, you can now set an existing domain as the [new primary domain](https://api-docs.kinsta.com/tag/WordPress-Site-Domains#operation/changePrimaryDomain)&nbsp;for a specific environment using the following endpoint:

```
PUT /sites/environments/{env_id}/change-primary-domain
```

To use the endpoint, you need the `domain_id`&nbsp;of the domain you want to set as primary. This must be one of the domains already associated with the environment.

You can find the `domain_id`&nbsp;using the `Get Site by ID`&nbsp;or `Get Site Environments`&nbsp;endpoints. It looks something like this in the response:

```
"domains": [
  {
    "id": "54fb80af-576c-4fdc-ba4f-b596c83f15a1",
    "name": "example.com",
    "type": "live"
  }
]
```

You also need to set the `run_search_and_replace`&nbsp;field. When set to `true`, it triggers a search and replace across the site’s database to update URLs referencing the domain.

### Info

If you’ve used the [Search and Replace tool](https://kinsta.com/docs/wordpress-hosting/mykinsta-tools/mykinsta-search-replace-tool/)&nbsp;in MyKinsta, this is the same concept. The API just lets you automate it.

Here’s an example using `curl`:

```
curl -i -X PUT \
  'https://api.kinsta.com/v2/sites/environments/{env_id}/change-primary-domain' \
  -H 'Authorization: Bearer ' \
  -H 'Content-Type: application/json' \
  -d '{
    "domain_id": "your-domain-id",
    "run_search_and_replace": true
  }'
```

## Full support for managing additional SFTP accounts

In April, we added the [ability to create and manage multiple SFTP user](https://kinsta.com/changelog/additional-sftp-users/)&nbsp;accounts directly in the MyKinsta dashboard. Now, you can do all of that using the Kinsta API.

This gives you full programmatic control over additional SFTP users in each environment. You can enable access, add new users, list existing ones, or remove them entirely.

### Enable or disable access

Before adding any users, additional SFTP access must be enabled for the environment. You can do that with:

```
PUT /sites/environments/{env_id}/additional-sftp-accounts/toggle-status
```

Here’s an example using `curl`:

```
curl -i -X PUT \
  'https://api.kinsta.com/v2/sites/environments/{env_id}/additional-sftp-accounts/toggle-status' \
  -H 'Authorization: Bearer ' \
  -H 'Content-Type: application/json' \
  -d '{
    "enabled": true
  }'
```

This can be reversed at any time by setting `"enabled": false`.

### Add a new SFTP user

Once enabled, you can&nbsp;[add users](https://api-docs.kinsta.com/tag/Additional-SFTP-Users#operation/addAdditionalSftpAccount)&nbsp;with this endpoint:

```
POST /sites/environments/{env_id}/additional-sftp-accounts
```

The request lets you define a username, secure password (minimum 16 characters), root directory, and permission level (`read`&nbsp;or `write`).

```
curl -i -X POST \
  'https://api.kinsta.com/v2/sites/environments/{env_id}/additional-sftp-accounts' \
  -H 'Authorization: Bearer ' \
  -H 'Content-Type: application/json' \
  -d '{
    "username": "dev-user",
    "password": "R8zXwT@#bV!kJq9^",
    "root_directory": "/wp-content/themes",
    "permission": "write"
  }'
```

This mirrors the same controls you’d find in MyKinsta, including the ability to restrict access to specific directories or assign read-only permissions.

### List and remove users

You can [retrieve a list of additional SFTP accounts](https://api-docs.kinsta.com/tag/Additional-SFTP-Users#operation/getAdditionalSftpAccounts)&nbsp;like this:

```
GET /sites/environments/{env_id}/additional-sftp-accounts
```

To [delete one](https://api-docs.kinsta.com/tag/Additional-SFTP-Users#operation/removeAdditionalSftpAccount):

```
DELETE /sites/environments/additional-sftp-accounts/{sftp_account_id}
```

This gives you full flexibility to automate account rotation, grant limited access to collaborators, or revoke credentials after a deployment.

### New metadata in environment listings

To support these new capabilities, we added the field `is_additional_sftp_accounts_enabled`&nbsp;to the following endpoints:

- [GET /sites/{site\_id}/environments](https://api-docs.kinsta.com/tag/WordPress-Site-Environments#operation/getSiteEnvironments)
- [GET /sites](https://api-docs.kinsta.com/tag/WordPress-Sites/#operation/getSites)&nbsp;(when using the `include_environments=true` query parameter)

This makes it easier to audit which environments have additional SFTP access enabled, especially if you’re managing many across your platform or client accounts.

## More control for modern teams

These new API features give you deeper control over your infrastructure, whether you’re automating staging workflows, rotating SFTP credentials, or programmatically switching site URLs.

You can find all request/response details in the[&nbsp;Kinsta API documentation](https://api-docs.kinsta.com/). There’s a lot you can do with the Kinsta API, and many agencies and developers already rely on it to manage hundreds of sites efficiently.

Ready to get started? Head to [MyKinsta](https://my.kinsta.com/login/)&nbsp;to [generate your API token](https://kinsta.com/blog/kinsta-api-key/)&nbsp;and start building.

The post [Change primary domains and manage SFTP access with Kinsta API](https://kinsta.com/changelog/kinsta-api-jun-23-2025/) appeared first on [Kinsta®](https://kinsta.com).

* * *
This is a companion discussion topic for the original entry at [https://kinsta.com/changelog/kinsta-api-jun-23-2025/](https://kinsta.com/changelog/kinsta-api-jun-23-2025/)
