# Scripts

## List Scripts

> Retrieves a paginated list of scripts. Can be filtered by \`name\` and \`versions.id\`.

```json
{"openapi":"3.0.0","info":{"title":"Patchworks Core API","version":"1.0.0"},"tags":[{"name":"Scripts"}],"servers":[{"url":"https://core.wearepatchworks.com"}],"security":[{"ApiKeyAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"API key passed in the Authorization header. Format: `<api-key>`"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"OAuth 2 Bearer token obtained from POST /fabric/api/login"}},"schemas":{"ScriptsListResponse":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Scripts"}},"meta":{"$ref":"#/components/schemas/PaginationMeta"},"links":{"$ref":"#/components/schemas/PaginationLinks"}}},"Scripts":{"type":"object","properties":{"id":{"type":"integer","description":"Unique identifier"},"script_template_id":{"type":"integer"},"name":{"type":"string"},"description":{"type":"string","items":{"type":"object"}},"language":{"type":"string","items":{"type":"object"}},"created_at":{"type":"string"},"updated_at":{"type":"string"},"script_id":{"type":"integer"},"version":{"type":"string"},"deployed_at":{"type":"string"},"deployment_failed_at":{"type":"string"},"deploying":{"type":"string"},"deployment_failure_reason":{"type":"string"},"content":{"type":"string"},"ai_created":{"type":"string","items":{"type":"object"}},"value":{"type":"string"},"versions":{"type":"array","items":{"type":"object"}},"latest_version":{"type":"object"}}},"PaginationMeta":{"type":"object","properties":{"current_page":{"type":"integer"},"from":{"type":"integer","nullable":true},"last_page":{"type":"integer"},"path":{"type":"string"},"per_page":{"type":"integer"},"to":{"type":"integer","nullable":true},"total":{"type":"integer"}}},"PaginationLinks":{"type":"object","properties":{"first":{"type":"string","format":"uri"},"last":{"type":"string","format":"uri"},"prev":{"type":"string","format":"uri","nullable":true},"next":{"type":"string","format":"uri","nullable":true}}}}},"paths":{"/api/v1/scripts":{"get":{"summary":"List Scripts","description":"Retrieves a paginated list of scripts. Can be filtered by `name` and `versions.id`.","parameters":[{"name":"filter[name]","in":"query","required":false,"schema":{"type":"string"},"description":"Filter results by name."},{"name":"filter[versions.id]","in":"query","required":false,"schema":{"type":"string"},"description":"Filter results by versions.id."},{"name":"include","in":"query","required":false,"schema":{"type":"string"},"description":"Comma-separated list of relationships to include. Available: versions, versions.content, latestVersion, latestVersion.content"},{"name":"sort","in":"query","required":false,"schema":{"type":"string"},"description":"Sort field. Prefix with - for descending. Available: name"},{"name":"fields[versions]","in":"query","required":false,"schema":{"type":"string"},"description":"Comma-separated list of versions fields to return. Available: id, script_id, version, name, deployed_at, deployment_failed_at, deploying, deployment_failure_reason"},{"name":"page","in":"query","required":false,"schema":{"type":"integer","minimum":1,"default":1},"description":"Page number for pagination."},{"name":"per_page","in":"query","required":false,"schema":{"type":"integer","minimum":1,"maximum":100},"description":"Number of results per page."}],"responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScriptsListResponse"}}}},"401":{"description":"Unauthenticated"},"403":{"description":"Unauthorized"}},"tags":["Scripts"]}}}}
```

## Create Script

> Creates a new script.

```json
{"openapi":"3.0.0","info":{"title":"Patchworks Core API","version":"1.0.0"},"tags":[{"name":"Scripts"}],"servers":[{"url":"https://core.wearepatchworks.com"}],"security":[{"ApiKeyAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"API key passed in the Authorization header. Format: `<api-key>`"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"OAuth 2 Bearer token obtained from POST /fabric/api/login"}},"schemas":{"ScriptsResponse":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/Scripts"}}},"Scripts":{"type":"object","properties":{"id":{"type":"integer","description":"Unique identifier"},"script_template_id":{"type":"integer"},"name":{"type":"string"},"description":{"type":"string","items":{"type":"object"}},"language":{"type":"string","items":{"type":"object"}},"created_at":{"type":"string"},"updated_at":{"type":"string"},"script_id":{"type":"integer"},"version":{"type":"string"},"deployed_at":{"type":"string"},"deployment_failed_at":{"type":"string"},"deploying":{"type":"string"},"deployment_failure_reason":{"type":"string"},"content":{"type":"string"},"ai_created":{"type":"string","items":{"type":"object"}},"value":{"type":"string"},"versions":{"type":"array","items":{"type":"object"}},"latest_version":{"type":"object"}}},"ErrorResponse":{"type":"object","properties":{"message":{"type":"string"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}},"ScriptsStoreRequest":{"type":"object","properties":{"description":{"type":"string","maxLength":255,"nullable":true},"language":{"type":"string"},"ai_created":{"type":"string","nullable":true},"name":{"type":"string","maxLength":255}},"required":["language","name"]}}},"paths":{"/api/v1/scripts":{"post":{"summary":"Create Script","description":"Creates a new script.","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScriptsResponse"}}}},"401":{"description":"Unauthenticated"},"403":{"description":"Unauthorized"},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScriptsStoreRequest"}}}},"tags":["Scripts"],"parameters":[]}}}}
```

## Get Script

> Retrieves the details of a specific script.

```json
{"openapi":"3.0.0","info":{"title":"Patchworks Core API","version":"1.0.0"},"tags":[{"name":"Scripts"}],"servers":[{"url":"https://core.wearepatchworks.com"}],"security":[{"ApiKeyAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"API key passed in the Authorization header. Format: `<api-key>`"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"OAuth 2 Bearer token obtained from POST /fabric/api/login"}},"schemas":{"ScriptsResponse":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/Scripts"}}},"Scripts":{"type":"object","properties":{"id":{"type":"integer","description":"Unique identifier"},"script_template_id":{"type":"integer"},"name":{"type":"string"},"description":{"type":"string","items":{"type":"object"}},"language":{"type":"string","items":{"type":"object"}},"created_at":{"type":"string"},"updated_at":{"type":"string"},"script_id":{"type":"integer"},"version":{"type":"string"},"deployed_at":{"type":"string"},"deployment_failed_at":{"type":"string"},"deploying":{"type":"string"},"deployment_failure_reason":{"type":"string"},"content":{"type":"string"},"ai_created":{"type":"string","items":{"type":"object"}},"value":{"type":"string"},"versions":{"type":"array","items":{"type":"object"}},"latest_version":{"type":"object"}}}}},"paths":{"/api/v1/scripts/{script}":{"get":{"summary":"Get Script","description":"Retrieves the details of a specific script.","parameters":[{"name":"script","in":"path","required":true,"schema":{"type":"string"},"description":"The script identifier."},{"name":"filter[name]","in":"query","required":false,"schema":{"type":"string"},"description":"Filter results by name."},{"name":"filter[versions.id]","in":"query","required":false,"schema":{"type":"string"},"description":"Filter results by versions.id."},{"name":"include","in":"query","required":false,"schema":{"type":"string"},"description":"Comma-separated list of relationships to include. Available: versions, versions.content, latestVersion, latestVersion.content"},{"name":"sort","in":"query","required":false,"schema":{"type":"string"},"description":"Sort field. Prefix with - for descending. Available: name"},{"name":"fields[versions]","in":"query","required":false,"schema":{"type":"string"},"description":"Comma-separated list of versions fields to return. Available: id, script_id, version, name, deployed_at, deployment_failed_at, deploying, deployment_failure_reason"},{"name":"page","in":"query","required":false,"schema":{"type":"integer","minimum":1,"default":1},"description":"Page number for pagination."},{"name":"per_page","in":"query","required":false,"schema":{"type":"integer","minimum":1,"maximum":100},"description":"Number of results per page."}],"responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScriptsResponse"}}}},"401":{"description":"Unauthenticated"},"403":{"description":"Unauthorized"}},"tags":["Scripts"]}}}}
```

## Update Script

> Updates an existing script.

```json
{"openapi":"3.0.0","info":{"title":"Patchworks Core API","version":"1.0.0"},"tags":[{"name":"Scripts"}],"servers":[{"url":"https://core.wearepatchworks.com"}],"security":[{"ApiKeyAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"API key passed in the Authorization header. Format: `<api-key>`"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"OAuth 2 Bearer token obtained from POST /fabric/api/login"}},"schemas":{"ScriptsResponse":{"type":"object","properties":{"data":{"$ref":"#/components/schemas/Scripts"}}},"Scripts":{"type":"object","properties":{"id":{"type":"integer","description":"Unique identifier"},"script_template_id":{"type":"integer"},"name":{"type":"string"},"description":{"type":"string","items":{"type":"object"}},"language":{"type":"string","items":{"type":"object"}},"created_at":{"type":"string"},"updated_at":{"type":"string"},"script_id":{"type":"integer"},"version":{"type":"string"},"deployed_at":{"type":"string"},"deployment_failed_at":{"type":"string"},"deploying":{"type":"string"},"deployment_failure_reason":{"type":"string"},"content":{"type":"string"},"ai_created":{"type":"string","items":{"type":"object"}},"value":{"type":"string"},"versions":{"type":"array","items":{"type":"object"}},"latest_version":{"type":"object"}}},"ErrorResponse":{"type":"object","properties":{"message":{"type":"string"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}},"ScriptsUpdateRequest":{"type":"object","properties":{"description":{"type":"string","maxLength":255,"nullable":true},"language":{"type":"string"},"value":{"type":"string","minLength":1},"name":{"type":"string","maxLength":255}}}}},"paths":{"/api/v1/scripts/{script}":{"put":{"summary":"Update Script","description":"Updates an existing script.","parameters":[{"name":"script","in":"path","required":true,"schema":{"type":"string"},"description":"The script identifier."}],"responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScriptsResponse"}}}},"401":{"description":"Unauthenticated"},"403":{"description":"Unauthorized"},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScriptsUpdateRequest"}}}},"tags":["Scripts"]}}}}
```

## Delete Script

> Permanently deletes a specific script.

```json
{"openapi":"3.0.0","info":{"title":"Patchworks Core API","version":"1.0.0"},"tags":[{"name":"Scripts"}],"servers":[{"url":"https://core.wearepatchworks.com"}],"security":[{"ApiKeyAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"API key passed in the Authorization header. Format: `<api-key>`"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT","description":"OAuth 2 Bearer token obtained from POST /fabric/api/login"}},"schemas":{"MessageResponse":{"type":"object","properties":{"message":{"type":"string"}}}}},"paths":{"/api/v1/scripts/{script}":{"delete":{"summary":"Delete Script","description":"Permanently deletes a specific script.","parameters":[{"name":"script","in":"path","required":true,"schema":{"type":"string"},"description":"The script identifier."}],"responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"401":{"description":"Unauthenticated"},"403":{"description":"Unauthorized"}},"tags":["Scripts"]}}}}
```
