> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.webflow.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.webflow.com/_mcp/server.

# Add/Update Custom Code

PUT https://api.webflow.com/v2/sites/{site_id}/custom_code
Content-Type: application/json

Apply registered scripts to a site. If you have multiple scripts your App needs to apply or maintain on a site, ensure they are always included in the request body for this endpoint. To remove individual scripts, simply call this endpoint without the script in the request body.To apply a script to a site or page, the script must first be registered to a site via the [Register Script](/data/reference/custom-code/custom-code/register-hosted) endpoints. Once registered, the script can be applied to a Site or Page using the appropriate endpoints. See the documentation on [working with Custom Code](/data/docs/custom-code) for more information.Access to this endpoint requires a bearer token obtained from an [OAuth Code Grant Flow](/data/reference/oauth-app).Required scope | `custom_code:write`

Reference: https://developers.webflow.com/data/reference/custom-code/custom-code-sites/upsert-custom-code

## Authentication

- `Authorization` header (bearer token, required)

## Request

### Path parameters

- `site_id` (string, required) — Unique identifier for a Site

### Body (application/json)

- `scripts` (list of object, optional) — A list of scripts applied to a Site or a Page
  - `id` (string, required) — ID of the registered custom code script
  - `location` (enum, required, default: header) — Location of the script, either in the header or footer of the published site
    - Allowed values: `header`, `footer`
  - `version` (string, required) — Semantic Version String for the registered script *e.g. 0.0.1*
  - `attributes` (object, optional) — Developer-specified key/value pairs to be applied as attributes to the script
- `lastUpdated` (string, optional) — Date when the Site's scripts were last updated
- `createdOn` (string, optional) — Date when the Site's scripts were created

## Response

### 200

Request was successful

- `scripts` (list of object, optional) — A list of scripts applied to a Site or a Page
  - `id` (string, required) — ID of the registered custom code script
  - `location` (enum, required, default: header) — Location of the script, either in the header or footer of the published site
    - Allowed values: `header`, `footer`
  - `version` (string, required) — Semantic Version String for the registered script *e.g. 0.0.1*
  - `attributes` (object, optional) — Developer-specified key/value pairs to be applied as attributes to the script
- `lastUpdated` (string, optional) — Date when the Site's scripts were last updated
- `createdOn` (string, optional) — Date when the Site's scripts were created

## Examples

**Request**

```json
{
  "scripts": [
    {
      "id": "cms_slider",
      "location": "header",
      "version": "1.0.0",
      "attributes": {
        "my-attribute": "some-value"
      }
    },
    {
      "id": "alert",
      "location": "header",
      "version": "0.0.1"
    }
  ]
}
```

**Response**

```json
{
  "scripts": [
    {
      "id": "cms_slider",
      "location": "header",
      "version": "1.0.0",
      "attributes": {
        "my-attribute": "some-value"
      }
    },
    {
      "id": "alert",
      "location": "header",
      "version": "0.0.1"
    }
  ]
}
```

**SDK Code**

```typescript sites_scripts_upsert-custom-code_example
import { WebflowClient } from "webflow-api";

async function main() {
    const client = new WebflowClient({
        accessToken: "YOUR_TOKEN_HERE",
    });
    await client.sites.scripts.upsertCustomCode("580e63e98c9a982ac9b8b741", {
        scripts: [
            {
                id: "cms_slider",
                location: "header",
                version: "1.0.0",
                attributes: {
                    "my-attribute": "some-value",
                },
            },
            {
                id: "alert",
                location: "header",
                version: "0.0.1",
            },
        ],
    });
}
main();

```

```python sites_scripts_upsert-custom-code_example
from webflow import Webflow, ScriptApply

client = Webflow(
    access_token="YOUR_TOKEN_HERE",
)

client.sites.scripts.upsert_custom_code(
    site_id="580e63e98c9a982ac9b8b741",
    scripts=[
        ScriptApply(
            id="cms_slider",
            location="header",
            version="1.0.0",
            attributes={
                "my-attribute": "some-value"
            },
        ),
        ScriptApply(
            id="alert",
            location="header",
            version="0.0.1",
        )
    ],
)

```

```go sites_scripts_upsert-custom-code_example
package main

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

func main() {

	url := "https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/custom_code"

	payload := strings.NewReader("{\n  \"scripts\": [\n    {\n      \"id\": \"cms_slider\",\n      \"location\": \"header\",\n      \"version\": \"1.0.0\",\n      \"attributes\": {\n        \"my-attribute\": \"some-value\"\n      }\n    },\n    {\n      \"id\": \"alert\",\n      \"location\": \"header\",\n      \"version\": \"0.0.1\"\n    }\n  ]\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

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

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

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

}
```

```ruby sites_scripts_upsert-custom-code_example
require 'uri'
require 'net/http'

url = URI("https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/custom_code")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"scripts\": [\n    {\n      \"id\": \"cms_slider\",\n      \"location\": \"header\",\n      \"version\": \"1.0.0\",\n      \"attributes\": {\n        \"my-attribute\": \"some-value\"\n      }\n    },\n    {\n      \"id\": \"alert\",\n      \"location\": \"header\",\n      \"version\": \"0.0.1\"\n    }\n  ]\n}"

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

```java sites_scripts_upsert-custom-code_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/custom_code")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"scripts\": [\n    {\n      \"id\": \"cms_slider\",\n      \"location\": \"header\",\n      \"version\": \"1.0.0\",\n      \"attributes\": {\n        \"my-attribute\": \"some-value\"\n      }\n    },\n    {\n      \"id\": \"alert\",\n      \"location\": \"header\",\n      \"version\": \"0.0.1\"\n    }\n  ]\n}")
  .asString();
```

```php sites_scripts_upsert-custom-code_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/custom_code', [
  'body' => '{
  "scripts": [
    {
      "id": "cms_slider",
      "location": "header",
      "version": "1.0.0",
      "attributes": {
        "my-attribute": "some-value"
      }
    },
    {
      "id": "alert",
      "location": "header",
      "version": "0.0.1"
    }
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp sites_scripts_upsert-custom-code_example
using RestSharp;

var client = new RestClient("https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/custom_code");
var request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"scripts\": [\n    {\n      \"id\": \"cms_slider\",\n      \"location\": \"header\",\n      \"version\": \"1.0.0\",\n      \"attributes\": {\n        \"my-attribute\": \"some-value\"\n      }\n    },\n    {\n      \"id\": \"alert\",\n      \"location\": \"header\",\n      \"version\": \"0.0.1\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift sites_scripts_upsert-custom-code_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["scripts": [
    [
      "id": "cms_slider",
      "location": "header",
      "version": "1.0.0",
      "attributes": ["my-attribute": "some-value"]
    ],
    [
      "id": "alert",
      "location": "header",
      "version": "0.0.1"
    ]
  ]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/custom_code")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```