Skip to content

Instantly share code, notes, and snippets.

@mickaelbaron
Last active February 4, 2022 13:19
Show Gist options
  • Save mickaelbaron/0388c530f2f55926e4e4a7e2213a9b10 to your computer and use it in GitHub Desktop.
Save mickaelbaron/0388c530f2f55926e4e4a7e2213a9b10 to your computer and use it in GitHub Desktop.
XOA json-rpc call basic example

A piece of code to communicate from a Python program to XO-Server API.

import json
import aiohttp
import asyncio

from jsonrpc_websocket import Server

async def routine():
  async with aiohttp.ClientSession() as client:
    server = Server('ws://XO_SERVER_IP/api/', client)

    await server.ws_connect()

    # No signIn required
    methodsInfoResult = await server.system.getMethodsInfo()
    print('\n'.join([str(e) for e in methodsInfoResult.keys()]))

    # signIn required
    result = await server.session.signIn(username='YOUR_LOGIN', password='YOUR_PASSWORD')
    result = await server.xo.getAllObjects(filter={"type": "VIF"}, limit=10)

    print('[')
    print(', \n'.join([str(json.dumps(e, indent=4)) for e in result.values()]))
    print(']')

asyncio.get_event_loop().run_until_complete(routine())

This code is using the jsonrpc_websocket_ library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment