# Fetch files and target specific paths with the Kinsta API

**URL:** https://community.kinsta.com/t/fetch-files-and-target-specific-paths-with-the-kinsta-api/5149
**Category:** News and Announcements
**Created:** [June 6, 2025, 3:16pm UTC](https://community.kinsta.com/t/fetch-files-and-target-specific-paths-with-the-kinsta-api/5149 "2025-06-06T15:16:45Z")
**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 6, 2025, 3:16pm UTC](https://community.kinsta.com/t/fetch-files-and-target-specific-paths-with-the-kinsta-api/5149/1 "2025-06-06T15:16:45Z")

</div>

Working with environments just got easier. This Kinsta API update introduces new ways to fetch file structure data, perform [selective file pushes between environments](https://kinsta.com/docs/wordpress-hosting/staging-environment/#push-environment-to-live-or-staging), and retrieve all environments in a single request when listing sites.

These additions are designed to reduce the number of calls you need to make, so your deployments and dev tools are faster and more efficient.

## Get file list for an environment

You can now [retrieve the full directory structure](https://api-docs.kinsta.com/tag/WordPress-Site-Environments/#operation/ListFiles)&nbsp;of a WordPress environment using the Kinsta API. This new endpoint returns a recursive list of folders and subfolders, giving you a clear view of what’s inside each environment — no [SSH](https://kinsta.com/blog/how-to-use-ssh/)&nbsp;logins required.

This is especially useful when building internal tools, validating file paths before selective deployments, or automating environment tasks with precision.

You can send a `GET`&nbsp;request to:

```
GET /sites/environments/{env_id}/file-list
```

### Info

You need a valid API access token to use these endpoints. You can [create or manage your API tokens in MyKinsta](https://kinsta.com/blog/kinsta-api-key/)..

Here’s a sample request using `curl`:

```
curl -i -X GET \
  'https://api.kinsta.com/v2/sites/environments/{env_id}/file-list' \
  -H 'Authorization: Bearer '
```

The response includes nested objects representing directories like:

- `wp-content/`
- `wp-content/plugins/`
- `wp-content/themes/`
- `wp-content/uploads/`

Each folder contains its name, path, and any children, making it easy to map or visualize.

## Selective file push between environments

The existing `Push Environment`&nbsp;endpoint now supports a more flexible way to manage file transfers. With two new optional fields, you can push either the full environment or target specific directories — perfect for workflows where you don’t want to sync everything.

You can send a `PUT`&nbsp;request to:

```
PUT /sites/{site_id}/environments
```

Use the following fields to control which files are included:

- `push_files_option`: Choose between `"ALL_FILES"`&nbsp;or `"SPECIFIC_FILES"`
- `file_list`: Provide a list of directory paths you want to push

Here’s an example using `curl`&nbsp;to push only selected folders from one environment to another:

```
curl -i -X PUT \
  'https://api.kinsta.com/v2/sites/{site_id}/environments' \
  -H 'Authorization: Bearer ' \
  -H 'Content-Type: application/json' \
  -d '{
    "source_env_id": "your-source-env-id",
    "target_env_id": "your-target-env-id",
    "push_db": true,
    "push_files": true,
    "run_search_and_replace": true,
    "push_files_option": "SPECIFIC_FILES",
    "file_list": [
      "wp-content/plugins",
      "wp-content/themes",
      "wp-content/uploads"
    ]
  }'
```

This selective approach helps:

- Reduce deployment time by syncing only what has changed
- Avoid overwriting other assets or uploads
- Improve control when pushing changes from staging to production

If you don’t include `push_files_option`, it defaults to `"ALL_FILES"`, maintaining backward compatibility.

## List sites and their environments in one call

You can now [fetch all of a company’s sites](https://api-docs.kinsta.com/tag/WordPress-Sites#operation/getSites)**[and](https://api-docs.kinsta.com/tag/WordPress-Sites#operation/getSites)**[&nbsp;their environments](https://api-docs.kinsta.com/tag/WordPress-Sites#operation/getSites)&nbsp;with a single API call. By adding the `include_environments=true`&nbsp;query parameter to the `GET /sites`&nbsp;endpoint, the response includes each site’s associated environments — no need for separate follow-up requests.

This is especially useful for agencies or teams managing a large number of sites, where minimizing API calls and speeding up environment audits can make a big difference.

```
GET /sites?company=your-company-id&include_environments=true
```

Here’s a sample `curl`&nbsp;request:

```
curl -i -X GET \
'https://api.kinsta.com/v2/sites?company=your-company-id&include_environments=true' \
  -H 'Authorization: Bearer '
```

The response includes site metadata (name, ID, etc.) and a nested list of environments (`staging`, `production`, etc.).

### Info

In rare cases, this may result in a temporary `500 Internal Server Error`. If you run into this issue, [contact our support team](https://kinsta.com/kinsta-support/),&nbsp;and we can intervene manually if needed.

## Kinsta API: Built for teams managing at scale

These API enhancements are designed to save time and reduce complexity, especially for developers and agencies managing dozens (or hundreds) of WordPress sites.

Whether you’re syncing selected plugin files, [building internal tools](https://kinsta.com/topic/api/), or auditing environments across a portfolio, these improvements help streamline the work you’d otherwise have to do manually in the dashboard.

You can explore these new capabilities in the [Kinsta API documentation](https://api-docs.kinsta.com/)&nbsp;or jump straight into [MyKinsta](https://my.kinsta.com/login/)&nbsp;to [generate your access token](https://kinsta.com/blog/kinsta-api-key/)&nbsp;and start building.

The post [Fetch files and target specific paths with the Kinsta API](https://kinsta.com/changelog/kinsta-api-jun-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-2025/](https://kinsta.com/changelog/kinsta-api-jun-2025/)
