Sign in

Most calls require an authToken. In normal conditions one authToken expires after one month.

Acquiring authToken
import requests
response = requests.post(
    endpoint + '/user/signInUsername',
    data = {'username':'user''password':'user123'}
)
authtoken = response.text

Files

Listing files
import requests
response = requests.get(
    endpoint + '/file/list',
    params = {'target': project_id},
    headers = {'authtoken': authtoken}
)
Download file
import requests
response = requests.get(
    endpoint + '/file/download',
    params = {'target': project_id, 'fileId': file_id},
    headers = {'authtoken': authtoken}
)

Or in an url: https://alpha.wvr.io/api/file/download?target=project_id&fileId=file_id (this only works if the authtoken is sent on the header)

Upload file
import requests
response = requests.post(
    endpoint + '/file/upload',
    params = {'target': project_id, 'filename': file_name},
    files = {'authToken': authtoken, 'file': (file_name, open(file_location, 'rb'), {'Expires''0'})}  // this lets python send a multipart upload
)
Delete file
import requests
response = requests.post(
    endpoint + '/file/delete',
    params = {'target': project_id, 'fileId': file_id}
)

Projects

Listing projects
import requests
response = requests.get(
    endpoint + '/project',
    headers = {'authtoken': authtoken}
)

Branches

This call is a little bit weird since it passes a GET call via a POST call

Listing branches
import requests
response = requests.post(endpoint + '/v2/projects',
    headers = {'authtoken': authtoken},
    data = {
        'method''GET',
        'path''/branches',
        'target''cksh5u98d002h1w6b1p09sbw6'
    }
)

Write

The nodes, attributes and relations in Weaver are created and updated using write operations. These are atomic operations that are sent to a branch in a project.

Sending write operations
import requests
response = requests.post(
    endpoint + '/write',
    headers = {
        'authToken': authtoken,                 # the authtoken
        'Content-Type''application/json'
    },
    data = json.dumps({
        "target""cksh5u98d002h1w6b1p09sbw6",  # the projectId
        "branch""main",                       # the branch
        "operations": [{                        # the write operations
            "action""create-node",
            "id""rdl:InstallDate",
            "graph""mixed-0"
        }]
    })
)

These are the supported write operations:

action
id
graph (*)
sourceId
sourceGraph (*)
key
value
dataType (*)
targetId
targetGraph (*)
replacesId
replacesGraph (*)
create-nodexx








remove-nodexx








create-attributexxxxxxx

x (*)x
remove-attribute








xx
create-relationidxxxx

xxx (*)x
remove-relation








xx

(*) optional


Plugins

NOTE: Interacting with plugins works from weaver-server version 6.1.1

Listing files
import requests
response = requests.get(
    endpoint + '/plugins',
)

This will not only list all available plugins but also their possible arguments.

Example:

[
  {
    "name""weaver-importer-exporter",
    "version""6.4.0-rc.0",
    "apiVersion""4.0.0",
    "author""[email protected]",
    "description""Import to and export from weaver",
    "functions": [
      {
        "route""plugin.function.weaver-importer-exporter.export",
...
        "signature": {
          "summary""Export to a file",
          "description""Exports data to a file using a profile",
          "operationId""export",
          "requestBody": {
            "content": {
              "multipart/form-data": {
                "schema": {
                  "required": [
                    "project",
                    "user"
                  ],
                  "properties": {
                    "project": {
                      "type""string",
                      "description""The id of the project to import into"
                    },
                    "user": {
                      "type""string",
                      "description""The authToken of a user to import as"
                    },
                    "profile": {
                      "type""string",
                      "description""The name of the profile. This determines how the excel file is read. Default is 'model-driven'."
                    },
                    "branch": {
                      "type""string",
                      "description""The branch uid",
                      "default""main"
                    },
                    "graph": {
                      "type""string",
                      "description""The graph the export should read from"
                    },
                    "config": {
                      "type""object",
                      "description""A stringified json containing any field the profile needs",
                      "default""undefined"
                    },
                    "zipped": {
                      "type""boolean",
                      "description""If the export should be zipped",
                      "default"true
                    }
...

The properties listed here can be sent as fields. The two fields project and user get sent in a different way using target and authToken:






Call function in plugin
projectId = weaver.currentProject().id()
authToken = Weaver.getInstance().currentUser().authToken
res = await supertest.agent(WEAVER_ENDPOINT)
.post('/plugin/function/weaver-importer-exporter/export')
# System fields
.field('target', projectId)
.field('authToken', authToken)
# Plugin fields
.field('profile''turtle')
res.status.should.equal(200)
report = await waitForPlugin(plugin, JSON.parse(res.text))
expectDone(report)