Add Document to Flow

Adds a document for a flow 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/flows/:id/docs

Permissions

upload-documents | create-documents | manage-documents | manage-flows

Path parameters

Parameter Type Description

id

String
required

The ID of a flow 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": "Dataflow",
    "type_id": 6,
    "value": "https://en.wikipedia.org/wiki/Dataflow"
}

To upload a file, request body should contain a document in the binary format:

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

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

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

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

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

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

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

curl -u $login:$password \
    -F "file=@/path/to/Dataflow.pdf;type=application/pdf" $url

The file can be selected with an HTML <input type="file" /> input element

let login = <...>
let password = <...>
let saymon_hostname = <...>
let flowId = <...>
let path = "https://" + saymon_hostname + "/node/api/flows/" +
    flowId + "/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 flow_id = <...>
let url = "https://" + saymon_hostname + "/node/api/flows/" +
    flow_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/Dataflow.pdf"),
        filetype: "pdf",
        filename: "Dataflow.pdf"
    }
};

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

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

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

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

Response

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