<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[XOA json-rpc call basic exemple]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">This is my first post here, I apologize  for its length.</p>
<p dir="auto">I'm trying to understand how to use xo-api call to perform some actions programmatically.</p>
<p dir="auto">I'm aware of how to use a ReST API but I don't know much about JSON-RPC.</p>
<p dir="auto">So I looked into xen-orchestra code base (expecially xo-cli, xo-lib, xo-server) and also the xen-orchestra terraform provider which I already use with success.</p>
<p dir="auto">Unfortunately I'm not enough well versed in JS nor Go to really understand how to correctly request the JSON-RPC API, not even even to sucesfully connect to the XOA (from source) instance via JSON-RPC.</p>
<p dir="auto">In fact, I'm not even sure of the exact exposed URL of the JSON-RPC API !</p>
<p dir="auto">I tried with my favorite language, Python3, using "jsonrpcclient" to connect passing module without success.</p>
<pre><code># Very basic json-rpc auth attempt

from jsonrpcclient import request

# url = 'wss://xoa.local.example.com'
# url = 'wss://xoa.local.example.com/api'
# url = 'https://xoa.local.example.com'
url = 'https://xoa.local.example.com/api'
credentials = {'email': 'test@example.com', 'password': 'testme'}

response = request(url, "signin", credentials=json.dumps(credentials)
</code></pre>
<p dir="auto">The above code fails on a misinterpretation of the XO server response. I guess the response is not JSON formated but more something like HTTP 302 response.</p>
<p dir="auto">I probably miss some very basic knowledge but can't find any direction.<br />
I need to know:</p>
<ul>
<li>What precise URL to call</li>
<li>What form and content should have the given parameters</li>
</ul>
<p dir="auto">Does someone could be kind enough to post a basic code snippet in another language than JS or Go that use the XOA JSON-RPC, even with plain cURL ?</p>
<p dir="auto">A sample like the following one would help me a lot to understand (the following code snippet is not working):</p>
<pre><code>curl --include \
     --no-buffer \
     -H "Host: xoa.local.example.com:443" \
     -H "Origin: https://xoa.local.example.com:443" \
     -H "Upgrade: websocket" \
     -H "Connection: Upgrade" \
     -H "content-type: application/json" \
     -H "Accept: application/json" \
     -X POST https://xoa.local.example.com/api \
     -d '{"method":"signin","credentials":{'email': 'test@example.com', 'password': 'testme'}}'

</code></pre>
]]></description><link>https://xcp-ng.org/forum/topic/4538/xoa-json-rpc-call-basic-exemple</link><generator>RSS for Node</generator><lastBuildDate>Sun, 15 Nov 2026 22:59:04 GMT</lastBuildDate><atom:link href="https://xcp-ng.org/forum/topic/4538.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Apr 2021 06:00:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Fri, 28 May 2021 23:16:35 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/mbaron" aria-label="Profile: mbaron">@<bdi>mbaron</bdi></a>,</p>
<p dir="auto">Your blog helped me to get a better understanding of the different steps involved in jsonrpc.</p>
<p dir="auto">Thank you for sharing your code samples.</p>
]]></description><link>https://xcp-ng.org/forum/post/39858</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39858</guid><dc:creator><![CDATA[mco-system]]></dc:creator><pubDate>Fri, 28 May 2021 23:16:35 GMT</pubDate></item><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Fri, 28 May 2021 17:40:46 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/mco-system" aria-label="Profile: mco-system">@<bdi>mco-system</bdi></a>,</p>
<p dir="auto">I propose to you a solution to communicate from a Python program to xo-server api.</p>
<pre><code>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') # email attribute is working in place of username
        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())
