Export of items generated via Openhab rest api to txt (items) file

Raspi 4 4GB, raspbian buster, OH 2.5.12
OpenJDK Runtime Environment Zulu Embedded 8.25.0.76

Hi,
if I generate a block of new items via python script using OH2 rest api put command a lot of items are generated internally to OH2.
Is it possible to export this internally stored “items” to a txt file, or direct .items file please ?
Thanks for help.

Python example:

import requests
from requests.auth import HTTPBasicAuth
import json

base_url = "http://ip:8080"
auth = HTTPBasicAuth('pi', 'pw')
headers = {"Content-type": "application/json", "Accept": "application/json"}

url = base_url + "/rest/items/ai_1_IN01"
data = {"type": "Contact", "name": "ai_1_IN01", "label": "ai_1_IN01", "groupNames": ["AGVolt"], "-d": ["OPEN"]}
data = json.dumps(data)
print(data)

try:
    response = requests.put(url, auth=auth, data=data, headers=headers, timeout=8)
    response.raise_for_status()
    print(response)
except requests.exceptions.HTTPError as errh:
    print(errh)
except requests.exceptions.ConnectionError as errc:
    print(errc)
except requests.exceptions.Timeout as errt:
    print(errt)
except requests.exceptions.RequestException as err:
    print(err)

There’s a some scripts posted to the forum here and there that do this to some extent. I’m not sure why you would just modify your Python script to create the .items file in the first place if that’s what you are after in the end.

1 Like

Thanks Rich. Yes I can modify the script to generate .items like txt file.