Upload background image to an object

To set the custom image of an object via REST API, you need to upload the image to the SAYMON server and then assign its internal ID to the background field of an object with the Update Object request.

Uploaded file is stored in the /var/saymon/resources directory.
import requests

# Request settings
saymon_hostname = "<...>"
login = "<...>"
password = "<...>"
object_id = "<...>"
f = '<...>' # Path to the background image file

# Upload a background image to the server
url = "http://" + saymon_hostname + "/node-resources/images"

files = {
    "file": (f, open(f, "rb"), "image/*")
}

response = requests.post(url, files=files, auth=(login, password))
response.raise_for_status()

# Get the internal ID of the image from the response
internal_id = response.json()

# Set object's background image to the internal ID of the uploaded image
url = "http://" + saymon_hostname + "/node/api/objects/" + object_id

body = {
    "background": internal_id
}

response = requests.request("PATCH", url, auth=(login, password), json=body)
print(response.text)