# Automatic importing of collections with Postman API

**URL:** <https://community.postman.com/t/automatic-importing-of-collections-with-postman-api/58263>\
**Category:** Help Hub\
**Tags:** openapi, postman-api\
**Created:** [February 28, 2024, 9:06pm UTC](https://community.postman.com/t/automatic-importing-of-collections-with-postman-api/58263 "2024-02-28T21:06:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jthom2](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@jthom2](https://community.postman.com/u/jthom2)\
**Post date:** [February 28, 2024, 9:06pm UTC](https://community.postman.com/t/automatic-importing-of-collections-with-postman-api/58263/1 "2024-02-28T21:06:02Z")

</div>

Im trying to create a script using the Postman API to import a URL as a collection. When I use the import button through the app, it works, but doing with the script returns that it is missing a required parameter “collection” within the json.

```auto
Failed to import collection. Status code: 400
Response body: {"error":{"name":"paramMissingError","message":"Parameter is missing in the request.","details":{"param":"collection"}}}

```

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [February 28, 2024, 9:47pm UTC](https://community.postman.com/t/automatic-importing-of-collections-with-postman-api/58263/2 "2024-02-28T21:47:41Z")

</div>

Hi @jthom2. Welcome to the Postman Community.

AFAIK, you can only import a Postman data dump or an OpenAPI definition via the Postman API. Can you share how you’re trying to do this import using the Postman API?

---

<div class="post-metadata">

**Author:** ![jthom2](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@jthom2](https://community.postman.com/u/jthom2)\
**Post date:** [February 29, 2024, 5:34pm UTC](https://community.postman.com/t/automatic-importing-of-collections-with-postman-api/58263/3 "2024-02-29T17:34:14Z")

</div>

Yes, the code below is what im using.

```auto
from dotenv import load_dotenv
import requests
import json
import os

load_dotenv()

api_key = os.environ.get('POSTMAN_API_KEY')

api_url = os.environ.get('API_URL')

api_response = requests.get(api_url)
if api_response.status_code == 200:
    api_definition_content = api_response.json()
else:
    print("Failed to fetch API defintion. Status code:", api_response.status_code)
    exit()

url = "https://api.getpostman.com/collections"

headers = {
    "X-Api-Key": api_key,
    "Content-Type": "application/json"
}

api_definition_json = json.dumps(api_definition_content)

response = requests.post(url, headers=headers, data=api_definition_json)

if response.status_code == 200:
    print("Collection created successfully")
else:
    print("Failed to import collection. Status code:", response.status_code)
    print("Response body:", response.text)

```

---

<div class="post-metadata">

**Author:** ![gbadebo-bello](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/gbadebo-bello/32/12175_2.png) [@gbadebo-bello](https://community.postman.com/u/gbadebo-bello)\
**Post date:** [March 1, 2024, 12:00pm UTC](https://community.postman.com/t/automatic-importing-of-collections-with-postman-api/58263/4 "2024-03-01T12:00:21Z")

</div>

It seems you’re making an API call to the wrong endpoint. You can refer to the documentation for importing dumps [here](https://documenter.getpostman.com/view/12959542/UV5XjJV8#902c2d6e-eb59-49ec-8f6f-6bb1fa96f597).

---

<div class="post-metadata">

**Author:** ![jthom2](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@jthom2](https://community.postman.com/u/jthom2)\
**Post date:** [March 1, 2024, 3:53pm UTC](https://community.postman.com/t/automatic-importing-of-collections-with-postman-api/58263/5 "2024-03-01T15:53:37Z")

</div>

I was able to get it working with that endpoint and a few other minor modifications. Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [March 4, 2024, 3:54pm UTC](https://community.postman.com/t/automatic-importing-of-collections-with-postman-api/58263/6 "2024-03-04T15:54:34Z")

</div>

Closed on March 4, 2024, 3:54pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
