Добавить документ к связи
Запрос
Тело запроса
Чтобы добавить веб страницу как документ, нужно добавить ссылку на неё в параметр value
:
{
"name": "About Bus (Computing)",
"type_id": 6,
"value": "https://en.wikipedia.org/wiki/Bus_(computing)"
}
Чтобы загрузить файл, тело запроса должно содержать бинарный файл:
{
"file": (
"Bus_(computing).pdf",
open("/path/to/resources/Bus_(computing).pdf", "rb"),
"application/pdf"
)
}
Ответ
При привязке веб страницы, ответ будет содержать ID загруженного документа:
{
"id":"62ed29a618baa649c1d25a18"
}
При загрузке файла, ответ будет содержать информацию о загруженном документе:
{
"id":"62ed2bdb18baa649c1d25a1a"
"type_id":7,
"name":"Bus_(computing).pdf",
"value":"upload_29c7ddcbcd2de76e4b938d9845eeaaba",
}
Ответ может содержать следующие поля:
Параметр | Тип | Описание |
---|---|---|
id |
String |
ID документа. |
type_id |
Integer |
Тип загруженного документа. |
name |
String |
Имя документа. |
value |
String |
Внутренняя ссылка на документ. Хранит адреса для веб страниц и |
Примеры
Добавить ссылку на веб страницу
Запрос
-
Bash
-
JavaScript
-
NodeJS
-
Python
login=<...>
password=<...>
saymon_hostname=<...>
link_id=<...>
url=https://$saymon_hostname/node/api/links/$link_id/docs
curl -X POST $url -u $login:$password \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"name": "About Bus (Computing)",
"type_id": 6,
"value": "https://en.wikipedia.org/wiki/Bus_(computing)"
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let linkId = <...>
let path = "/node/api/links/" + linkId + "/docs";
let auth = "Basic " + btoa(login + ":" + password);
let headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("Authorization", auth);
let data = JSON.stringify({
"name": "About Bus (Computing)",
"type_id": 6,
"value": "https://en.wikipedia.org/wiki/Bus_(computing)"
});
let requestOptions = {
method: "POST",
headers: headers,
body: data
};
fetch(saymonHostname + path, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log("error", error));
const request = require("request");
const fs = require("fs");
let login = <...>
let password = <...>
let saymon_hostname = <...>
let link_id = <...>
let url = "https://" + saymon_hostname + "/node/api/links/" +
link_id + "/docs";
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let body = JSON.stringify({
"name": "About Bus (Computing)",
"type_id": 6,
"value": "https://en.wikipedia.org/wiki/Bus_(computing)"
});
let options = {
method: "POST",
url: url,
headers: {
Authorization: auth
},
json : body
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
});
import requests
import json
login = <...>
password = <...>
saymon_hostname = <...>
link_id = <...>
url = "https://" + saymon_hostname + "/node/api/links/" + \
link_id + "/docs"
body = {
"name": "About Bus (Computing)",
"type_id": 6,
"value": "https://en.wikipedia.org/wiki/Bus_(computing)"
}
response = requests.request("POST", url, json=body, auth=(login, password))
print(response.text)
Загрузить документ
Запрос
-
Bash
-
JavaScript
-
NodeJS
-
Python
login=<...>
password=<...>
saymon_hostname=<...>
link_id=<...>
url=https://$saymon_hostname/node/api/links/$link_id/docs
curl -F "file=@/path/to/Bus_(computing).pdf;type=application/pdf" $url \
-u $login:$password
The file can be selected with an HTML <input type="file" />
input element
let login = <...>
let password = <...>
let saymon_hostname = <...>
let linkId = <...>
let path = "https://" + saymon_hostname + "/node/api/links/" +
linkId + "/docs";
let auth = "Basic " + btoa(login + ":" + password);
let headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("Authorization", auth);
let formData = new FormData();
let fileField = document.querySelector('input[type="file"]');
formData.append('file', fileField.files[0]);
let requestOptions = {
method: "POST",
headers: headers,
body: formData
};
fetch(saymonHostname + path, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log("error", error));
const request = require("request");
const fs = require("fs");
let login = <...>
let password = <...>
let saymon_hostname = <...>
let link_id = <...>
let url = "https://" + saymon_hostname + "/node/api/links/" +
link_id + "/docs";
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let options = {
method: "POST",
url: url,
headers: {
Authorization: auth
},
formData: {
file: fs.createReadStream("/path/to/Bus_(computing).pdf"),
filetype: "pdf",
filename: "Bus_(computing).pdf"
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
import requests
import json
login = <...>
password = <...>
saymon_hostname = <...>
link_id = <...>
url = "https://" + saymon_hostname + "/node/api/links/" + \
link_id + "/docs"
files = {
"file": (
"Bus_(computing).pdf",
open("/path/to/resources/Bus_(computing).pdf", "rb"),
"application/pdf"
)
}
response = requests.request("POST", url, files=files, auth=(login, password))
print(response.text)