# Automate backups of your Postman Collections with the Postman API

Postman enables you to manually [back up your data](https://learning.postman.com/docs/getting-started/importing-and-exporting/exporting-data/) and [recover deleted collections](https://learning.postman.com/docs/collections/using-collections/#recovering-a-deleted-collection). While keeping backups of your Postman Collections is always a good idea under normal circumstances, it can be a real lifesaver when:

- You have automatic processes that modify collections. In such cases, you may want to back up collections before there are any changes. Then, if there’s an error, you can safely roll those changes back.
- There are accidental manual changes you want to revert.
 
 But did you know that you can use the [Postman API](https://www.postman.com/postman/workspace/postman-public-workspace/documentation/12959542-c8142d51-e97c-46b6-bd77-52bb66712c9a) to programmatically maintain a copy of your collection? You can do it by using the Postman API’s GET and PUT collection endpoints, a transfer method, or the new [pull source changes](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-e6533094-cf99-45bc-9637-f9489ff68c29?ctx=documentation) endpoint. ## Using the /collections GET and PUT endpoints

 The Postman API offers a [GET](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-a6a282df-907e-438b-8fe6-e5efaa60b8bf?ctx=documentation) `/collections/{id}` and [PUT](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-bc8b292b-ffbb-4c67-a2a1-2fc416e2aef8?ctx=documentation) `/collections/{id}` endpoint that you can use to create a collection backup. These endpoints read a source collection and then update an empty destination collection with the source collection’s contents. To simplify the process, we’ve created a [collection](https://www.postman.com/postman/workspace/postman-public-workspace/documentation/20891195-67cd7f44-c9a8-4ccf-9d8d-373d1cf7f762) and [environment](https://www.postman.com/postman/workspace/postman-public-workspace/environment/20891195-95a7743f-26b6-4e4d-bf12-be16776644ea) you can fork and run. You can also use this collection in your CI/CD environments using the[ Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-run-collection/). **Prerequisites**- An empty collection in a workspace. This will be your backup (destination) collection. During the process, this collection will be renamed to use the original (source) collection’s name.
- The empty backup [collection's ID](https://support.postman.com/hc/en-us/articles/5063785095319-How-to-find-the-ID-of-an-element-in-Postman).
 
### **How it works**

 When you run this collection, it: 1. Performs a GET of the source collection using the GET `/collections/{id}` endpoint.
2. Processes the GET response and removes all the `id`, `_postman_id`, and `uid` fields. This is necessary for the next step.
3. Runs a PUT `/collections/{id}` on the backup destination collection with an empty `item` list in the body. This cleans up all the data in the destination collection.
4. Runs a PUT `/collections/{id}` using the processed payload (without the ID fields) into the destination collection.
 
### Pros

- It’s a simple process: it reads from the source collection and overwrites the destination collection.
- It requires fewer requests to complete than the Transfers API method, so it is best for small collections.
 
### Cons

- It requires some code in the collection scripts to remove the ID fields from the source collection’s response.
- It performs several requests to the Postman API, so [Postman API rate limits](https://learning.postman.com/docs/developer/postman-api/postman-api-rate-limits/) may apply.
- Not recommended for large collections because the process can take some time to complete.
 
## Using the /collections/{id}/pulls endpoint

 The [PUT](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-e6533094-cf99-45bc-9637-f9489ff68c29?ctx=documentation) `/collections/{id}/pulls` endpoint lets you pull changes from a source collection into a forked (destination) collection. The process consists of a single request, which you can run with a cURL command: ```
curl --location --globoff --request PUT 'https://api.getpostman.com/collections/{{forkedCollectionId}}/pulls' \
--header 'x-api-key: PMAK-XXX'

```

 **Prerequisites**- Create a fork of the collection you want to back up.
- The [forked collection’s ID](https://support.postman.com/hc/en-us/articles/5063785095319-How-to-find-the-ID-of-an-element-in-Postman).
 
### How it works

 Use the PUT `/collections/{id}/pulls` endpoint to pull changes from the source into the destination collection: 1. [Fork](https://learning.postman.com/docs/collaborating-in-postman/using-version-control/forking-elements/#create-a-fork) the source collection in the Postman app or use the Postman API [**Create a fork**](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-214f4f93-cbb9-4b86-8a56-76a05eaab9fe) endpoint.
2. Perform a [pull changes](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-e6533094-cf99-45bc-9637-f9489ff68c29?ctx=documentation) request on the forked collection. To avoid conflicts when you pull changes, make certain that you don’t modify the forked collection. For large collections, this request can take several seconds to complete.
 
### Pros

- This is the fastest and easiest way to update a collection because it only propagates changes. It consists of creating a fork of the collection and updating it periodically with a pull of the changes on the source collection.
- The process is a single API call that you can implement with a cURL request and integrate into your CI/CD processes without exceeding your Postman API rate limits.
 
### Cons

- If the backup collection changes, the process may fail due to conflicts.
 
## Using Transfers APIs

 The Postman API has [**Transfers**](https://www.postman.com/postman/workspace/postman-public-workspace/folder/12959542-507b324e-e208-4e2c-9b7a-c658e20dfa73) endpoints, which let you move collection items—such as requests and responses—between different collections and folders. These endpoints copy the collection’s items (folders and requests) from the source collection into a backup collection. This is a variant of the GET and PUT method, but instead of retrieving all the collection contents, it just gets basic information about the collection. It uses the Postman API’s **Transfers** endpoints to iteratively copy that information into the backup collection. We've created a [collection](https://www.postman.com/postman/workspace/postman-public-workspace/documentation/20891195-47a6a3a9-c7bf-47bc-81e0-c2f0b1e1b904) and [environment](https://www.postman.com/postman/workspace/postman-public-workspace/environment/20891195-95a7743f-26b6-4e4d-bf12-be16776644ea) you can fork and use to make backups of your collections. **Prerequisites**- An empty collection in a workspace. This will be your backup (destination) collection. During the process, this collection will be renamed to use the original (source) collection’s name.
- The empty backup [collection's ID](https://support.postman.com/hc/en-us/articles/5063785095319-How-to-find-the-ID-of-an-element-in-Postman).
 
### How it works

 When your run this collection, it: 1. Retrieves the source collection data using the [GET](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-a6a282df-907e-438b-8fe6-e5efaa60b8bf?ctx=documentation) `/collections/{id}` endpoint and passing the `model=minimal` query string parameter. This returns all folders and requests located in the collection’s root level.
2. Performs a PUT on the destination collection using the previous data, but passes an empty `item` list. This copies the collection’s variables, scripts, and authorization information.
3. Loops over the `rootLevelFolders` property and uses the [POST](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-8489855a-a47c-428d-8f82-d5f3830fbc0c?ctx=documentation) `/collection-folders-transfers` endpoint to copy each folder into the backup collection.
4. Loops over the `rootLevelRequests` list and uses the [POST](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-cc197fee-af62-4a78-af0c-921a6c076e44?ctx=documentation) `/collection-requests-transfers` endpoint to copy each request into the backup collection.
 
### Pros

- This method is best for very large collections because it does not process the entire collection in a single request.
 
### Cons

- It’s an advanced process that requires some code and uses a complex collection.
- It performs several requests to the Postman API, so Postman API rate limits may apply.
- It is a slower process versus the pull strategy.
 
## Next steps

 The Postman API provides full CRUD capabilities that let you programmatically back up your collections into another collection in different ways. Depending on your use case, you can fork and pull changes or read and copy the information using different strategies. We’ve shown you some possible scenarios and implemented some collections with these solutions. Do you have any use cases related to collections that require managing them programmatically? We would love to hear about it—please let us know in a comment below!