</code></pre>
<p dir="auto">This code is using the jsonrpc_websocket library.</p>
<p dir="auto">A full description is available on my blog =&gt; <a href="https://mickael-baron.fr/blog/2021/05/28/xo-server-websocket-jsonrcp" target="_blank" rel="noopener noreferrer nofollow ugc">https://mickael-baron.fr/blog/2021/05/28/xo-server-websocket-jsonrcp</a> (in french). A Java version is also available.</p>
]]></description><link>https://xcp-ng.org/forum/post/39846</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39846</guid><dc:creator><![CDATA[mbaron]]></dc:creator><pubDate>Fri, 28 May 2021 17:40:46 GMT</pubDate></item><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Mon, 03 May 2021 08:11:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/julien-f" aria-label="Profile: julien-f">@<bdi>julien-f</bdi></a>  Thank you for your help.</p>
<p dir="auto">I finally figured out that I missed the API endpoint trailing <code>/</code> which seems mandatory.</p>
<p dir="auto">My test with <code>openssl s_client</code> worked fine because the trailing <code>/</code> was in place:</p>
<pre><code>GET /api/ HTTP/1.1
</code></pre>
<p dir="auto">To  answer your advice about <code>xo-cli</code>, I don't need a CLI tool and <code>xo-cli</code> is fine when I need one.</p>
<p dir="auto">My goal is to determine what would be the needed efforts to code something like an <em>xo-api Python connector</em> that would allow requesting <em>xo-server</em> from <em>Python</em> apps and scripts.</p>
<p dir="auto">Such a connector would be useful to me  but also to all <em>Python</em>  coders.<br />
I'm seriously considering it.</p>
<p dir="auto">Thank you again for your time, it could have take me days to figure out this missing trailing <code>/</code>.</p>
]]></description><link>https://xcp-ng.org/forum/post/39164</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39164</guid><dc:creator><![CDATA[mco-system]]></dc:creator><pubDate>Mon, 03 May 2021 08:11:12 GMT</pubDate></item><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Fri, 30 Apr 2021 08:46:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/mco-system" aria-label="Profile: mco-system">@<bdi>mco-system</bdi></a> I don't know <code>wcat</code>, I just mentioned it because it looked interesting.</p>
<p dir="auto">I cannot explain how the WebSocket protocol works, all I can tell you is that XO API is JSON-RPC inside a WebSocket connection, and that before being able to use methods, you need to sign in via the <code>session.signIn</code> method:</p>
<pre><code># Open WebSocket connection to http://xoa/api/
→ {"id":0,"jsonrpc":"2.0","method":"session.signIn","params":{"username":"jsmith","password":"passw0rd"}}
← {"id":0,"jsonrpc":"2.0","result":{"id":"ad2593b0-97c7-446f-bc0e-f5558c013d52","email":"jsmith","groups":[],"permission":"admin","preferences":{}}}
</code></pre>
<p dir="auto">If all you need is a CLI, you can use <a href="https://xen-orchestra.com/docs/architecture.html#xo-cli-cli" target="_blank" rel="noopener noreferrer nofollow ugc"><code>xo-cli</code></a>.</p>
]]></description><link>https://xcp-ng.org/forum/post/39089</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39089</guid><dc:creator><![CDATA[julien-f]]></dc:creator><pubDate>Fri, 30 Apr 2021 08:46:17 GMT</pubDate></item><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Fri, 30 Apr 2021 06:47:09 GMT]]></title><description><![CDATA[<p dir="auto">Don't worry <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/mco-system" aria-label="Profile: mco-system">@<bdi>mco-system</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/julien-f" aria-label="Profile: julien-f">@<bdi>julien-f</bdi></a> will answer when he's around <img src="https://xcp-ng.org/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=566b705aef6" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
]]></description><link>https://xcp-ng.org/forum/post/39069</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39069</guid><dc:creator><![CDATA[olivierlambert]]></dc:creator><pubDate>Fri, 30 Apr 2021 06:47:09 GMT</pubDate></item><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Fri, 30 Apr 2021 02:40:08 GMT]]></title><description><![CDATA[<p dir="auto">Using <code>opensll s_client</code> I can connect and upgrade to WebSocket without any difficulties:</p>
<pre><code>openssl s_client -crlf -connect xoa.local.example.com:443 -servername xoa.local.exampe.com
CONNECTED(00000003)
depth=1 C = NC, ST = Somewhere, L = Shell-city, O = Example Co, OU = Lab, CN = Root CA example.com
verify return:1
depth=0 C = NC, ST = Somewhere, O = Example Co, CN = xoa.example.com
verify return:1


