> This page is for Postman API Docs.

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt.

# Sync spec with collection

PUT https://api.postman.com/specs/{specId}/synchronizations

Syncs an API specification linked to a collection. This is an asynchronous endpoint that returns an HTTP `202 Accepted` response.

**Note:**

- This endpoint only supports the OpenAPI 2.0, 3.0, and 3.1 specification types.
- You can only sync collections generated from the given specification ID.


Reference: https://learning.postman.com/api-docs/api-reference/specs/sync-spec-with-collection

## Authentication

- `x-api-key` header (required) — API Key authentication via header

## Servers

- `https://api.postman.com` (https://api.postman.com, default)
- `https://api.eu.postman.com` (https://api.eu.postman.com)

## Request

### Path parameters

- `specId` (string, required) — The spec's ID.

### Query parameters

- `collectionUid` (string, required) — The collection's unique ID.

## Response

### 202

Successful Response

- `taskId` (string, optional) — The created task ID. You can use this ID to track the status of the task.
- `url` (string, optional) — The URL to get or poll the status of a generated spec task.

## Errors

### 401 Unauthorized Error

Unauthorized

- `type` (CommonErrorTypeTitleDetailStatusType, optional) — The type of error.
- `title` (string, optional) — A short summary of the problem.
- `detail` (string, optional) — Information about the error.
- `status` (integer, optional) — The error's HTTP status code.

### 403 Forbidden Error

Forbidden

- `SyncSpecWithCollectionRequestForbiddenError`
  - Error (Type, Title, Detail, Status): commonErrorTypeTitleDetailStatus
  - Error (Type, Title, Detail, Status, Instance): commonErrorTypeTitleDetailStatusInstance

### 404 Not Found Error

Not Found

- `type` (CommonErrorTypeTitleDetailStatusType, optional) — The type of error.
- `title` (string, optional) — A short summary of the problem.
- `detail` (string, optional) — Information about the error.
- `status` (integer, optional) — The error's HTTP status code.

### 500 Internal Server Error

Internal Server Error

- `SyncSpecWithCollectionRequestInternalServerError`
  - Error (Type, Title, Detail): commonErrorTypeTitleDetail
  - Error (Type, Title, Detail, Status): commonErrorTypeTitleDetailStatus
  - Error (Name, Message): commonErrorNameMessage

## Types

### CommonErrorTypeTitleDetailStatusType

The type of error.

- string
- string

### commonErrorTypeTitleDetailStatus

- `type` (CommonErrorTypeTitleDetailStatusType, optional) — The type of error.
- `title` (string, optional) — A short summary of the problem.
- `detail` (string, optional) — Information about the error.
- `status` (integer, optional) — The error's HTTP status code.

### commonErrorTypeTitleDetailStatusInstance

- `type` (string, optional) — The [URI reference](https://www.rfc-editor.org/rfc/rfc3986) that identifies the type of problem.
- `title` (string, optional) — A short summary of the problem.
- `detail` (string, optional) — An explanation about the problem.
- `status` (integer, optional) — The HTTP status code generated by the origin server.
- `instance` (string, optional) — The URI reference that identifies the specific occurrence of the problem.

### commonErrorTypeTitleDetail

- `type` (string, optional) — The type of error.
- `title` (string, optional) — A short summary of the problem.
- `detail` (CommonErrorTypeTitleDetailDetail, optional) — Information about the error.

### commonErrorNameMessage

- `error` (CommonErrorNameMessageError, optional) — Information about the error.

### CommonErrorTypeTitleDetailDetail

Information about the error.

- string
- map from string to any

### CommonErrorNameMessageError

Information about the error.

- `name` (string, optional) — The error name.
- `message` (string, optional) — The error message.

## Examples

### Generate Spec Task

**Response**

```json
{
  "taskId": "66ae9950-0869-4e65-96b0-1e0e47e771af",
  "url": "/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/tasks/66ae9950-0869-4e65-96b0-1e0e47e771af"
}
```

**SDK Code**

```python Generate Spec Task
import requests

url = "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations"

querystring = {"collectionUid":"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2"}

headers = {"x-api-key": "<apiKey>"}

response = requests.put(url, headers=headers, params=querystring)

print(response.json())
```

```javascript Generate Spec Task
const url = 'https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2';
const options = {method: 'PUT', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Generate Spec Task
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2"

	req, _ := http.NewRequest("PUT", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Generate Spec Task
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Generate Spec Task
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Generate Spec Task
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Generate Spec Task
using RestSharp;

var client = new RestClient("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2");
var request = new RestRequest(Method.PUT);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Generate Spec Task
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Generate Collection Task

**Response**

```json
{
  "taskId": "66ae9950-0869-4e65-96b0-1e0e47e771af",
  "url": "/collections/12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2/tasks/66ae9950-0869-4e65-96b0-1e0e47e771af"
}
```

**SDK Code**

```python Generate Collection Task
import requests

url = "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations"

querystring = {"collectionUid":"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2"}

headers = {"x-api-key": "<apiKey>"}

response = requests.put(url, headers=headers, params=querystring)

print(response.json())
```

```javascript Generate Collection Task
const url = 'https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2';
const options = {method: 'PUT', headers: {'x-api-key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Generate Collection Task
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2"

	req, _ := http.NewRequest("PUT", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Generate Collection Task
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java Generate Collection Task
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Generate Collection Task
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Generate Collection Task
using RestSharp;

var client = new RestClient("https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2");
var request = new RestRequest(Method.PUT);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Generate Collection Task
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/specs/73e15000-bc7a-4802-b80e-05fff18fd7f8/synchronizations?collectionUid=12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```