Add Document to Link

Add a new document to a link with the specified ID.

Document is a web-page or an uploaded file. You can see supported formats for uploaded files in the Property model description.

Request

HTTP Request

POST /node/api/links/:id/docs

Permissions

upload-documents | create-documents | manage-documents | manage-links

Path parameters

Parameter Type Description

id

String
required

The ID of a link for which a document should be added.

Request body

To add a web page as a document, specify a link to it in the value parameter of the request body.

{
  "name": "About Bus (Computing)",
  "type_id": 6,
  "value": "https://en.wikipedia.org/wiki/Bus_(computing)"
}

To upload a file, specify this in the request body:

{
    "file": (
        "Bus_(computing).pdf",
        open("/path/to/resources/Bus_(computing).pdf", "rb"),
        "application/pdf"
    )
}

Response

If you link a web page, the response will contain an id of an uploaded document:

{
    "id":"62ed29a618baa649c1d25a18"
}

If you upload a file, the response will contain a JSON representation of the uploaded document:

{
    "id":"62ed2bdb18baa649c1d25a1a"
    "type_id":7,
    "name":"Bus_(computing).pdf",
    "value":"upload_29c7ddcbcd2de76e4b938d9845eeaaba",
}

The response contains the following properties:

Name Type Description

id

String

ID of the document.

type_id

Integer

Type of an uploaded document — 6 for URLs, 7 for uploaded files.

name

String

Name of the document.

value

String

An internal link to the document. Stores URLs for web pages and upload_<...> for uploaded files.

Examples

Request

  • 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)

Response

{
    "id":"62ed29a618baa649c1d25a18"
}

Upload a document

Request

  • 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)

Response

{
    "name":"Bus_(computing).pdf",
    "value":"upload_29c7ddcbcd2de76e4b938d9845eeaaba",
    "type_id":7,
    "id":"62ed2bdb18baa649c1d25a1a"
}