GET /api/ HTTP/1.1
Host: xoa.local.example.com:443
User-Agent: Go-http-client/1.1
Connection: Upgrade
Sec-WebSocket-Key: 7lcEMScTa7sTRzwW8jebLQ==
Sec-WebSocket-Version: 13
Upgrade: websocket

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: 5pKEtEmZTJbNiFx/gZ9VIMVy2B8=
</code></pre>
<p dir="auto">And the corresponding line in <code>syslog</code></p>
<pre><code>Apr 30 02:22:04 xoa xo-server[31752]: 2021-04-30T02:22:04.785Z xo:main INFO + WebSocket connection (192.168.2.1)
</code></pre>
<p dir="auto">So everything <strong>should</strong> work but I'm still missing something that I'm pretty sure is very simple. Some basic stuff that I can not see by myself....<br />
Very frustrating...</p>
]]></description><link>https://xcp-ng.org/forum/post/39063</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39063</guid><dc:creator><![CDATA[mco-system]]></dc:creator><pubDate>Fri, 30 Apr 2021 02:40:08 GMT</pubDate></item><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Fri, 30 Apr 2021 00:42:18 GMT]]></title><description><![CDATA[<p dir="auto">I successfully sniffed traffic between the <a href="https://github.com/terra-farm/terraform-provider-xenorchestra" target="_blank" rel="noopener noreferrer nofollow ugc">XOA Terraform provider</a> and I have now a better understanding of what a JSON-RPC requests looks like.</p>
<p dir="auto">However, I'm still unable to connect to the XO host with <code>wscat</code> which systematically timeouts .<br />
I can't get the <code>Connected (press CTRL+C to quit)</code> prompt from <code>wscat</code> as I would if the connection was successful.</p>
<p dir="auto">However, on XO host, I can see traffic using <code>tcpdump</code>, the problem does not seem network, nor SSL related.</p>
<pre><code>xoa:/opt/xo/xo-server# tcpdump -nni eth0 host 192.168.2.1 and not port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes


