Add Document to Object

Add a new document to an object 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/objects/:id/docs

Permissions

upload-documents | create-documents | manage-documents | manage-objects

Path parameters

Parameter Type Description

id

String
required

The ID or the discovery ID of an object 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 CPU",
    "type_id": 6,
    "value": "https://en.wikipedia.org/wiki/Central_processing_unit"
}

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

{
    "file": (
        "cpu.pdf",
        open("/path/to/cpu.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":"cpu.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=<...>
object_id=<...>
url=https://$saymon_hostname/node/api/objects/$object_id/docs

curl -X POST $url -u $login:$password \
    -H "Content-Type: application/json" \
    -d @- <<EOF
{
    "name": "About CPU",
    "type_id": 6,
    "value": "https://en.wikipedia.org/wiki/Central_processing_unit"
}
EOF
let login = <...>
let password = <...>
let saymonHostname = <...>
let objectId = <...>
let path = "/node/api/objects/" + objectId + "/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 CPU",
    "type_id": 6,
    "value": "https://en.wikipedia.org/wiki/Central_processing_unit"
});

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 object_id = <...>
let url = "https://" + saymon_hostname + "/node/api/objects/" +
    object_id + "/docs";

let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");
let body = JSON.stringify({
    "name": "About CPU",
    "type_id": 6,
    "value": "https://en.wikipedia.org/wiki/Central_processing_unit"
});

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 = <...>
object_id = <...>
url = "https://" + saymon_hostname + "/node/api/objects/" + \
    object_id + "/docs";

body = {
"name": "About CPU",
"type_id": 6,
"value": "https://en.wikipedia.org/wiki/Central_processing_unit"
}

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=<...>
object_id=<...>
url=https://$saymon_hostname/node/api/objects/$object_id/docs

curl -F "file=@/path/to/cpu.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 objectId = <...>
let path = "https://" + saymon_hostname + "/node/api/objects/" +
    objectId + "/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 object_id = <...>
let url = "https://" + saymon_hostname + "/node/api/objects/" +
    object_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/cpu.pdf"),
        filetype: "pdf",
        filename: "cpu.pdf"
    }
};

request(options, function (error, response, body) {
    if (error) throw new Error(error);
    console.log(body);
});
import requests
import json

login = <...>
password = <...>
saymon_hostname = <...>
object_id = <...>
url = "https://" + saymon_hostname + "/node/api/objects/" + \
    object_id + "/docs";

files = {
    "file": (
        "cpu.pdf",
        open("/path/to/cpu.pdf", "rb"),
        "application/pdf"
    )
}

response = requests.request("POST", url, files=files, auth=(login, password))
print(response.text)

Response

{
    "name":"cpu.pdf",
    "value":"upload_29c7ddcbcd2de76e4b938d9845eeaaba",
    "type_id":7,
    "id":"62ed2bdb18baa649c1d25a1a"
}

See Also