Uploads and attaches a new file to the specified template using a multipart form submission.
Reference
POST https://YOUR-NETWORK-DOMAIN/rest-api/template/template-file/edit.do
Uploads and attaches a new file to the specified template using a multipart form submission. The file is stored with its original filename, MIME content type, and an MD5 checksum for integrity verification. The macro key for the file must be unique within the template and must not conflict with any reserved system macros or existing property keys. The template version is automatically incremented after the file is added. Requires edit permission on the template.
Query Params
templateIdintegerrequired
Unique numeric identifier of the template to add the file to
300
keystring
File key used in template content (format: $$KEY$$)
import fs from 'node:fs/promises';
const form = new FormData();
form.append('commonsMultipartFile', new Blob([await fs.readFile('logo.png')]), 'logo.png');
const response = await fetch('https://YOUR-NETWORK-DOMAIN/rest-api/template/template-file/edit.do?templateId=300&key=%24%24LOGO%24%24', {
method: 'POST',
headers: { 'X-Api-Key': 'YOUR_API_KEY' },
body: form,
});
console.log(await response.json());
Java Request
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://YOUR-NETWORK-DOMAIN/rest-api/template/template-file/edit.do?templateId=300&key=%24%24LOGO%24%24"))
.header("X-Api-Key", "YOUR_API_KEY")
// multipart upload: build the body with your HTTP library of choice
.method("POST", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
C# Request
using var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://YOUR-NETWORK-DOMAIN/rest-api/template/template-file/edit.do?templateId=300&key=%24%24LOGO%24%24");
request.Headers.Add("X-Api-Key", "YOUR_API_KEY");
var form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(File.ReadAllBytes("logo.png")), "commonsMultipartFile", "logo.png");
request.Content = form;
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
Go Request
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("POST", "https://YOUR-NETWORK-DOMAIN/rest-api/template/template-file/edit.do?templateId=300&key=%24%24LOGO%24%24", nil)
req.Header.Set("X-Api-Key", "YOUR_API_KEY")
// multipart upload: build the body with mime/multipart
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(string(out))
}