00:28:35.456615 IP 192.168.2.1.49074 &gt; 192.168.2.251.443: Flags [S], seq 3784699052, win 64240, options [mss 1460,sackOK,TS val 3147372683 ecr 0,nop,wscale 7], length 0
00:28:35.456660 IP 192.168.2.251.443 &gt; 192.168.2.1.49074: Flags [S.], seq 962165778, ack 3784699053, win 65160, options [mss 1460,sackOK,TS val 4217115831 ecr 3147372683,nop,wscale 7], length 0
00:28:35.456904 IP 192.168.2.1.49074 &gt; 192.168.2.251.443: Flags [.], ack 1, win 502, options [nop,nop,TS val 3147372684 ecr 4217115831], length 0
00:28:35.457104 IP 192.168.2.1.49074 &gt; 192.168.2.251.443: Flags [P.], seq 1:372, ack 1, win 502, options [nop,nop,TS val 3147372684 ecr 4217115831], length 371
00:28:35.457120 IP 192.168.2.251.443 &gt; 192.168.2.1.49074: Flags [.], ack 372, win 507, options [nop,nop,TS val 4217115831 ecr 3147372684], length 0
00:28:35.460902 IP 192.168.2.251.443 &gt; 192.168.2.1.49074: Flags [P.], seq 1:1672, ack 372, win 507, options [nop,nop,TS val 4217115835 ecr 3147372684], length 1671
00:28:35.461216 IP 192.168.2.1.49074 &gt; 192.168.2.251.443: Flags [.], ack 1672, win 495, options [nop,nop,TS val 3147372688 ecr 4217115835], length 0
00:28:35.462613 IP 192.168.2.1.49074 &gt; 192.168.2.251.443: Flags [P.], seq 372:700, ack 1672, win 501, options [nop,nop,TS val 3147372690 ecr 4217115835], length 328
00:28:35.463727 IP 192.168.2.251.443 &gt; 192.168.2.1.49074: Flags [P.], seq 1672:2214, ack 700, win 505, options [nop,nop,TS val 4217115838 ecr 3147372690], length 542
00:28:35.464040 IP 192.168.2.1.49074 &gt; 192.168.2.251.443: Flags [.], ack 2214, win 501, options [nop,nop,TS val 3147372691 ecr 4217115838], length 0
</code></pre>
<p dir="auto">In xo-server <code>config.toml</code>, I turned <code>verboseApiLogsOnErrors</code> to <code>true</code> and restarted the xo-server service but the log does not show any connection attempt.</p>
<p dir="auto">It's just like the connection is <em>lost</em> by the xo-server... I'm very confused...</p>
]]></description><link>https://xcp-ng.org/forum/post/39060</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39060</guid><dc:creator><![CDATA[mco-system]]></dc:creator><pubDate>Fri, 30 Apr 2021 00:42:18 GMT</pubDate></item><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Thu, 29 Apr 2021 19:54:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/julien-f" aria-label="Profile: julien-f">@<bdi>julien-f</bdi></a> Thank you for your reply.</p>
<p dir="auto">I tried <code>wscat</code> and I can see I'm successfully connected at TCP level as I would with a basic telnet client   but then I have no response from the server at all. until timeout occurs.</p>
<p dir="auto">Though, the xo terraform provider is working without problem, so I guess I'm doing something wrong or miss a very basic step at protocol level (i'm very new at using json-rpc).</p>
<p dir="auto">I also don't get how does the authentication mechanism work.<br />
Where and when send credentials to the API ?</p>
<p dir="auto">/me is currently reading <a href="https://www.jsonrpc.org/specification" target="_blank" rel="noopener noreferrer nofollow ugc">json-rpc specification </a></p>
]]></description><link>https://xcp-ng.org/forum/post/39054</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39054</guid><dc:creator><![CDATA[mco-system]]></dc:creator><pubDate>Thu, 29 Apr 2021 19:54:41 GMT</pubDate></item><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Thu, 29 Apr 2021 06:57:12 GMT]]></title><description><![CDATA[<p dir="auto">Maybe try something like <a href="https://github.com/websockets/wscat" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/websockets/wscat</a>, though I have no experience with it.</p>
]]></description><link>https://xcp-ng.org/forum/post/39017</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39017</guid><dc:creator><![CDATA[julien-f]]></dc:creator><pubDate>Thu, 29 Apr 2021 06:57:12 GMT</pubDate></item><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Thu, 29 Apr 2021 06:55:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/mco-system" aria-label="Profile: mco-system">@<bdi>mco-system</bdi></a> I don't know how to do a WebSocket call with <code>cURL</code>, it's probably not a simple HTTP request.</p>
]]></description><link>https://xcp-ng.org/forum/post/39016</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39016</guid><dc:creator><![CDATA[julien-f]]></dc:creator><pubDate>Thu, 29 Apr 2021 06:55:39 GMT</pubDate></item><item><title><![CDATA[Reply to XOA json-rpc call basic exemple on Thu, 29 Apr 2021 06:45:39 GMT]]></title><description><![CDATA[<p dir="auto">Pinging <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/julien-f" aria-label="Profile: julien-f">@<bdi>julien-f</bdi></a></p>
]]></description><link>https://xcp-ng.org/forum/post/39015</link><guid isPermaLink="true">https://xcp-ng.org/forum/post/39015</guid><dc:creator><![CDATA[olivierlambert]]></dc:creator><pubDate>Thu, 29 Apr 2021 06:45:39 GMT</pubDate></item></channel></rss>