# Replace Document Content PATCH /api/v1/content-vault/documents/{document_id}/replace/ Content-Type: multipart/form-data Replace the entire content of a document while preserving its metadata and configuration. Supports file replacement with automatic reprocessing. Reference: https://docs.aisquare.studio/api-reference/ai-square-studio-api/content-vault/documents-replace-update ## OpenAPI Specification ```yaml openapi: 3.1.0 info: title: AISquare Studio API version: 1.0.0 paths: /api/v1/content-vault/documents/{document_id}/replace/: patch: operationId: documents-replace-partial-update summary: Replace Document Content description: >- Replace the entire content of a document while preserving its metadata and configuration. Supports file replacement with automatic reprocessing. tags: - subpackage_contentVault parameters: - name: document_id in: path description: Document ID required: true schema: type: integer responses: '200': description: Content replaced successfully content: application/json: schema: $ref: '#/components/schemas/RAGDocumentUpdate' '400': description: Validation error content: application/json: schema: description: Any type '401': description: Authentication required content: application/json: schema: description: Any type '404': description: Document not found or not owned by user content: application/json: schema: description: Any type requestBody: content: multipart/form-data: schema: type: object properties: document_name: type: - string - 'null' document_url: type: - string - 'null' content: type: - string - 'null' config: oneOf: - description: Any type - type: 'null' document_file: type: string format: uri components: schemas: RAGDocumentUpdate: type: object properties: document_name: type: - string - 'null' document_url: type: - string - 'null' content: type: - string - 'null' config: oneOf: - description: Any type - type: 'null' document_file: type: string format: uri description: Serializer for updating RAG documents title: RAGDocumentUpdate ``` ## SDK Code Examples ```python import requests url = "https://api.example.com/api/v1/content-vault/documents/1/replace/" payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_name\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"config\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_file\"\r\n\r\n\r\n-----011000010111000001101001--\r\n" headers = {"Content-Type": "multipart/form-data; boundary=---011000010111000001101001"} response = requests.patch(url, data=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.example.com/api/v1/content-vault/documents/1/replace/'; const form = new FormData(); form.append('document_name', ''); form.append('document_url', ''); form.append('content', ''); form.append('config', ''); form.append('document_file', ''); const options = {method: 'PATCH'}; options.body = form; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.example.com/api/v1/content-vault/documents/1/replace/" payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_name\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"config\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_file\"\r\n\r\n\r\n-----011000010111000001101001--\r\n") req, _ := http.NewRequest("PATCH", url, payload) res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.example.com/api/v1/content-vault/documents/1/replace/") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Patch.new(url) request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_name\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"config\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_file\"\r\n\r\n\r\n-----011000010111000001101001--\r\n" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.patch("https://api.example.com/api/v1/content-vault/documents/1/replace/") .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_name\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"config\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_file\"\r\n\r\n\r\n-----011000010111000001101001--\r\n") .asString(); ``` ```php request('PATCH', 'https://api.example.com/api/v1/content-vault/documents/1/replace/', [ 'headers' => [ 'Content-Type' => 'multipart/form-data; boundary=---011000010111000001101001', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.example.com/api/v1/content-vault/documents/1/replace/"); var request = new RestRequest(Method.PATCH); request.AddHeader("Content-Type", "multipart/form-data; boundary=---011000010111000001101001"); request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_name\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_url\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"content\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"config\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"document_file\"\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let parameters = [ [ "name": "document_name", "value": ], [ "name": "document_url", "value": ], [ "name": "content", "value": ], [ "name": "config", "value": ], [ "name": "document_file", "value": ] ] let boundary = "---011000010111000001101001" var body = "" var error: NSError? = nil for param in parameters { let paramName = param["name"]! body += "--\(boundary)\r\n" body += "Content-Disposition:form-data; name=\"\(paramName)\"" if let filename = param["fileName"] { let contentType = param["content-type"]! let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8) if (error != nil) { print(error as Any) } body += "; filename=\"\(filename)\"\r\n" body += "Content-Type: \(contentType)\r\n\r\n" body += fileContent } else if let paramValue = param["value"] { body += "\r\n\r\n\(paramValue)" } } let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/api/v1/content-vault/documents/1/replace/")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "PATCH" 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() ```