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

# Update a custom function

PATCH https://api.postman.com/custom-functions/{customFunctionId}
Content-Type: application/merge-patch+json

Updates a custom function. Only the fields present in the request body are updated. If `content` is provided, it replaces the entire contents of the custom function.

Reference: https://learning.postman.com/api-docs/api-reference/api-governance/update-custom-function

## 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

- `customFunctionId` (string, required) — The custom function's ID.

### Body (application/merge-patch+json)

This endpoint expects a customFunctionUpdate.

- `path` (string, optional) — The custom function's path, in the form `functions/<name>.js`. Root-level paths and nested paths aren't supported.
- `description` (string, optional) — The custom function's description.
- `content` (string, optional) — The custom function's content, up to a maximum of 500 KB (UTF-8).

## Response

### 200

Custom Function Updated

- `id` (string, required) — The resource's ID.

## Errors

### 400 Bad Request Error

Bad Request

- `UpdateCustomFunctionRequestBadRequestError`

### 401 Unauthorized Error

Unauthorized

- `UpdateCustomFunctionRequestUnauthorizedError`

### 403 Forbidden Error

Forbidden

- `UpdateCustomFunctionRequestForbiddenError`

### 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.

### 409 Conflict Error

Conflict

- `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

- `UpdateCustomFunctionRequestInternalServerError`

## Types

### commonErrorTypeTitleDetail

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

### 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.

### commonErrorNameMessageDetails

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

### commonErrorNameMessage

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

### CommonErrorTypeTitleDetailStatusType

The type of error.

### CommonErrorTypeTitleDetailDetail

Information about the error.

### CommonErrorNameMessageDetailsError

Information about the error.

- `name` (string, optional) — The error name.
- `message` (string, optional) — The error message.
- `details` (CommonErrorNameMessageDetailsErrorDetails, optional) — Information about the error.

### CommonErrorNameMessageError

Information about the error.

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

### CommonErrorNameMessageDetailsErrorDetails

Information about the error.

## Examples

### Custom Function Updated

**Request**

```json
undefined
```

**Response**

```json
{
  "id": "01JCUSTOMFN0123456789ABCDE"
}
```

**SDK Code**

```python Custom Function Updated
import requests

url = "https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE"

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

response = requests.patch(url, headers=headers)

print(response.json())
```

```javascript Custom Function Updated
const url = 'https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE';
const options = {method: 'PATCH', 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 Custom Function Updated
package main

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

func main() {

	url := "https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE"

	req, _ := http.NewRequest("PATCH", 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 Custom Function Updated
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE")

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

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

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

```java Custom Function Updated
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php Custom Function Updated
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Custom Function Updated
using RestSharp;

var client = new RestClient("https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE");
var request = new RestRequest(Method.PATCH);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Custom Function Updated
import Foundation

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
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()
```

### Update Metadata

**Request**

```json
{
  "path": "functions/checkResourceNestingV2.js",
  "description": "Updated custom Spectral function."
}
```

**Response**

```json
{
  "id": "01JCUSTOMFN0123456789ABCDE"
}
```

**SDK Code**

```python Update Metadata
import requests

url = "https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE"

payload = "{\n  \"path\": \"functions/checkResourceNestingV2.js\",\n  \"description\": \"Updated custom Spectral function.\"\n}"
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/merge-patch+json"
}

response = requests.patch(url, data=payload, headers=headers)

print(response.json())
```

```javascript Update Metadata
const url = 'https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE';
const options = {
  method: 'PATCH',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/merge-patch+json'},
  body: '{\n  "path": "functions/checkResourceNestingV2.js",\n  "description": "Updated custom Spectral function."\n}'
};

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

```go Update Metadata
package main

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

func main() {

	url := "https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE"

	payload := strings.NewReader("{\n  \"path\": \"functions/checkResourceNestingV2.js\",\n  \"description\": \"Updated custom Spectral function.\"\n}")

	req, _ := http.NewRequest("PATCH", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/merge-patch+json")

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

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

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

}
```

```ruby Update Metadata
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE")

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

request = Net::HTTP::Patch.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/merge-patch+json'
request.body = "{\n  \"path\": \"functions/checkResourceNestingV2.js\",\n  \"description\": \"Updated custom Spectral function.\"\n}"

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

```java Update Metadata
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/merge-patch+json")
  .body("{\n  \"path\": \"functions/checkResourceNestingV2.js\",\n  \"description\": \"Updated custom Spectral function.\"\n}")
  .asString();
```

```php Update Metadata
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE', [
  'body' => '{
  "path": "functions/checkResourceNestingV2.js",
  "description": "Updated custom Spectral function."
}',
  'headers' => [
    'Content-Type' => 'application/merge-patch+json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Update Metadata
using RestSharp;

var client = new RestClient("https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE");
var request = new RestRequest(Method.PATCH);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/merge-patch+json");
request.AddParameter("application/merge-patch+json", "{\n  \"path\": \"functions/checkResourceNestingV2.js\",\n  \"description\": \"Updated custom Spectral function.\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Update Metadata
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/merge-patch+json"
]

let postData = NSData(data: "{
  "path": "functions/checkResourceNestingV2.js",
  "description": "Updated custom Spectral function."
}".data(using: String.Encoding.utf8)!)

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```

### Replace Content

**Request**

```json
{
  "content": "export default (input) => { return [{ message: 'Invalid input' }]; };"
}
```

**Response**

```json
{
  "id": "01JCUSTOMFN0123456789ABCDE"
}
```

**SDK Code**

```python Replace Content
import requests

url = "https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE"

payload = "{\n  \"content\": \"export default (input) => { return [{ message: 'Invalid input' }]; };\"\n}"
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/merge-patch+json"
}

response = requests.patch(url, data=payload, headers=headers)

print(response.json())
```

```javascript Replace Content
const url = 'https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE';
const options = {
  method: 'PATCH',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/merge-patch+json'},
  body: '{\n  "content": "export default (input) => { return [{ message: \'Invalid input\' }]; };"\n}'
};

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

```go Replace Content
package main

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

func main() {

	url := "https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE"

	payload := strings.NewReader("{\n  \"content\": \"export default (input) => { return [{ message: 'Invalid input' }]; };\"\n}")

	req, _ := http.NewRequest("PATCH", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/merge-patch+json")

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

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

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

}
```

```ruby Replace Content
require 'uri'
require 'net/http'

url = URI("https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE")

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

request = Net::HTTP::Patch.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/merge-patch+json'
request.body = "{\n  \"content\": \"export default (input) => { return [{ message: 'Invalid input' }]; };\"\n}"

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

```java Replace Content
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/merge-patch+json")
  .body("{\n  \"content\": \"export default (input) => { return [{ message: 'Invalid input' }]; };\"\n}")
  .asString();
```

```php Replace Content
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE', [
  'body' => '{
  "content": "export default (input) => { return [{ message: \'Invalid input\' }]; };"
}',
  'headers' => [
    'Content-Type' => 'application/merge-patch+json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Replace Content
using RestSharp;

var client = new RestClient("https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE");
var request = new RestRequest(Method.PATCH);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/merge-patch+json");
request.AddParameter("application/merge-patch+json", "{\n  \"content\": \"export default (input) => { return [{ message: 'Invalid input' }]; };\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Replace Content
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/merge-patch+json"
]

let postData = NSData(data: "{
  "content": "export default (input) => { return [{ message: 'Invalid input' }]; };"
}".data(using: String.Encoding.utf8)!)

let request = NSMutableURLRequest(url: NSURL(string: "https://api.postman.com/custom-functions/01JCUSTOMFN0123456789ABCDE")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```