<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><atom:link href="https://zato.io/en/blog/rss.xml" rel="self"/><lastBuildDate>Fri, 03 Apr 2026 03:00:00 +0000</lastBuildDate><title>Python API Integration Insights with Zato</title><link>https://zato.io/en/blog</link><description>Zato - ESB, API, AI and Cloud Integrations in Python.</description><item><title>SSH API Service in Python</title><link>https://zato.io/en/blog/ssh-api-service.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/ssh-api-service.html&quot;&gt;SSH API Service in Python&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2026-01-12, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;This is a quick guide on how to turn SSH commands into a REST API service. The use-case may be remote administration
of devices or equipment that does not offer a REST interface or making sure that access to SSH commands is restricted
to selected external REST-based API clients only.&lt;/p&gt;
&lt;h2 id=&quot;python&quot;&gt;Python&lt;/h2&gt;
&lt;p&gt;The first thing needed is code of the service that will connect to SSH servers. Below is a service doing just that -
it receives name of the command to execute and host to run in on, translating stdout and stderr of SSH commands
into response documents which Zato in turn serializes to JSON.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# stdlib&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;traceback&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;format_exc&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SSHInvoker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot; Accepts an SSH command to run on a remote host and returns its output to caller.&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# A list of elements that we expect on input&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;host&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;command&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# A list of elements that our responses will contain&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;is_ok&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cid&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;-stdout&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;-stderr&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Local aliases&lt;/span&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;host&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Correlation ID is always returned&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Build the full command&lt;/span&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;full_command&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;ssh &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Run the command and collect output&lt;/span&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;commands&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;invoke&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;full_command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Assign both stdout and stderr to response&lt;/span&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stderr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stderr&lt;/span&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;Exception&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-40&quot; name=&quot;line-0-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Catch any exception and log it&lt;/span&gt;
&lt;a id=&quot;line-0-41&quot; name=&quot;line-0-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Exception caught (&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;), e:`&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;format_exc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;a id=&quot;line-0-42&quot; name=&quot;line-0-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-43&quot; name=&quot;line-0-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Indicate an error&lt;/span&gt;
&lt;a id=&quot;line-0-44&quot; name=&quot;line-0-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_ok&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;False&lt;/span&gt;
&lt;a id=&quot;line-0-45&quot; name=&quot;line-0-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-46&quot; name=&quot;line-0-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-47&quot; name=&quot;line-0-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Everything went fine&lt;/span&gt;
&lt;a id=&quot;line-0-48&quot; name=&quot;line-0-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_ok&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;dashboard&quot;&gt;Dashboard&lt;/h2&gt;
&lt;p&gt;In the Zato Dashboard, let&#x27;s go ahead and create an HTTP Basic Auth definition that a remote API client will authenticate against:&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-ssh/basic-auth-menu.png&quot;/&gt;
&lt;/center&gt;

&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-ssh/basic-auth-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Now, the SSH service can be mounted on a newly created REST channel - note the security definition used and that data format is set to JSON.
We can skip all the other details such as caching or rate limiting, for illustration purposes, this is not needed.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-ssh/rest-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-ssh/rest-form.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;
&lt;p&gt;At this point, everything is ready to use. We could make it accessible to external API clients but, for testing purposes,
let&#x27;s simply invoke our SSH API gateway service from the command line:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;api:password@localhost:11223/api/ssh&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-d&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;{&amp;quot;host&amp;quot;:&amp;quot;localhost&amp;quot;, &amp;quot;command&amp;quot;:&amp;quot;uptime&amp;quot;}&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;is_ok&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;true,
&lt;a id=&quot;line-1-5&quot; name=&quot;line-1-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;cid&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;27406f29c66c2ab6296bc0c0&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-1-6&quot; name=&quot;line-1-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;stdout&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot; 09:45:42 up 37 min,  1 user,  load average: 0.14, 0.27, 0.18\n&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-1-7&quot; name=&quot;line-1-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
Note that, at this stage, the service should be used in trusted environments only, e.g. it will run any command that it is given
on input which means that in the next iteration it could be changed to only allow commands from an allow-list, rejecting
anything that is not recognized.&lt;/p&gt;
&lt;p&gt;And this completes it - the service is deployed and made accessible via a REST channel that can be invoked using JSON.
Any command can be sent to any host and their output will be returned to API callers in JSON responses.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 12 Jan 2026 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/ssh-api-service.html</guid></item><item><title>Python scheduler for API integrations</title><link>https://zato.io/en/blog/python-scheduler.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/python-scheduler.html&quot;&gt;Python scheduler for API integrations&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2026-01-05, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;Are you looking for a practical way to automate API tasks with reliable scheduling?
This &lt;a href=&quot;https://zato.io/en/tutorials/python-scheduler.html&quot;&gt;tutorial&lt;/a&gt;
demonstrates how to implement
task scheduling using Zato within Docker.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://zato.io/en/tutorials/python-scheduler.html&quot;&gt;guide&lt;/a&gt; focuses on real-world implementation rather than theory, showing you how to build scheduling solutions that work consistently in production environments.&lt;/p&gt;
&lt;p&gt;What you&#x27;ll learn in the tutorial:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to set up a Python scheduler with Docker&lt;/li&gt;
&lt;li&gt;Creating services that run on precise intervals (as short as 5 seconds)&lt;/li&gt;
&lt;li&gt;Techniques for API automation, SQL database integration, and Bash script execution&lt;/li&gt;
&lt;li&gt;DevOps practices for maintaining scheduled jobs across environments&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/en/tutorials/python-scheduler.html&quot;&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/python-scheduler/python-scheduler.jpg&quot;
    class=&quot;img-responsive docs-article&quot;
    style=&quot;width:60%&quot;
    alt=&quot;Python Scheduler&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/network-packet-broker.html&quot;&gt;What is a Network Packet Broker? How to automate networks in Python?&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 05 Jan 2026 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/python-scheduler.html</guid></item><item><title>Modern REST API Tutorial in Python</title><link>https://zato.io/en/blog/modern-rest-api-tutorial-in-python.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/modern-rest-api-tutorial-in-python.html&quot;&gt;Modern REST API Tutorial in Python&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-12-22, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;Great APIs don&#x27;t win theoretical arguments - they just prefer to work reliably and to make developers&#x27; lives easier.&lt;/p&gt;
&lt;p&gt;Here&#x27;s a tutorial on what building production APIs is really about: creating interfaces that are practical in usage,
while keeping your systems maintainable for years to come.&lt;/p&gt;
&lt;p&gt;Sound intriguing? Read the &lt;a href=&quot;https://zato.io/en/tutorials/rest-api/python.html&quot;&gt;modern REST API tutorial in Python here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/en/tutorials/rest-api/python.html&quot;&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/modern-rest-apis/modern-rest-apis.webp&quot;
    class=&quot;img-responsive docs-article&quot;
    alt=&quot;Modern REST API tutorial in Python&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/network-packet-broker.html&quot;&gt;What is a Network Packet Broker? How to automate networks in Python?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 22 Dec 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/modern-rest-api-tutorial-in-python.html</guid></item><item><title>Microsoft Dataverse with Python and Zato Services</title><link>https://zato.io/en/blog/dataverse-in-python.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/dataverse-in-python.html&quot;&gt;Microsoft Dataverse with Python and Zato Services&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-12-15, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/en/docs/4.1/gfx/api/dev/examples/dataverse.png&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;Microsoft Dataverse is a cloud-based data storage and management platform, often used with PowerApps and Dynamics 365.&lt;/p&gt;
&lt;p&gt;Integrating Dataverse with Python via Zato enables automation, API orchestration, and seamless CRUD (Create, Read, Update, Delete) operations on any Dataverse object.&lt;/p&gt;
&lt;p&gt;Below, you&#x27;ll find practical code examples for working with Dataverse from Python, including detailed comments and explanations. The focus is on the &quot;accounts&quot; entity, but the same approach applies to any object in Dataverse.&lt;/p&gt;
&lt;h2 id=&quot;connecting-to-dataverse-and-retrieving-accounts&quot;&gt;Connecting to Dataverse and retrieving accounts&lt;/h2&gt;
&lt;p&gt;The main service class configures the Dataverse client and retrieves all accounts. Both the &lt;code&gt;handle&lt;/code&gt; and &lt;code&gt;get_accounts&lt;/code&gt; methods are shown together for clarity.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.common.typing_&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;any_&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DataverseClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Set up Dataverse credentials - in a real service,&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# this would go to your configuration file.&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;tenant_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;221de69a-602d-4a0b-a0a4-1ff2a3943e9f&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;client_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;17aaa657-557c-4b18-95c3-71d742fbc6a3&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;client_secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;MjsrO1zc0.WEV5unJCS5vLa1&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;org_url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;https://org123456.api.crm4.dynamics.com&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Build the Dataverse client using the credentials&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DataverseClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;tenant_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tenant_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;client_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;client_secret&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client_secret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;org_url&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;org_url&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Retrieve all accounts using a helper method&lt;/span&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;accounts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_accounts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Process the accounts as needed (custom logic goes here)&lt;/span&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get_accounts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;DataverseClient&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;any_&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Specify the API path for the accounts entity&lt;/span&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;accounts&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Call the Dataverse API to retrieve all accounts&lt;/span&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-40&quot; name=&quot;line-0-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-41&quot; name=&quot;line-0-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Log the response for debugging/auditing&lt;/span&gt;
&lt;a id=&quot;line-0-42&quot; name=&quot;line-0-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-43&quot; name=&quot;line-0-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Dataverse response (get accounts): &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-44&quot; name=&quot;line-0-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-45&quot; name=&quot;line-0-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Return the API response to the caller&lt;/span&gt;
&lt;a id=&quot;line-0-46&quot; name=&quot;line-0-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;@odata.context&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;https://org1234567.crm4.dynamics.com/api/data/v9.0/$metadata#accounts&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;value&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;@odata.etag&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;W/&amp;quot;11122233&amp;quot;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;territorycode&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;accountid&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;d92e6f18-36fb-4fa8-b7c2-ecc7cc28f50c&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Zato Test Account 1&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;_owninguser_value&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;ea4dd84c-dee6-405d-b638-c37b57f00938&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}]}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Let&#x27;s check more examples - you&#x27;ll note they all follow the same pattern as the first one.&lt;/p&gt;
&lt;h2 id=&quot;retrieving-an-account-by-id&quot;&gt;Retrieving an Account by ID&lt;/h2&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get_account_by_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;DataverseClient&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;account_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;str&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;any_&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Construct the API path using the account&amp;#39;s GUID&lt;/span&gt;
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;accounts(&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;account_id&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;)&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-5&quot; name=&quot;line-2-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-6&quot; name=&quot;line-2-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Call the Dataverse API to fetch the account&lt;/span&gt;
&lt;a id=&quot;line-2-7&quot; name=&quot;line-2-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-8&quot; name=&quot;line-2-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-9&quot; name=&quot;line-2-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Log the response for traceability&lt;/span&gt;
&lt;a id=&quot;line-2-10&quot; name=&quot;line-2-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Dataverse response (get account by ID): &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-11&quot; name=&quot;line-2-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-12&quot; name=&quot;line-2-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Return the fetched account&lt;/span&gt;
&lt;a id=&quot;line-2-13&quot; name=&quot;line-2-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;retrieving-an-account-by-name&quot;&gt;Retrieving an account by name&lt;/h2&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;get_account_by_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;DataverseClient&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;account_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;str&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;any_&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-3-2&quot; name=&quot;line-3-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-3&quot; name=&quot;line-3-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Construct the API path with a filter for the account name&lt;/span&gt;
&lt;a id=&quot;line-3-4&quot; name=&quot;line-3-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;accounts?$filter=name eq &amp;#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;account_name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;#39;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-3-5&quot; name=&quot;line-3-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-6&quot; name=&quot;line-3-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Call the Dataverse API with the filter&lt;/span&gt;
&lt;a id=&quot;line-3-7&quot; name=&quot;line-3-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-3-8&quot; name=&quot;line-3-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-9&quot; name=&quot;line-3-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Log the response for auditing&lt;/span&gt;
&lt;a id=&quot;line-3-10&quot; name=&quot;line-3-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Dataverse response (get account by name): &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-3-11&quot; name=&quot;line-3-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-12&quot; name=&quot;line-3-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Return the filtered account(s)&lt;/span&gt;
&lt;a id=&quot;line-3-13&quot; name=&quot;line-3-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;creating-a-new-account&quot;&gt;Creating a new account&lt;/h2&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-4-1&quot; name=&quot;line-4-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;create_account&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;DataverseClient&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;any_&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-4-2&quot; name=&quot;line-4-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-3&quot; name=&quot;line-4-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Specify the API path for account creation&lt;/span&gt;
&lt;a id=&quot;line-4-4&quot; name=&quot;line-4-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;accounts&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-4-5&quot; name=&quot;line-4-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-6&quot; name=&quot;line-4-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Prepare the data for the new account&lt;/span&gt;
&lt;a id=&quot;line-4-7&quot; name=&quot;line-4-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;account_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-4-8&quot; name=&quot;line-4-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;New Test Account&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-9&quot; name=&quot;line-4-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;s1&quot;&gt;&amp;#39;telephone1&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;+1-555-123-4567&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-10&quot; name=&quot;line-4-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;s1&quot;&gt;&amp;#39;emailaddress1&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;hello@example.com&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-11&quot; name=&quot;line-4-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;s1&quot;&gt;&amp;#39;address1_city&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Prague&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-12&quot; name=&quot;line-4-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;s1&quot;&gt;&amp;#39;address1_country&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Czech Republic&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-13&quot; name=&quot;line-4-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-4-14&quot; name=&quot;line-4-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-15&quot; name=&quot;line-4-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Call the Dataverse API to create the account&lt;/span&gt;
&lt;a id=&quot;line-4-16&quot; name=&quot;line-4-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;account_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-4-17&quot; name=&quot;line-4-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-18&quot; name=&quot;line-4-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Log the response for traceability&lt;/span&gt;
&lt;a id=&quot;line-4-19&quot; name=&quot;line-4-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Dataverse response (create account): &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-4-20&quot; name=&quot;line-4-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-21&quot; name=&quot;line-4-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Return the API response&lt;/span&gt;
&lt;a id=&quot;line-4-22&quot; name=&quot;line-4-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;updating-an-existing-account&quot;&gt;Updating an existing account&lt;/h2&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-5-1&quot; name=&quot;line-5-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;update_account&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;DataverseClient&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;account_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;str&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;any_&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-5-2&quot; name=&quot;line-5-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-5-3&quot; name=&quot;line-5-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Prepare the data to update&lt;/span&gt;
&lt;a id=&quot;line-5-4&quot; name=&quot;line-5-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;update_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-5-5&quot; name=&quot;line-5-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Updated Account Name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-5-6&quot; name=&quot;line-5-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;s1&quot;&gt;&amp;#39;telephone1&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;+1-555-987-6543&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-5-7&quot; name=&quot;line-5-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;s1&quot;&gt;&amp;#39;emailaddress1&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;hello2@example.com&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-5-8&quot; name=&quot;line-5-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-5-9&quot; name=&quot;line-5-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-5-10&quot; name=&quot;line-5-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Call the Dataverse API to update the account by ID&lt;/span&gt;
&lt;a id=&quot;line-5-11&quot; name=&quot;line-5-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;patch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;accounts(&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;account_id&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;)&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;update_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-5-12&quot; name=&quot;line-5-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-5-13&quot; name=&quot;line-5-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Log the response for auditing&lt;/span&gt;
&lt;a id=&quot;line-5-14&quot; name=&quot;line-5-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Dataverse response (update account): &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-5-15&quot; name=&quot;line-5-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-5-16&quot; name=&quot;line-5-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Return the updated account response&lt;/span&gt;
&lt;a id=&quot;line-5-17&quot; name=&quot;line-5-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;deleting-an-account&quot;&gt;Deleting an Account&lt;/h2&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-6-1&quot; name=&quot;line-6-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;delete_account&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;DataverseClient&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;account_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;str&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;any_&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-6-2&quot; name=&quot;line-6-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-6-3&quot; name=&quot;line-6-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Call the Dataverse API to delete the account&lt;/span&gt;
&lt;a id=&quot;line-6-4&quot; name=&quot;line-6-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;accounts(&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;account_id&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;)&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-6-5&quot; name=&quot;line-6-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-6-6&quot; name=&quot;line-6-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Log the response for traceability&lt;/span&gt;
&lt;a id=&quot;line-6-7&quot; name=&quot;line-6-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Dataverse response (delete account): &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-6-8&quot; name=&quot;line-6-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-6-9&quot; name=&quot;line-6-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Return the API response&lt;/span&gt;
&lt;a id=&quot;line-6-10&quot; name=&quot;line-6-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;api-path-vs-powerapps-ui-table-names&quot;&gt;API path vs. PowerApps UI table names&lt;/h2&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/en/docs/4.1/gfx/api/dev/examples/dataverse-table.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;A detail to note when working with Dataverse APIs is that the names you see in the PowerApps or Dynamics UI are not
always the same as the paths expected by the API. For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In PowerApps, you may see a table called &lt;strong&gt;Account&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the API, you must use the path &lt;strong&gt;accounts&lt;/strong&gt; (lowercase, plural) when making requests.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This pattern applies to all Dataverse objects: always check the API documentation or inspect the metadata to determine the correct entity path.&lt;/p&gt;
&lt;h2 id=&quot;working-with-other-dataverse-objects&quot;&gt;Working with other Dataverse objects&lt;/h2&gt;
&lt;p&gt;While the examples above focus on the &quot;accounts&quot; entity, the same approach applies to any object in Dataverse: contacts, leads,
opportunities, custom tables, and more. Simply adjust the API path and payload as needed.&lt;/p&gt;
&lt;h2 id=&quot;full-crud-support&quot;&gt;Full CRUD Support&lt;/h2&gt;
&lt;p&gt;With Zato and Python, you get full CRUD (Create, Read, Update, Delete) capability for any Dataverse entity. The methods
shown above can be adapted for any object, allowing you to automate, integrate, and orchestrate data flows across your organization.&lt;/p&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;This article has shown how to connect to Microsoft Dataverse from Python using Zato, perform CRUD operations,
and understand the mapping between UI and API paths. These techniques enable robust integration and automation scenarios with any Dataverse data.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ &lt;a href=&quot;https://zato.io/en/tutorials/microsoft/365.html&quot;&gt;Microsoft 365 APIs and Python Tutorial&lt;/a&gt;
&lt;br/&gt;
➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 15 Dec 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/dataverse-in-python.html</guid></item><item><title>Automate Microsoft 365 like a pro: skip the OAuth headaches</title><link>https://zato.io/en/blog/automate-microsoft-365-in-python.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/automate-microsoft-365-in-python.html&quot;&gt;Automate Microsoft 365 like a pro: skip the OAuth headaches&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-12-08, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;Are you tired of fighting with Microsoft 365 APIs and complex authentication flows? This
&lt;a href=&quot;https://zato.io/en/tutorials/microsoft/365.html&quot;&gt;practical tutorial&lt;/a&gt;
cuts through the complexity,
showing you how to build production-ready Python automations for Outlook, Calendar, and SharePoint in just 60 minutes.&lt;/p&gt;
&lt;p&gt;No OAuth2 struggles, no Graph API complexity - just working code you can deploy today.&lt;/p&gt;
&lt;p&gt;What you&#x27;ll learn in the &lt;a href=&quot;https://zato.io/en/tutorials/microsoft/365.html&quot;&gt;tutorial&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Connect to Microsoft 365 APIs with minimal Python code&lt;/li&gt;
&lt;li&gt;Build real email, calendar, and SharePoint automations&lt;/li&gt;
&lt;li&gt;Schedule background tasks without programming&lt;/li&gt;
&lt;li&gt;Access Entra ID (Azure AD) user data effortlessly&lt;/li&gt;
&lt;li&gt;Implement enterprise-grade patterns that solve actual business problems&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/en/tutorials/microsoft/365.html&quot;&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/automate-microsoft-365/automate-microsoft-365-vertical.webp&quot;
    class=&quot;img-responsive docs-article&quot;
    style=&quot;width:60%&quot;
    alt=&quot;Automate Microsoft 365 in Python&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/network-packet-broker.html&quot;&gt;What is a Network Packet Broker? How to automate networks in Python?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 08 Dec 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/automate-microsoft-365-in-python.html</guid></item><item><title>Network packet broker automation in Python</title><link>https://zato.io/en/blog/network-packet-broker-automation-python.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/network-packet-broker-automation-python.html&quot;&gt;Network packet broker automation in Python&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-12-01, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/articles/network-packet-broker/what-is-a-network-packet-broker.png&quot;
    class=&quot;img-responsive docs-article&quot;
    alt=&quot;What is a network packet broker and what does it do?&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Packet brokers are crucial for network engineers, providing a clear, detailed view of network traffic,
aiding in efficient issue identification and resolution.&lt;/p&gt;
&lt;p&gt;But what is a network packet broker (NBP) really? Why are they needed? And how to automate one in Python?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;➤ Read this article about &lt;a href=&quot;https://zato.io/articles/network-packet-broker.html&quot;&gt;network packet brokers&lt;/a&gt;&lt;/strong&gt; and their automation in Python to find out more.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ &lt;a href=&quot;https://zato.io/en/industry/telecom/index.html&quot;&gt;Click here&lt;/a&gt; to read more about using Python and Zato in telecommunications
&lt;br/&gt;
➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 01 Dec 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/network-packet-broker-automation-python.html</guid></item><item><title>Automation in Python</title><link>https://zato.io/en/blog/automation-in-python.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/automation-in-python.html&quot;&gt;Automation in Python&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-11-24, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;How to automate systems in Python and how the Zato &lt;a href=&quot;https://zato.io/index.html&quot;&gt;Python integration platform&lt;/a&gt; differs from a network
automation tool, how to start using it, along with a couple of examples of integrations with
Office 365 and Jira, is what the latest article is about.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;➤ Read it here: &lt;a href=&quot;https://zato.io/articles/automation-in-python.html&quot;&gt;Systems Automation in Python&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/articles/automation-in-python.html&quot;&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/en/docs/4.1/gfx/api/networks/network-architecture.png&quot;
    class=&quot;img-responsive docs-article&quot;
    alt=&quot;Systems Automation in Python&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/articles/automation-in-python.html&quot;&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/en/docs/4.1/gfx/api/networks/scope-comparison.png&quot;
    class=&quot;img-responsive docs-article&quot;
    alt=&quot;Systems Automation in Python&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 24 Nov 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/automation-in-python.html</guid></item><item><title>Enterprise gRPC Services with Python and Zato</title><link>https://zato.io/en/blog/enterprise-grpc-integrations.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/enterprise-grpc-integrations.html&quot;&gt;Enterprise gRPC Services with Python and Zato&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-07-22, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;gRPC is a high-performance framework for building distributed systems and microservices. It leverages Protocol
Buffers for serialization and HTTP/2 for transport, making it ideal for production environments
requiring low-latency communication.&lt;/p&gt;
&lt;p&gt;This Python integration with Zato demonstrates how to build scalable gRPC services with strongly-typed schemas. The approach enables efficient API orchestration and reliable data exchange between services using type-safe contracts.&lt;/p&gt;
&lt;p&gt;Below you&#x27;ll find a Protocol Buffer schema definition and an enterprise-ready API integration service showing end-to-end implementation.&lt;/p&gt;
&lt;h2 id=&quot;protocol-buffer-schema-definition&quot;&gt;Protocol buffer schema definition&lt;/h2&gt;
&lt;p&gt;First, define your gRPC service contract using Protocol Buffers. This example shows a mandate registration service - a financial
services process where a customer authorizes a merchant or service provider to automatically collect recurring payments
from their bank account.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;syntax&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;proto3&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;debit_mandate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kd&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MandateRegistrationService&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;rpc&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RegisterMandate&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MandateRegistrationRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;returns&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MandateActionResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MandateCollectionFrequencyType&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MANDATE_COLLECTION_FREQUENCY_TYPE_UNSPECIFIED&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MANDATE_COLLECTION_FREQUENCY_TYPE_DAILY&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MANDATE_COLLECTION_FREQUENCY_TYPE_WEEKLY&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MANDATE_COLLECTION_FREQUENCY_TYPE_MONTHLY&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CurrencyCode&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;CURRENCY_CODE_UNSPECIFIED&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;CURRENCY_CODE_EUR&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kd&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MoneyObject&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CurrencyCode&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;currency_code&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;positive_value&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;uint32&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;units&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;uint32&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;nanos&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kd&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MandateRegistrationRequest&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;debtor_name&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MandateCollectionFrequencyType&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;collection_frequency&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MoneyObject&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;instalment_amount&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;debtor_identity_number&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;bank_account_number&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kd&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MandateActionResponse&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;uint32&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;response_code&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;response_description&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;enabling-grpc-in-zato-projects&quot;&gt;Enabling gRPC in Zato Projects&lt;/h2&gt;
&lt;p&gt;To use gRPC in your integration services, add the required dependencies to
&lt;a href=&quot;https://zato.io/en/tutorials/devops/deployment.html&quot;&gt;your project&#x27;s requirements file&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;# config/python-reqs/requirements.txt
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;grpcio&amp;gt;=1.50.0
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;grpcio-tools&amp;gt;=1.50.0
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;protobuf&amp;gt;=4.21.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;When your container starts, these dependencies will be automatically installed and available to your service.&lt;/p&gt;
&lt;h2 id=&quot;zato-service-integration&quot;&gt;Zato service integration&lt;/h2&gt;
&lt;p&gt;Create a Zato service that uses the gRPC client with proper input handling:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# stdlib&lt;/span&gt;
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;dataclasses&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dataclass&lt;/span&gt;
&lt;a id=&quot;line-2-5&quot; name=&quot;line-2-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-6&quot; name=&quot;line-2-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-2-7&quot; name=&quot;line-2-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-2-8&quot; name=&quot;line-2-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-9&quot; name=&quot;line-2-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# gRPC Code&lt;/span&gt;
&lt;a id=&quot;line-2-10&quot; name=&quot;line-2-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;debit_mandate_pb2&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MANDATE_COLLECTION_FREQUENCY_TYPE_MONTHLY&lt;/span&gt;
&lt;a id=&quot;line-2-11&quot; name=&quot;line-2-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;debit_mandate_client&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MandateClient&lt;/span&gt;
&lt;a id=&quot;line-2-12&quot; name=&quot;line-2-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-13&quot; name=&quot;line-2-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-2-14&quot; name=&quot;line-2-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-15&quot; name=&quot;line-2-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;nd&quot;&gt;@dataclass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-16&quot; name=&quot;line-2-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MandateRegistrationRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-17&quot; name=&quot;line-2-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;debtor_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;
&lt;a id=&quot;line-2-18&quot; name=&quot;line-2-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;debtor_identity_number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;
&lt;a id=&quot;line-2-19&quot; name=&quot;line-2-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;bank_account_number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;
&lt;a id=&quot;line-2-20&quot; name=&quot;line-2-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;collection_frequency&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;
&lt;a id=&quot;line-2-21&quot; name=&quot;line-2-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;amount_units&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;
&lt;a id=&quot;line-2-22&quot; name=&quot;line-2-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-23&quot; name=&quot;line-2-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;nd&quot;&gt;@dataclass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-24&quot; name=&quot;line-2-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MandateRegistrationResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-25&quot; name=&quot;line-2-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;
&lt;a id=&quot;line-2-26&quot; name=&quot;line-2-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;details&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;
&lt;a id=&quot;line-2-27&quot; name=&quot;line-2-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-28&quot; name=&quot;line-2-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-2-29&quot; name=&quot;line-2-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-30&quot; name=&quot;line-2-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MandateRegistrationService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-31&quot; name=&quot;line-2-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-32&quot; name=&quot;line-2-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Use API models&lt;/span&gt;
&lt;a id=&quot;line-2-33&quot; name=&quot;line-2-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MandateRegistrationRequest&lt;/span&gt;
&lt;a id=&quot;line-2-34&quot; name=&quot;line-2-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MandateRegistrationResponse&lt;/span&gt;
&lt;a id=&quot;line-2-35&quot; name=&quot;line-2-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-36&quot; name=&quot;line-2-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-37&quot; name=&quot;line-2-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-38&quot; name=&quot;line-2-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Local variables&lt;/span&gt;
&lt;a id=&quot;line-2-39&quot; name=&quot;line-2-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;
&lt;a id=&quot;line-2-40&quot; name=&quot;line-2-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-41&quot; name=&quot;line-2-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get a client for the gRPC endpoint ..&lt;/span&gt;
&lt;a id=&quot;line-2-42&quot; name=&quot;line-2-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MandateClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-2-43&quot; name=&quot;line-2-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-44&quot; name=&quot;line-2-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-45&quot; name=&quot;line-2-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. invoke the endpoint ..&lt;/span&gt;
&lt;a id=&quot;line-2-46&quot; name=&quot;line-2-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;grpc_response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register_mandate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;a id=&quot;line-2-47&quot; name=&quot;line-2-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;debtor_name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;debtor_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-2-48&quot; name=&quot;line-2-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;debtor_identity_number&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;debtor_identity_number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-2-49&quot; name=&quot;line-2-49&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-49&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;49 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;bank_account_number&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bank_account_number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-2-50&quot; name=&quot;line-2-50&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-50&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;50 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;collection_frequency&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;collection_frequency&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-2-51&quot; name=&quot;line-2-51&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-51&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;51 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;amount_units&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amount_units&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-2-52&quot; name=&quot;line-2-52&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-52&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;52 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-53&quot; name=&quot;line-2-53&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-53&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;53 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-54&quot; name=&quot;line-2-54&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-54&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;54 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. map its response to ours ..&lt;/span&gt;
&lt;a id=&quot;line-2-55&quot; name=&quot;line-2-55&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-55&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;55 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MandateRegistrationResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-2-56&quot; name=&quot;line-2-56&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-56&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;56 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grpc_response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response_code&lt;/span&gt;
&lt;a id=&quot;line-2-57&quot; name=&quot;line-2-57&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-57&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;57 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;details&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grpc_response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response_description&lt;/span&gt;
&lt;a id=&quot;line-2-58&quot; name=&quot;line-2-58&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-58&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;58 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-59&quot; name=&quot;line-2-59&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-59&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;59 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. and return it to the caller.&lt;/span&gt;
&lt;a id=&quot;line-2-60&quot; name=&quot;line-2-60&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-60&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;60 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;
&lt;a id=&quot;line-2-61&quot; name=&quot;line-2-61&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-61&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;61 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-62&quot; name=&quot;line-2-62&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-62&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;62 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-63&quot; name=&quot;line-2-63&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-63&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;63 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;testing-the-integration&quot;&gt;Testing the Integration&lt;/h2&gt;
&lt;p&gt;Once deployed, you can invoke your Zato service through a REST endpoint:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-X&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;POST&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;http://localhost:17010/api/mandate/register&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-3-2&quot; name=&quot;line-3-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;-H&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Content-Type: application/json&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-3-3&quot; name=&quot;line-3-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;-d&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;{&lt;/span&gt;
&lt;a id=&quot;line-3-4&quot; name=&quot;line-3-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;    &amp;quot;debtor_name&amp;quot;: &amp;quot;John Doe&amp;quot;,&lt;/span&gt;
&lt;a id=&quot;line-3-5&quot; name=&quot;line-3-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;    &amp;quot;debtor_identity_number&amp;quot;: &amp;quot;123456789&amp;quot;,&lt;/span&gt;
&lt;a id=&quot;line-3-6&quot; name=&quot;line-3-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;    &amp;quot;bank_account_number&amp;quot;: &amp;quot;GB29NWBK60161331926819&amp;quot;,&lt;/span&gt;
&lt;a id=&quot;line-3-7&quot; name=&quot;line-3-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;    &amp;quot;collection_frequency&amp;quot;: 3,&lt;/span&gt;
&lt;a id=&quot;line-3-8&quot; name=&quot;line-3-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;    &amp;quot;amount_units&amp;quot;: 100&lt;/span&gt;
&lt;a id=&quot;line-3-9&quot; name=&quot;line-3-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;  }&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The service returns a structured JSON response:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-4-1&quot; name=&quot;line-4-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;status&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;details&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Mandate registered successfully&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Tue, 22 Jul 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/enterprise-grpc-integrations.html</guid></item><item><title>Enterprise Python: integrating with Salesforce</title><link>https://zato.io/en/blog/salesforce-python.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/salesforce-python.html&quot;&gt;Enterprise Python: integrating with Salesforce&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-06-02, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/en/customer-success/keysight/salesforce.html&quot;&gt;Salesforce connections&lt;/a&gt; are one of the newest additions to
Zato
3.2, allowing you to look up and manage Salesforce records
and other business data. To showcase it, the article will create a sample Salesforce marketing campaign in a way that
does not require the usage of anything else except for basic REST APIs combined with plain Python objects, such as dicts.&lt;/p&gt;
&lt;p&gt;If you have not done it already, you can &lt;a href=&quot;https://zato.io/en/docs/4.1/admin/guide/install/index.html&quot;&gt;download Zato here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;basic-workflow&quot;&gt;Basic workflow&lt;/h2&gt;
&lt;p&gt;The scope of our works will be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Creating Salesforce credentials for our integration project&lt;/li&gt;
&lt;li&gt;Defining a Salesforce connection in Zato&lt;/li&gt;
&lt;li&gt;Authoring a service that will map input data to the format that Salesforce expects&lt;/li&gt;
&lt;li&gt;Creating a Zato REST channel that will be invoked through curl during tests&lt;/li&gt;
&lt;li&gt;Testing the integration&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;creating-salesforce-credentials&quot;&gt;Creating Salesforce credentials&lt;/h2&gt;
&lt;p&gt;To be able to create as connection to Salesforce in the next step, we need a few credentials. There is
&lt;a href=&quot;https://zato.io/en/blog/salesforce-credentials.html&quot;&gt;a full article&lt;/a&gt;
about how to prepare them and this section is the gist of it.&lt;/p&gt;
&lt;p&gt;In runtime,
based on this information, Zato will obtain the necessary authentication and authorization tokens itself,
which means that you will only focus on the business side of the integrations, not on the low-level
aspects of it.&lt;/p&gt;
&lt;p&gt;The process of obtaining the credentials needs to be coordinated with an administrator of your organization.
To assist in that, the screenshots below explain where to find them.&lt;/p&gt;
&lt;p&gt;The credentials are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Username and password&lt;/li&gt;
&lt;li&gt;Consumer key&lt;/li&gt;
&lt;li&gt;Consumer secret&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The username and password are simply the same credentials that can be used to log in to Salesforce:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/salesforce-login.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Consumer key and secret are properties of a &lt;strong&gt;connected app&lt;/strong&gt; - this is a term that Salesforce uses for API
clients that invoke its services. If you are already an experienced Salesforce REST API user, you may know
the key and secret under their aliases of &quot;client_id&quot; and &quot;client_secret&quot; - these are the same objects.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/salesforce-app-manager.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Note that when a connected app already exists and you would like to retrieve the key and secret, they will be available
under the &quot;View&quot; menu option for the app, not under &quot;Edit&quot; or &quot;Manage&quot;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/salesforce-app-credentials.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;defining-a-salesforce-connection-in-zato&quot;&gt;Defining a Salesforce connection in Zato&lt;/h2&gt;
&lt;p&gt;With all the credentials in place, we can create a new Salesforce connection in Zato Dashboard, as below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/zato-sf-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/zato-sf-form-create.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;authoring-an-integration-service-in-python&quot;&gt;Authoring an integration service in Python&lt;/h2&gt;
&lt;p&gt;Above, we created a connection definition that lets Zato obtain session tokens and establish connections to Salesforce.
Now, we can create an API service that will make use of such connections.&lt;/p&gt;
&lt;p&gt;In the example below, we are using the POST REST method to invoke an endpoint that creates new Salesforce campaigns.
In your own integrations, you can invoke any other Salesforce endpoint, using any REST method as needed, by following the same
pattern, which is, create a model with input fields, build a Python dict for the request to Salesforce, invoke it
and map all the required from the response from Salesforce to that which your own service returns to its own callers.&lt;/p&gt;
&lt;p&gt;Note that we use a datamodel-based &lt;a href=&quot;https://zato.io/en/docs/4.1/dev/model/index.html&quot;&gt;SimpleIO&lt;/a&gt; definition for the service.
Among other things, although we are not going to do it here, this would let us offer definitions for this and other services.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# stdlib&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;dataclasses&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dataclass&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.connection.salesforce&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SalesforceClient&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;nd&quot;&gt;@dataclass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CreateCampaignRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;    &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;segment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;nd&quot;&gt;@dataclass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CreateCampaignResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;campaign_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CreateCampaign&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SimpleIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CreateCampaignRequest&lt;/span&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CreateCampaignResponse&lt;/span&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# This is our input data&lt;/span&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# type: CreateCampaignRequest&lt;/span&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-40&quot; name=&quot;line-0-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Salesforce REST API endpoint to invoke - note that Zato&lt;/span&gt;
&lt;a id=&quot;line-0-41&quot; name=&quot;line-0-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# will add a prefix to it containing the API version.&lt;/span&gt;
&lt;a id=&quot;line-0-42&quot; name=&quot;line-0-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/sobjects/Campaign/&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-43&quot; name=&quot;line-0-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-44&quot; name=&quot;line-0-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Build the request to Salesforce based on what we received&lt;/span&gt;
&lt;a id=&quot;line-0-45&quot; name=&quot;line-0-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-46&quot; name=&quot;line-0-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;          &lt;span class=&quot;s1&quot;&gt;&amp;#39;Name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-47&quot; name=&quot;line-0-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;          &lt;span class=&quot;s1&quot;&gt;&amp;#39;Segment__c&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;segment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-48&quot; name=&quot;line-0-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-49&quot; name=&quot;line-0-49&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-49&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;49 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-50&quot; name=&quot;line-0-50&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-50&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;50 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. create a reference to our connection definition ..&lt;/span&gt;
&lt;a id=&quot;line-0-51&quot; name=&quot;line-0-51&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-51&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;51 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;salesforce&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salesforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My Salesforce Connection&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-52&quot; name=&quot;line-0-52&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-52&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;52 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-53&quot; name=&quot;line-0-53&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-53&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;53 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. obtain a client to Salesforce ..&lt;/span&gt;
&lt;a id=&quot;line-0-54&quot; name=&quot;line-0-54&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-54&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;54 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salesforce&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# type: SalesforceClient&lt;/span&gt;
&lt;a id=&quot;line-0-55&quot; name=&quot;line-0-55&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-55&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;55 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-56&quot; name=&quot;line-0-56&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-56&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;56 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. create the campaign now ..&lt;/span&gt;
&lt;a id=&quot;line-0-57&quot; name=&quot;line-0-57&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-57&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;57 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;sf_response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-58&quot; name=&quot;line-0-58&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-58&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;58 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-59&quot; name=&quot;line-0-59&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-59&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;59 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. build our response object ..&lt;/span&gt;
&lt;a id=&quot;line-0-60&quot; name=&quot;line-0-60&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-60&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;60 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CreateCampaignResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-0-61&quot; name=&quot;line-0-61&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-61&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;61 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;campaign_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sf_response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-62&quot; name=&quot;line-0-62&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-62&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;62 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-63&quot; name=&quot;line-0-63&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-63&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;63 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. and return its ID to our caller.&lt;/span&gt;
&lt;a id=&quot;line-0-64&quot; name=&quot;line-0-64&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-64&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;64 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;
&lt;a id=&quot;line-0-65&quot; name=&quot;line-0-65&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-65&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;65 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-66&quot; name=&quot;line-0-66&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-66&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;66 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;creating-a-rest-channel&quot;&gt;Creating a REST channel&lt;/h2&gt;
&lt;p&gt;Note that we assign HTTP Basic Auth credentials to the channel. In this manner, it is possible for clients of this REST
channel to authenticate using a method that they are already familiar which simplifies everyone&#x27;s work - it is Zato that deals
with how to authenticate against Salesforce whereas your API clients use the ubiquitous HTTP Basic Auth method.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/zato-rest-menu.png&quot;/&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/zato-rest-form-create.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;testing&quot;&gt;Testing&lt;/h2&gt;
&lt;p&gt;The last step is to invoke the newly created channel:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;http://api:password@localhost:17010/api/campaign/create&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-d&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;{&amp;quot;name&amp;quot;:&amp;quot;Hello&amp;quot;, &amp;quot;segment&amp;quot;:&amp;quot;123&amp;quot;}&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;campaign_id&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;8901Z3VHXDTebEJWs&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That is everything - you have just integrated with Salesforce and exposed a REST channel for external applications to integrate
with!&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 02 Jun 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/salesforce-python.html</guid></item><item><title>Sustainable water management with IoT, Open Source and Python</title><link>https://zato.io/en/blog/sustainable-water.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/sustainable-water.html&quot;&gt;Sustainable water management with IoT, Open Source and Python&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-04-29, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://link.springer.com/article/10.1007/s12652-021-03656-1&quot;&gt;&lt;strong&gt;&quot;Towards a cyber-physical system for sustainable and smart building: a use case for optimizing water consumption on a SmartCampus&quot;&lt;/strong&gt;&lt;/a&gt; is an interesting, Open Access paper via Springer Publishing authored by
Sergio Barroso Ramírez,
Pablo Bustos
and
Pedro Núñez Trujillo
of
&lt;a href=&quot;https://www.unex.es&quot;&gt;Universidad de Extremadura&lt;/a&gt; uses Python, Zato and other open source technologies for IoT integrations.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://link.springer.com/article/10.1007/s12652-021-03656-1&quot;&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-water-management/water.jpeg&quot;/&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Pytho&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Tue, 29 Apr 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/sustainable-water.html</guid></item><item><title>Integrating with Jira APIs</title><link>https://zato.io/en/blog/jira-python-api.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/jira-python-api.html&quot;&gt;Integrating with Jira APIs&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-04-24, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;Continuing in the series of articles about newest cloud connections in Zato 4.1, this episode covers Atlassian Jira
from the perspective of invoking its APIs to build integrations between Jira and other systems.&lt;/p&gt;
&lt;p&gt;There are essentially two use modes of integrations with Jira:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Jira reacts to events taking place in your projects and invokes your endpoints accordingly via WebHooks.
   In this case, it is Jira that explicitly establishes connections with and sends requests to your APIs.&lt;/li&gt;
&lt;li&gt;Jira projects are queried periodically or as a consequence of events triggered by Jira using means other than WebHooks.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-atlassian/jira-integrations.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;The first case is usually more straightforward to conceptualize - you create a WebHook in Jira, point it to your endpoint
and Jira invokes it when a situation of interest arises, e.g. a new ticket is opened or updated. I will talk about this variant
of integrations with Jira in a future instalment as the current one is about the other situation, when it is your systems
that establish connections with Jira.&lt;/p&gt;
&lt;p&gt;The reason why it is more practical to first speak about the second form is that, even if WebHooks are somewhat easier
to reason about, they do come with their own ramifications.&lt;/p&gt;
&lt;p&gt;To start off, assuming that you use the cloud-based version of
Jira (e.g. https://example.atlassian.net), you need to have a publicly available endpoint for Jira to invoke through WebHooks.
Very often, this is undesirable because the systems that you need to integrate with may be internal ones, never meant
to be exposed to public networks.&lt;/p&gt;
&lt;p&gt;Secondly, your endpoints need to have a TLS certificate signed by a public Certificate Authority and they need to be accessible
on port 443. Again, both of these are something that most enterprise systems will not allow at all or it may take months
or years to process such a change internally across the various corporate departments involved.&lt;/p&gt;
&lt;p&gt;Lastly, even if a WebHook can be used, it is not always a given that the initial information that you receive in the request
from a WebHook will already contain everything that you need in your particular integration service. Thus, you will still
need a way to issue requests to Jira to look up details of a particular object, such as tickets, in this way reducing
WebHooks to the role of initial triggers of an interaction with Jira, e.g. a WebHook invokes your endpoint,
you have a ticket ID on input and then you invoke Jira back anyway to obtain all the details that you
actually need in your business integration.&lt;/p&gt;
&lt;p&gt;The end situation is that, although WebHooks are a useful concept that I will write about in a future article,
they may very well not be sufficient for many integration use cases. That is why I start with integration
methods that are alternative to WebHooks.&lt;/p&gt;
&lt;h2 id=&quot;alternatives-to-webhooks&quot;&gt;Alternatives to WebHooks&lt;/h2&gt;
&lt;p&gt;If, in our case, we cannot use WebHooks then what next? Two good approaches are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Scheduled jobs&lt;/li&gt;
&lt;li&gt;Reacting to emails (via IMAP)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Scheduled jobs will let you periodically inquire with Jira about the changes that you have not processed yet. For instance,
with a job definition as below:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-atlassian/jira-scheduler-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-atlassian/jira-scheduler-sample.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Now, the service configured for this job will be invoked once per minute to carry out any integration works required.
For instance, it can get a list of tickets since the last time it ran, process each of them as required in your business context
and update a database with information about what has been just done - the database can be based on Redis, MongoDB, SQL or anything
else.&lt;/p&gt;
&lt;p&gt;Integrations built around scheduled jobs make most sense when you need to make periodic sweeps across a large swaths of business
data, these are the &quot;Give me everything that changed in the last period&quot; kind of interactions when you do not know precisely
how much data you are going to receive.&lt;/p&gt;
&lt;p&gt;In the specific case of Jira tickets, though, an interesting alternative may be to combine scheduled jobs with IMAP connections:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-atlassian/jira-imap-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-atlassian/jira-imap-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;The idea here is that when new tickets are opened, or when updates are made to existing ones, Jira will send out notifications
to specific email addresses and we can take advantage of it.&lt;/p&gt;
&lt;p&gt;For instance, you can tell Jira to CC or BCC an address such as zato@example.com. Now, Zato will still run a scheduled job
but instead of connecting with Jira directly, that job will look up unread emails for it inbox
(&quot;UNSEEN&quot; per the relevant
&lt;a href=&quot;https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol&quot;&gt;RFC&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Anything that is unread must be new since the last iteration which means that we can process each such email from the inbox, in this way
guaranteeing that we process only the latest updates, dispensing with the need for our own database of tickets already processed.
We can extract the ticket ID or other details from the email, look up its details in Jira and the continue as needed.&lt;/p&gt;
&lt;p&gt;All the details of how to work with IMAP emails are provided in the documentation but it would boil down to this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My Jira Inbox&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Process the message here ..&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;process_message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. and mark it as seen in IMAP.&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mark_seen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The natural question is - how would the &quot;process_message&quot; function extract details of a ticket from an email?&lt;/p&gt;
&lt;p&gt;There are several ways:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Each email has a subject of a fixed form - &quot;[JIRA] (ABC-123) Here goes description&quot;. In this case, ABC-123 is the ticket ID.&lt;/li&gt;
&lt;li&gt;Each email will contain a summary, such as the one below, which can also be parsed:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;         &lt;/span&gt;Summary:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Here&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;goes&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;description
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;             &lt;/span&gt;Key:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;ABC-123
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;             &lt;/span&gt;URL:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;https://example.atlassian.net/browse/ABC-123
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;         &lt;/span&gt;Project:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;My&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Project
&lt;a id=&quot;line-1-5&quot; name=&quot;line-1-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;      &lt;/span&gt;Issue&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Type:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Improvement
&lt;a id=&quot;line-1-6&quot; name=&quot;line-1-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;Affects&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Versions:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;.3.17
&lt;a id=&quot;line-1-7&quot; name=&quot;line-1-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;     &lt;/span&gt;Environment:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Production
&lt;a id=&quot;line-1-8&quot; name=&quot;line-1-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;        &lt;/span&gt;Reporter:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Reporter&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Name
&lt;a id=&quot;line-1-9&quot; name=&quot;line-1-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;        &lt;/span&gt;Assignee:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Assignee&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;Finally, each email will have an &quot;X-Atl-Mail-Meta&quot; header with interesting metadata that can also be parsed and extracted:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;X-Atl-Mail-Meta:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;123456:12d80508-dcd0-42a2-a2cd-c07f230030e5&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;                 &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;event_type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Issue Created&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;                 &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;tenant&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://example.atlassian.net&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The first option is the most straightforward and likely the most convenient one - simply parse out the ticket ID and
call Jira with that ID on input for all the other information about the ticket. How to do it exactly is presented in the
next chapter.&lt;/p&gt;
&lt;p&gt;Regardless of how we parse the emails, the important part is that we know that we invoke Jira only when there are new or updated
tickets - otherwise there would not have been any new emails to process. Moreover, because it is our side that invokes Jira,
we do not expose our internal system to the public network directly.&lt;/p&gt;
&lt;p&gt;However, from the perspective of the overall security architecture, email is still part of the attack surface so we need to make
sure that we read and parse emails with that in view. In other words, regardless of whether it is Jira invoking us
or our reading emails from Jira, all the usual security precautions regarding API integrations and accepting input from external
resources, all that still holds and needs to be part of the design of the integration workflow.&lt;/p&gt;
&lt;h2 id=&quot;creating-jira-connections&quot;&gt;Creating Jira connections&lt;/h2&gt;
&lt;p&gt;The above presented the ways in which we can arrive at the step of when we invoke Jira and now we are ready to actually do it.&lt;/p&gt;
&lt;p&gt;As with other types of connections, Jira connections are created in Zato Dashboard, as below. Note that you use the email
address of a user on whose behalf you connect to Jira but the only other credential is that user&#x27;s API token previously
generated in Jira, not the user&#x27;s password.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-atlassian/jira-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-atlassian/jira-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-atlassian/jira-change-api-token.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;invoking-jira&quot;&gt;Invoking Jira&lt;/h2&gt;
&lt;p&gt;With a Jira connection in place, we can now create a Python API service. In this case, we accept a ticket ID on input
(called &quot;a key&quot; in Jira) and we return a few details about the ticket to our caller.&lt;/p&gt;
&lt;p&gt;This is the kind of a service that could be invoked from a service that is triggered by a scheduled job. That is,
we would separate the tasks, one service would be responsible for opening IMAP inboxes and parsing emails
and the one below would be responsible for communication with Jira.&lt;/p&gt;
&lt;p&gt;Thanks to this loose coupling, we make everything much more reusable - that the services can be changed independently is but one part
and the more important side is that, with such separation, both of them can be reused by future services as well,
without tying them rigidly to this one integration alone.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-3-2&quot; name=&quot;line-3-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-3&quot; name=&quot;line-3-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# stdlib&lt;/span&gt;
&lt;a id=&quot;line-3-4&quot; name=&quot;line-3-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;dataclasses&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dataclass&lt;/span&gt;
&lt;a id=&quot;line-3-5&quot; name=&quot;line-3-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-6&quot; name=&quot;line-3-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-3-7&quot; name=&quot;line-3-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.common.typing_&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cast_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dictnone&lt;/span&gt;
&lt;a id=&quot;line-3-8&quot; name=&quot;line-3-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-3-9&quot; name=&quot;line-3-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-10&quot; name=&quot;line-3-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-3-11&quot; name=&quot;line-3-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-12&quot; name=&quot;line-3-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-3-13&quot; name=&quot;line-3-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.connection.jira_&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;JiraClient&lt;/span&gt;
&lt;a id=&quot;line-3-14&quot; name=&quot;line-3-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-15&quot; name=&quot;line-3-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-3-16&quot; name=&quot;line-3-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-17&quot; name=&quot;line-3-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;nd&quot;&gt;@dataclass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-3-18&quot; name=&quot;line-3-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GetTicketDetailsRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-19&quot; name=&quot;line-3-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;
&lt;a id=&quot;line-3-20&quot; name=&quot;line-3-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-21&quot; name=&quot;line-3-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;nd&quot;&gt;@dataclass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-3-22&quot; name=&quot;line-3-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GetTicketDetailsResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-23&quot; name=&quot;line-3-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;assigned_to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-3-24&quot; name=&quot;line-3-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;progress_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dictnone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;None&lt;/span&gt;
&lt;a id=&quot;line-3-25&quot; name=&quot;line-3-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-26&quot; name=&quot;line-3-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-3-27&quot; name=&quot;line-3-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-28&quot; name=&quot;line-3-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GetTicketDetails&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-29&quot; name=&quot;line-3-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-30&quot; name=&quot;line-3-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SimpleIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-3-31&quot; name=&quot;line-3-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetTicketDetailsRequest&lt;/span&gt;
&lt;a id=&quot;line-3-32&quot; name=&quot;line-3-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetTicketDetailsResponse&lt;/span&gt;
&lt;a id=&quot;line-3-33&quot; name=&quot;line-3-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-34&quot; name=&quot;line-3-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-35&quot; name=&quot;line-3-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-36&quot; name=&quot;line-3-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# This is our input data&lt;/span&gt;
&lt;a id=&quot;line-3-37&quot; name=&quot;line-3-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# type: GetTicketDetailsRequest&lt;/span&gt;
&lt;a id=&quot;line-3-38&quot; name=&quot;line-3-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-39&quot; name=&quot;line-3-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. create a reference to our connection definition ..&lt;/span&gt;
&lt;a id=&quot;line-3-40&quot; name=&quot;line-3-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;jira&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;jira&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My Jira Connection&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-3-41&quot; name=&quot;line-3-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-42&quot; name=&quot;line-3-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. obtain a client to Jira ..&lt;/span&gt;
&lt;a id=&quot;line-3-43&quot; name=&quot;line-3-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;jira&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-3-44&quot; name=&quot;line-3-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-45&quot; name=&quot;line-3-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Cast to enable code completion&lt;/span&gt;
&lt;a id=&quot;line-3-46&quot; name=&quot;line-3-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cast_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;JiraClient&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-3-47&quot; name=&quot;line-3-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-48&quot; name=&quot;line-3-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Get details of a ticket (issue) from Jira&lt;/span&gt;
&lt;a id=&quot;line-3-49&quot; name=&quot;line-3-49&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-49&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;49 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;ticket&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_issue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-3-50&quot; name=&quot;line-3-50&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-50&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;50 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-51&quot; name=&quot;line-3-51&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-51&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;51 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Observe that ticket may be None (e.g. invalid key), hence this &amp;#39;if&amp;#39; guard ..&lt;/span&gt;
&lt;a id=&quot;line-3-52&quot; name=&quot;line-3-52&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-52&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;52 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ticket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-3-53&quot; name=&quot;line-3-53&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-53&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;53 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-54&quot; name=&quot;line-3-54&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-54&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;54 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. build a shortcut reference to all the fields in the ticket ..&lt;/span&gt;
&lt;a id=&quot;line-3-55&quot; name=&quot;line-3-55&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-55&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;55 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;fields&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ticket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;fields&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-3-56&quot; name=&quot;line-3-56&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-56&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;56 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-57&quot; name=&quot;line-3-57&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-57&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;57 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. build our response object ..&lt;/span&gt;
&lt;a id=&quot;line-3-58&quot; name=&quot;line-3-58&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-58&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;58 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetTicketDetailsResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-3-59&quot; name=&quot;line-3-59&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-59&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;59 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assigned_to&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;assignee&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;emailAddress&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-3-60&quot; name=&quot;line-3-60&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-60&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;60 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;progress_info&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;progress&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-3-61&quot; name=&quot;line-3-61&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-61&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;61 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-62&quot; name=&quot;line-3-62&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-62&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;62 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. and return the response to our caller.&lt;/span&gt;
&lt;a id=&quot;line-3-63&quot; name=&quot;line-3-63&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-63&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;63 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;
&lt;a id=&quot;line-3-64&quot; name=&quot;line-3-64&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-64&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;64 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-65&quot; name=&quot;line-3-65&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-65&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;65 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;creating-a-rest-channel-and-testing-it&quot;&gt;Creating a REST channel and testing it&lt;/h2&gt;
&lt;p&gt;The last remaining part is a REST channel to invoke our service through. We will provide the ticket ID (key) on input
and the service will reply with what was found in Jira for that ticket.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-atlassian/jira-rest-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;We are now ready for the final step - we invoke the channel, which invokes the service which communicates with Jira,
transforming the response from Jira to the output that we need:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-4-1&quot; name=&quot;line-4-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;localhost:17010/jira1&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-d&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;{&amp;quot;key&amp;quot;:&amp;quot;ABC-123&amp;quot;}&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-4-2&quot; name=&quot;line-4-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-4-3&quot; name=&quot;line-4-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;assigned_to&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;zato@example.com&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-4-4&quot; name=&quot;line-4-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;progress_info&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-4-5&quot; name=&quot;line-4-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;progress&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;m&quot;&gt;10&lt;/span&gt;,
&lt;a id=&quot;line-4-6&quot; name=&quot;line-4-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;total&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;m&quot;&gt;30&lt;/span&gt;
&lt;a id=&quot;line-4-7&quot; name=&quot;line-4-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-4-8&quot; name=&quot;line-4-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-4-9&quot; name=&quot;line-4-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And this is everything for today - just remember that this is just one way of integrating with Jira. The other one,
using WebHooks, is something that I will go into in one of the future articles.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Thu, 24 Apr 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/jira-python-api.html</guid></item><item><title>Airport Integrations in Python</title><link>https://zato.io/en/blog/airport-integrations-in-python.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/airport-integrations-in-python.html&quot;&gt;Airport Integrations in Python&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-04-10, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;Did you know you can use Python as an &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;integration platform&lt;/a&gt;
for your airport systems? It&#x27;s Open Source too.&lt;/p&gt;
&lt;p&gt;From AODB, transportation, business operations and partner networks, to IoT, cloud and hybrid deployments, you can now use Python to build flexible,
scalable and future-proof architectures that integrate your airport systems and support your master plan.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/en/industry/airports/index.html&quot;&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/ads/airport-integrations-in-python.webp&quot;
    class=&quot;img-responsive docs-article&quot;
    alt=&quot;Airport integrations in Python&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;➤ &lt;a href=&quot;https://zato.io/en/industry/airports/index.html&quot;&gt;Read here&lt;/a&gt; about what is possible and learn more why Python and Open Source are the right choice.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/network-packet-broker.html&quot;&gt;What is a Network Packet Broker? How to automate networks in Python?&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Thu, 10 Apr 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/airport-integrations-in-python.html</guid></item><item><title>How to correctly integrate APIs in Python</title><link>https://zato.io/en/blog/how-to-integrate-apis-in-python.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/how-to-integrate-apis-in-python.html&quot;&gt;How to correctly integrate APIs in Python&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-03-17, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/intro/high-level.jpg&quot;
    class=&quot;img-responsive docs-article&quot;
    alt=&quot;How to correctly integrate systems in Python&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Understanding how to effectively integrate various systems and APIs is crucial. Yet, without a dedicated integration platform,
the result will be brittle point-to-point, spaghetti integrations, that never lead to good outcomes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;Read this article about Zato, an open-source integration platform in Python&lt;/a&gt;,
for an overview of what to avoid and how to do it correctly instead.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/network-packet-broker.html&quot;&gt;What is a Network Packet Broker? How to automate networks in Python?&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 17 Mar 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/how-to-integrate-apis-in-python.html</guid></item><item><title>LDAP and Active Directory as Python API Services</title><link>https://zato.io/en/blog/ldap-active-directory.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/ldap-active-directory.html&quot;&gt;LDAP and Active Directory as Python API Services&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-01-19, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;LDAP and Active Directory often play key a role in the management of a company&#x27;s network resources yet it is not always
very convenient to query a directory directly using the LDAP syntax and protocol that few people truly specialize in.
This is why in this article we are using Zato to offer a REST API on top of directory services
so that API clients can use REST and JSON instead.&lt;/p&gt;
&lt;h2 id=&quot;installing-zato&quot;&gt;Installing Zato&lt;/h2&gt;
&lt;p&gt;Start off by &lt;a href=&quot;https://zato.io/en/docs/4.1/admin/guide/install/index.html&quot;&gt;installing Zato&lt;/a&gt; -
if you are not sure what to choose, pick the &lt;a href=&quot;https://zato.io/en/docs/4.1/admin/guide/install/docker.html&quot;&gt;Docker Quickstart&lt;/a&gt;
option and this will set up a working environment in a few minutes.&lt;/p&gt;
&lt;h2 id=&quot;creating-connections&quot;&gt;Creating connections&lt;/h2&gt;
&lt;p&gt;Once Zato is running, connections can be easily created in its Dashboard (by default, &lt;a href=&quot;http://127.0.0.1:8183&quot;&gt;http://127.0.0.1:8183&lt;/a&gt;).
Navigate to &lt;strong&gt;Connections -&amp;gt; Outgoing -&amp;gt; LDAP&lt;/strong&gt; ..&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/ldap-ad/ldap-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;.. and then click &lt;strong&gt;Create a new connection&lt;/strong&gt; which will open a form as below:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/ldap-ad/ldap-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;The same form works for both regular LDAP and Active Directory - in the latter case, make sure that &lt;strong&gt;Auth type&lt;/strong&gt; is set to NTLM.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/ldap-ad/ldap-form-auth.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;The most important information is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;User credentials&lt;/li&gt;
&lt;li&gt;Authentication type&lt;/li&gt;
&lt;li&gt;Server or servers to connect to&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that if authentication type is not NTLM, user credentials can be provided using the LDAP syntax,
e.g. &lt;strong&gt;uid=MyUser,ou=users,o=MyOrganization,dc=example,dc=com&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Right after creating a connection be sure to set its password too - the password asigned by default is a randomly generated one.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/ldap-ad/ldap-change-password.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;pinging&quot;&gt;Pinging&lt;/h2&gt;
&lt;p&gt;It is always prudent to ping a newly created connection to ensure that all the information entered was correct.&lt;/p&gt;
&lt;p&gt;Note that if you have more than one server in a pool then the first available one of them will be pinged -
it is the whole pool that is pinged, not a particular part of it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/ldap-ad/ldap-ping.png&quot;/&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/ldap-ad/ldap-pinged.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;active-directory-as-a-rest-service&quot;&gt;Active Directory as a REST service&lt;/h2&gt;
&lt;p&gt;As the first usage example, let&#x27;s create a service that will translate JSON queries into LDAP lookups - given username or email
the service will basic information about the person&#x27;s account, such as first and last name.&lt;/p&gt;
&lt;p&gt;Note that the &lt;strong&gt;conn&lt;/strong&gt; object returned by client.get() below is capable of running any commands that its
&lt;a href=&quot;https://ldap3.readthedocs.io/en/latest/&quot;&gt;underlying Python library&lt;/a&gt;
offers - in this case we are only using searches but any other operation can also be used, e.g. add or modify as well.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# stdlib&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loads&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Bunch&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;bunch&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bunchify&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Where in the directory we expect to find the user&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;search_base&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cn=users, dc=example, dc=com&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# On input, we are looking users up by either username or email&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;search_filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;(&amp;amp;(|(uid=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{user_info}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;)(mail=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{user_info}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;)))&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# On output, we are interested in username, first name, last name and the person&amp;#39;s email&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;query_attributes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;uid&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;givenName&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;sn&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;mail&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;ADService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot; Looks up users in AD by their username or email.&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SimpleIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;input_required&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;user_info&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;output_optional&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;message&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;username&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;first_name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;last_name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;email&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;response_elem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;None&lt;/span&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;skip_empty_keys&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;True&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Connection name to use&lt;/span&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;My AD Connection&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get a handle to the connection pool&lt;/span&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ldap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Get a handle to a particular connection&lt;/span&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-40&quot; name=&quot;line-0-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-41&quot; name=&quot;line-0-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;c1&quot;&gt;# Build a filter to find a user by&lt;/span&gt;
&lt;a id=&quot;line-0-42&quot; name=&quot;line-0-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;user_info&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;user_info&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-43&quot; name=&quot;line-0-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;user_filter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;search_filter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_info&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-44&quot; name=&quot;line-0-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-45&quot; name=&quot;line-0-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;c1&quot;&gt;# Returns True if query succeeds and has any information on output&lt;/span&gt;
&lt;a id=&quot;line-0-46&quot; name=&quot;line-0-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;search_base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;attributes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;query_attributes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-47&quot; name=&quot;line-0-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-48&quot; name=&quot;line-0-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;c1&quot;&gt;# This is where the actual response can be found&lt;/span&gt;
&lt;a id=&quot;line-0-49&quot; name=&quot;line-0-49&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-49&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;49 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;entries&lt;/span&gt;
&lt;a id=&quot;line-0-50&quot; name=&quot;line-0-50&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-50&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;50 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-51&quot; name=&quot;line-0-51&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-51&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;51 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;c1&quot;&gt;# In this case, we expect at most one user matching input criteria&lt;/span&gt;
&lt;a id=&quot;line-0-52&quot; name=&quot;line-0-52&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-52&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;52 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-53&quot; name=&quot;line-0-53&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-53&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;53 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-54&quot; name=&quot;line-0-54&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-54&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;54 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;c1&quot;&gt;# Convert it to JSON for easier handling ..&lt;/span&gt;
&lt;a id=&quot;line-0-55&quot; name=&quot;line-0-55&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-55&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;55 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;entry_to_json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-0-56&quot; name=&quot;line-0-56&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-56&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;56 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-57&quot; name=&quot;line-0-57&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-57&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;57 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;c1&quot;&gt;# .. and load it from JSON to a Python dict&lt;/span&gt;
&lt;a id=&quot;line-0-58&quot; name=&quot;line-0-58&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-58&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;58 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-59&quot; name=&quot;line-0-59&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-59&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;59 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-60&quot; name=&quot;line-0-60&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-60&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;60 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;c1&quot;&gt;# Convert to a Bunch instance to get dot access to dictionary keys&lt;/span&gt;
&lt;a id=&quot;line-0-61&quot; name=&quot;line-0-61&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-61&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;61 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bunchify&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;attributes&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;a id=&quot;line-0-62&quot; name=&quot;line-0-62&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-62&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;62 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-63&quot; name=&quot;line-0-63&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-63&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;63 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;c1&quot;&gt;# Now, actually produce a JSON response. For simplicity&amp;#39;s sake,&lt;/span&gt;
&lt;a id=&quot;line-0-64&quot; name=&quot;line-0-64&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-64&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;64 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;c1&quot;&gt;# assume that users have only one of email or other attributes.&lt;/span&gt;
&lt;a id=&quot;line-0-65&quot; name=&quot;line-0-65&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-65&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;65 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;User found&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-66&quot; name=&quot;line-0-66&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-66&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;66 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-67&quot; name=&quot;line-0-67&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-67&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;67 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;givenName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-68&quot; name=&quot;line-0-68&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-68&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;68 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;last_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-69&quot; name=&quot;line-0-69&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-69&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;69 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mail&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-70&quot; name=&quot;line-0-70&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-70&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;70 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-71&quot; name=&quot;line-0-71&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-71&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;71 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-72&quot; name=&quot;line-0-72&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-72&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;72 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;c1&quot;&gt;# No business response = no such user found&lt;/span&gt;
&lt;a id=&quot;line-0-73&quot; name=&quot;line-0-73&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-73&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;73 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                    &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;No such user&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;After creating a
&lt;a href=&quot;https://zato.io/en/docs/4.1/dev/rest/channels.html&quot;&gt;REST channel&lt;/a&gt;,
we can invoke the service from command line, thus confirming that we can offer the directory as a REST service:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;localhost:11223/api/get-user?user_info=MyOrganization\\MyUser&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;message&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;User found&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;username&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;MyOrganization\\MyUser&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-1-5&quot; name=&quot;line-1-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;first_name&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;First&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-1-6&quot; name=&quot;line-1-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;last_name&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Last&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-1-7&quot; name=&quot;line-1-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;email&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;address@example.com&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-1-8&quot; name=&quot;line-1-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-1-9&quot; name=&quot;line-1-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/network-packet-broker.html&quot;&gt;What is a Network Packet Broker? How to automate networks in Python?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Sun, 19 Jan 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/ldap-active-directory.html</guid></item><item><title>Understanding API rate-limiting techniques</title><link>https://zato.io/en/blog/api-rate-limiting-intro.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/api-rate-limiting-intro.html&quot;&gt;Understanding API rate-limiting techniques&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-01-13, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;Enabling rate-limiting in Zato means that access to Zato APIs can be throttled per endpoint, user or service - including options to make limits apply to specific IP addresses only - and if limits are exceeded within a selected period of time, the invocation will fail. Let&#x27;s check how to use it all.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/api-rate-limit-intro/arch.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;API rate limiting works on several levels and the configuration is always checked in the order below, which follows from the narrowest, most specific parts of the system (endpoints), through users which may apply to multiple endpoints, up to services which in turn may be used by both multiple endpoints and users.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First, per-endpoint limits&lt;/li&gt;
&lt;li&gt;Then, per-user limits&lt;/li&gt;
&lt;li&gt;Finally, per-service limits&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When a request arrives through an endpoint, that endpoint&#x27;s rate limiting configuration is checked. If the limit is already reached for the IP address or network of the calling application, the request is rejected.&lt;/p&gt;
&lt;p&gt;Next, if there is any user associated with the endpoint, that account&#x27;s rate limits are checked in the same manner and, similarly, if they are reached, the request is rejected.&lt;/p&gt;
&lt;p&gt;Finally, if the endpoint&#x27;s underlying service is configured to do so, it also checks if its invocation limits are not exceeded, rejecting the message accordingly if they are.&lt;/p&gt;
&lt;p&gt;Note that the three levels are distinct yet they overlap in what they allow one to achieve.&lt;/p&gt;
&lt;p&gt;For instance, it is possible to have the same user credentials be used in multiple endpoints and express ideas such as &quot;Allow this and that user to invoke my APIs 1,000 requests/day but limit each endpoint to at most 5 requests/minute no matter which user&quot;.&lt;/p&gt;
&lt;p&gt;Moreover, because limits can be set on services, it is possible to make it even more flexible, e.g. &quot;Let this service be invoked at most 10,000 requests/hour, no matter which user it is, with particular users being able to invoke at most 500 requests/minute, no matter which service, topping it off with per separate limits for REST vs. SOAP vs. JSON-RPC endpoint, depending on what application is invoke the endpoints&quot;. That lets one conveniently express advanced scenarios that often occur in practical situations.&lt;/p&gt;
&lt;p&gt;Also, observe that API rate limiting applies to REST, SOAP and JSON-RPC endpoints only, it is not used with other API endpoints, such as AMQP, IBM MQ, SAP, task scheduler or any other technologies. However, per-service limits work no matter which endpoint the service is invoked with and they will work with endpoints such as WebSockets, ZeroMQ or any other.&lt;/p&gt;
&lt;p&gt;Lastly, limits pertain to with incoming requests only - any outgoing ones, from Zato to external resources - are not covered by it.&lt;/p&gt;
&lt;h2 id=&quot;per-ip-restrictions&quot;&gt;Per-IP restrictions&lt;/h2&gt;
&lt;p&gt;The architecture is made even more versatile thanks to the fact that for each object - endpoint, user or service - different limits can be configured depending on the caller&#x27;s IP address.&lt;/p&gt;
&lt;p&gt;This adds yet another dimension and allows to express ideas commonly witnessed in API-based projects, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;External applications, depending on their IP addresses, can have their own limits&lt;/li&gt;
&lt;li&gt;Internal users, e.g. employees of the company using VPN, may have hire limits if their addresses are in the 172.x.x.x range&lt;/li&gt;
&lt;li&gt;For performance testing purposes, access to Zato from a few selected hosts may have no limits at all&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;IP-based limits work hand in hand are an integral part of the mechanism - they do not rule out per-endpoit, user or service limits. In fact, for each such object, multiple IP-using limits can be set independently, thus allowing for highest degree of flexibility.&lt;/p&gt;
&lt;h2 id=&quot;exact-or-approximate&quot;&gt;Exact or approximate&lt;/h2&gt;
&lt;p&gt;Rate limits come in two types:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Exact&lt;/li&gt;
&lt;li&gt;Approximate&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Exact rate limits are just that, exact - they en that a limit is not exceeded at all, not even by a single request.&lt;/p&gt;
&lt;p&gt;Approximate limits may let a very small number of requests to exceed the limit with the benefit being that approximate limits are faster to check than exact ones.&lt;/p&gt;
&lt;p&gt;When to use which type depends on a particular project:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In some projects, it does not really matter if callers have a limit of 1,000 requests/minute or 1,005 requests/minute because the difference is too tiny to make a business impact. Approximate limits work best in this case.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In other projects, there may be requirements that the limit never be exceeded no matter the circumstances. Use exact limits here.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;python-code-and-web-admin&quot;&gt;Python code and web-admin&lt;/h2&gt;
&lt;p&gt;Alright, let&#x27;s check how to define the limits in the Zato Dashboard. We will use the sample service below:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;api.sample&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Return a simple string on response&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Hello there!&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, in web-admin, we will configure limits - separately for the service, a new and a new REST API channel (endpoint).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/api-rate-limit-intro/service.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/api-rate-limit-intro/user.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/api-rate-limit-intro/channel.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Points of interest:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Configuration for each type of object is independent - within the same invocation some limits may be exact, some may be approximate&lt;/li&gt;
&lt;li&gt;There can be multiple configuration entries for each object&lt;/li&gt;
&lt;li&gt;A unit of time is &quot;m&quot;, &quot;h&quot; or &quot;d&quot;, depending on whether the limit is per minute, hour or day, respectively&lt;/li&gt;
&lt;li&gt;All limits within the same configuration are checked in the order of their definition which is why the most generic ones should be listed first&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;testing-it-out&quot;&gt;Testing it out&lt;/h2&gt;
&lt;p&gt;Now, all is left is to invoke the service from curl.&lt;/p&gt;
&lt;p&gt;As long as limits are not reached, a business response is returned:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$ curl http://my.user:password@localhost:11223/api/sample
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;Hello there!
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;But if a limit is reached, the caller receives an error message with the 429 HTTP status.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$ curl -v http://my.user:password@localhost:11223/api/sample
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;*   Trying 127.0.0.1...
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;...
&lt;a id=&quot;line-2-5&quot; name=&quot;line-2-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-6&quot; name=&quot;line-2-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&amp;lt; HTTP/1.1 429 Too Many Requests
&lt;a id=&quot;line-2-7&quot; name=&quot;line-2-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&amp;lt; Server: Zato
&lt;a id=&quot;line-2-8&quot; name=&quot;line-2-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&amp;lt; X-Zato-CID: b8053d68612d626d338b02
&lt;a id=&quot;line-2-9&quot; name=&quot;line-2-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-10&quot; name=&quot;line-2-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;...
&lt;a id=&quot;line-2-11&quot; name=&quot;line-2-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-12&quot; name=&quot;line-2-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;{&amp;quot;zato_env&amp;quot;:{&amp;quot;result&amp;quot;:&amp;quot;ZATO_ERROR&amp;quot;,&amp;quot;cid&amp;quot;:&amp;quot;b8053d68612d626d338b02eb&amp;quot;,
&lt;a id=&quot;line-2-13&quot; name=&quot;line-2-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt; &amp;quot;details&amp;quot;:&amp;quot;Error 429 Too Many Requests&amp;quot;}}
&lt;a id=&quot;line-2-14&quot; name=&quot;line-2-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that the caller never knows what the limit was - that information is saved in Zato server logs along with other details so that API authors can correlate what callers get with the very rate limiting definition that prevented them from accessing the service.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;zato.common.rate_limiting.common.RateLimitReached: Max. rate limit of 100/m reached;
&lt;a id=&quot;line-3-2&quot; name=&quot;line-3-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;from:`10.74.199.53`, network:`*`; last_from:`127.0.0.1;
&lt;a id=&quot;line-3-3&quot; name=&quot;line-3-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;last_request_time_utc:`2025-01-12T15:30:41.943794;
&lt;a id=&quot;line-3-4&quot; name=&quot;line-3-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;last_cid:`5f4f1ef65490a23e5c37eda1`; (cid:b8053d68612d626d338b02)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And this is it - we have created a new API rate limiting definition in Zato and tested it out successfully!&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 13 Jan 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/api-rate-limiting-intro.html</guid></item><item><title>Network automation getting started</title><link>https://zato.io/en/blog/network-automation-getting-started.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/network-automation-getting-started.html&quot;&gt;Network automation getting started&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2025-01-07, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/articles/automation-in-python/automation-in-python.webp&quot;
    width=&quot;880&quot;
    class=&quot;img-responsive docs-article&quot;
    alt=&quot;Automation in Python&quot; /&gt;&lt;/p&gt;
&lt;p&gt;All network engineers and architects understand that automation is essential for efficiency and reliability,
especially with the increasing shift to cloud-based environments, where it&#x27;s no longer sufficient to merely connect
network elements alone, without taking the bigger IT picture into account.&lt;/p&gt;
&lt;p&gt;The latest article about network automation will introduce you to a Python-based integration platform designed to
automate network tasks, connect diverse systems, and manage complex workflows.&lt;/p&gt;
&lt;p&gt;You&#x27;ll see not only how to automate a network device, but also how to connect cloud applications outside of what a typical
automation tool would do, including Jira for tickets and Microsoft 365 to manage email, all using basic Python code.&lt;/p&gt;
&lt;p&gt;Read the article here: &lt;a href=&quot;https://zato.io/articles/automation-in-python.html&quot;&gt;Network Automation in Python&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/network-packet-broker.html&quot;&gt;What is a Network Packet Broker? How to automate networks in Python?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Tue, 07 Jan 2025 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/network-automation-getting-started.html</guid></item><item><title>Using OAuth in API Integrations</title><link>https://zato.io/en/blog/oauth-api-integrations.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/oauth-api-integrations.html&quot;&gt;Using OAuth in API Integrations&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-12-23, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;OAuth is often employed in processes requiring permissions to be granted to frontend applications and end users.
Yet, what we typically need in API systems integrations is a way to secure connections between the integration
middleware and backend systems without a need for any ongoing human interactions.&lt;/p&gt;
&lt;p&gt;OAuth can be a good choice for that scenario and this article shows how it can be achieved in Python, with backend
systems using REST and HL7 FHIR.&lt;/p&gt;
&lt;h2 id=&quot;what-we-would-like-to-have&quot;&gt;What we would like to have&lt;/h2&gt;
&lt;p&gt;Let&#x27;s say we have a typical integration scenario as in the diagram below:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-oauth/oauth-rest-hl7-api-architecture.png&quot;/&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;External systems and applications invoke the interoperability layer (Zato) which is expected to further invoke a few
  backend systems, e.g. a REST and HL7 FHIR one so as to return a combined result of backend API invocations. It does not
  matter what technology the client systems use, i.e. whether they are REST ones or not.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The interoperability layer needs to identify itself with the backend systems before it is allowed to invoke them - they
  need to make sure that it really is Zato and that it accesses only the resources allowed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An OAuth server issues time-based access tokens, which are simple strings, like web browser session cookies, confirming that such and such
  bearer of the said token is allowed to make such and such requests. Note that the tokens have an explicit expiration time,
  e.g. they will become invalid after one hour. Also observe that Zato stores the tokens as-is, they are genuinely opaque
  strings.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If a client system invokes the interoperability layer, the layer will obtain a token from the OAuth server and keep it in an internal cache.
  Next, Zato will invoke the backend systems, bearing the token among other HTTP headers. Each invoked backend system will extract the token
  from the incoming request and validate it.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How the validation looks like in practices is something that Zato will not be aware of because it treats the token as an opaque string
  but, in practice, if the token is self-contained (e.g. JWT data) the system may validate it on its own, and if it is not self-contained,
  the system may invoke an introspection endpoint on the OAuth server to validate the access token from Zato.&lt;/p&gt;
&lt;p&gt;Once the validation succeeds, the backend system will reply with the business data and the interoperability layer will combine
  the results for the calling application&#x27;s benefit.&lt;/p&gt;
&lt;p&gt;In subsequent requests, the same access token will be reused by Zato with the same flow of messages as previously. However,
  if the cached token expires, Zato will request a new one from the OAuth server - this will be transparent to the calling application -
  and the flow will resume.&lt;/p&gt;
&lt;p&gt;In OAuth terminology, what is described above has specific names, the overall flow of messages between Zato and the OAuth server is
called a &quot;Client Credential Flow&quot; and Zato is then considered a &quot;client&quot; from the OAuth server&#x27;s perspective.&lt;/p&gt;
&lt;h2 id=&quot;configuring-oauth&quot;&gt;Configuring OAuth&lt;/h2&gt;
&lt;p&gt;First, we need to create an OAuth security definition that contains the OAuth server&#x27;s connection details. In this case,
the server is &lt;a href=&quot;https://www.okta.com/&quot;&gt;Okta&lt;/a&gt;. Note the scopes field - it is a list of permissions (&quot;scopes&quot;) that Zato will be able to make use of.&lt;/p&gt;
&lt;p&gt;What exactly the list of scopes should look like is something to be coordinated with the people who are responsible
for the configuration of the OAuth server. If it is you personally, simply ensure that what is in the the OAuth server and in Zato is in sync.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-oauth/oauth-menu.png&quot;/&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-oauth/oauth-form.png&quot;/&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-oauth/oauth-secret.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;calling-rest&quot;&gt;Calling REST&lt;/h2&gt;
&lt;p&gt;To invoke REST services, fill out a form as below, pointing the &quot;Security&quot; field to the newly created OAuth definition.
This suffices for Zato to understand when and how to obtain new tokens from the underlying OAuth server.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-oauth/rest-menu.png&quot;/&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-oauth/rest-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Here is sample code to invoke a backend REST system - note that we merely refer to a connection by its name, without having
to think about security at all. It is Zato that knows how to get and use OAuth tokens as required.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GetClientBillingPlan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot; Returns a billing plan for the input client.&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# In a real service, this would be read from input&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;client_id&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;123&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get a connection to the server ..&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;REST Server&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. invoke it ..&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. and handle the response here.&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;calling-hl7-fhir&quot;&gt;Calling HL7 FHIR&lt;/h2&gt;
&lt;p&gt;Similarly to REST endpoints, to invoke HL7 FHIR servers, fill out a form as below and let the &quot;Security&quot; field point to the OAuth
definition just created. This will suffice for Zato to know when and how to use tokens received from the underlying OAuth server.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-oauth/fhir-menu.png&quot;/&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-oauth/fhir-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Here is sample code to invoke a FHIR server system - as with REST servers above, observe that we only refer to a connection by its name
and Zato takes care of OAuth.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-1-5&quot; name=&quot;line-1-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-6&quot; name=&quot;line-1-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GetPractitioner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-7&quot; name=&quot;line-1-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot; Returns a practictioner matching input data.&lt;/span&gt;
&lt;a id=&quot;line-1-8&quot; name=&quot;line-1-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-1-9&quot; name=&quot;line-1-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;None&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-1-10&quot; name=&quot;line-1-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-11&quot; name=&quot;line-1-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Connection to use&lt;/span&gt;
&lt;a id=&quot;line-1-12&quot; name=&quot;line-1-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;My EHR&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-1-13&quot; name=&quot;line-1-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-14&quot; name=&quot;line-1-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# In a real service, this would be read from input&lt;/span&gt;
&lt;a id=&quot;line-1-15&quot; name=&quot;line-1-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;practitioner_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;456&lt;/span&gt;
&lt;a id=&quot;line-1-16&quot; name=&quot;line-1-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-17&quot; name=&quot;line-1-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get a connection to the server ..&lt;/span&gt;
&lt;a id=&quot;line-1-18&quot; name=&quot;line-1-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hl7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fhir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-1-19&quot; name=&quot;line-1-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-20&quot; name=&quot;line-1-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Get a reference to a FHIR resource ..&lt;/span&gt;
&lt;a id=&quot;line-1-21&quot; name=&quot;line-1-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;practitioners&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resources&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Practitioner&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-1-22&quot; name=&quot;line-1-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-23&quot; name=&quot;line-1-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. look up the practitioner ..&lt;/span&gt;
&lt;a id=&quot;line-1-24&quot; name=&quot;line-1-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;practitioners&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;active&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;practitioner_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-1-25&quot; name=&quot;line-1-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-26&quot; name=&quot;line-1-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. and handle the response here.&lt;/span&gt;
&lt;a id=&quot;line-1-27&quot; name=&quot;line-1-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;what-about-the-api-clients&quot;&gt;What about the API clients?&lt;/h2&gt;
&lt;p&gt;One aspect omitted above are the initial API clients - this is on purpose. How they invoke Zato, using what protocols,
with what security mechanisms, and how to build responses based on their input data, this is completely independent of how
Zato uses OAuth in its own communication with backend systems.&lt;/p&gt;
&lt;p&gt;All of these aspects can and will be independent in practice,
e.g. clients will use Basic Auth rather than OAuth. Or perhaps the clients will use AMQP, Odoo, SAP, or IBM MQ, without any HTTP,
or maybe there will be no explicit API invocations and what we call &quot;clients&quot; will be actually CSV files in a shared
directory that your services will be scheduled to periodically pick up. Yet, once more, regardless of what makes the input data
available, the backend OAuth mechanism will work independently of it all.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/intro/ira.png&quot; /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;h2 id=&quot;next-steps&quot;&gt;Next steps&lt;/h2&gt;
&lt;p&gt;➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/screenshots.html&quot;&gt;API programming screenshots&lt;/a&gt;
&lt;br/&gt;
➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ More &lt;a href=&quot;https://zato.io/en/docs/4.1/dev/index.html&quot;&gt;API programming examples in Python&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 23 Dec 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/oauth-api-integrations.html</guid></item><item><title>HL7 FHIR API Integrations in Python</title><link>https://zato.io/en/blog/hl7-fhir-api-integrations-python.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/hl7-fhir-api-integrations-python.html&quot;&gt;HL7 FHIR API Integrations in Python&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-12-16, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-python/platform.jpg&quot;/&gt;&lt;/p&gt;
&lt;p&gt;HL7 FHIR, pronounced &quot;fire&quot;, is a data model and message transfer protocol designed to facilitate the exchange of information
among systems used in health care settings.&lt;/p&gt;
&lt;p&gt;In such environments, a FHIR server will assume the role of a central repository of health records
with other systems integrating with it, potentially in a hub-and-spoke fashion, thus letting the FHIR server become a unified
and consistent source of data that would otherwise stay confined to a silo of each individual health information system.&lt;/p&gt;
&lt;p&gt;While FHIR is the way forward, the current reality of health care systems is that much of the useful and actionable
information is distributed and scattered among many individual data sources - paper-based directories, applications or
data bases belonging to the same or different enterprises - and that directly hampers the progress towards delivering
good health care. Anyone witnessing health providers copy-and-pasting the same information from one application to another,
not having access to the already existing data, not to mention people not having an easy way to access their own data about
themselves either, can understand what the lack of interoperability looks like externally.&lt;/p&gt;
&lt;p&gt;The challenges that integrators face are two-fold. On the one hand, the already existing systems, including
software as well as medical appliances, were often not, or are still not being, designed for the contemporary inter-connected world.
On the other hand, FHIR in itself is a relatively new technology which means that it is not straightforward to re-use
the existing skills and competencies.&lt;/p&gt;
&lt;p&gt;Zato is an open-source platform that makes it possible to integrate systems with FHIR using Python. Specifically,
its support for FHIR enables quick on-boarding of integrators who may be new to health care interoperability,
who are coming to FHIR with previous experience or interest in web development technologies, and who need an easy way to
get started with and to navigate the complex landscape of health care integrations.&lt;/p&gt;
&lt;h2 id=&quot;connecting-to-fhir-servers&quot;&gt;Connecting to FHIR servers&lt;/h2&gt;
&lt;p&gt;Outgoing FHIR connections are what allows Python-based services to communicate with FHIR servers. Throughout the rest
of the chapter, the following definition will be used. It connects to a live, publicly available FHIR server.&lt;/p&gt;
&lt;p&gt;Filling out the form below will suffice, there is no need for any server restarts. This principle, that restarts are not needed,
applies all throughout the platform, whenever you change any piece of configuration, it will be automatically propagated
as necessary.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Name: FHIR.Sample&lt;/li&gt;
&lt;li&gt;Address: &lt;a href=&quot;https://fhir.simplifier.net/zato&quot;&gt;https://simplifier.net/zato&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Security: No security definition (we will talk about security later)&lt;/li&gt;
&lt;li&gt;TLS CA Certs: Default bundle&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-python/fhir-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-python/fhir-form.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;retrieving-data-from-fhir-servers&quot;&gt;Retrieving data from FHIR servers&lt;/h2&gt;
&lt;p&gt;In Python code, you obtain client connections to FHIR servers through &lt;strong&gt;self.out.hl7.fhir&lt;/strong&gt; objects, as in the example
below which first refers to the server by its name and then looks up all the patients in the server.&lt;/p&gt;
&lt;p&gt;The structure of the Patient resource that we expect to receive can be found
&lt;a href=&quot;https://simplifier.net/zato/Patient/~overview&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;FHIService1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;demo.fhir.1&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;None&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Connection to use&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;FHIR.Sample&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hl7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fhir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# This is how we can refer to patients&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;patients&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resources&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Patient&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Get all active patients, sorted by their birth date&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;patients&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;active&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;-birthdate&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Log the result that we received&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elem&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Received -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Invoking the service will store in logs the data expected:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;INFO - Received -&amp;gt; [{&amp;#39;use&amp;#39;: &amp;#39;official&amp;#39;, &amp;#39;family&amp;#39;: &amp;#39;Chalmers&amp;#39;, &amp;#39;given&amp;#39;: [&amp;#39;Peter&amp;#39;, &amp;#39;James&amp;#39;]}]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For comparison, this is what the FHIR server displays in
&lt;a href=&quot;https://simplifier.net/zato/Patient/~overview&quot;&gt;its frontend&lt;/a&gt;.
- the information is the same.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-python/fhir-resource.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;storing-data-in-fhir-servers&quot;&gt;Storing data in FHIR servers&lt;/h2&gt;
&lt;p&gt;To save information in a FHIR server, create the required resources and call .save to permanently store the data
in the server. Resources can be saved either individually (as in the example below) or as a bundle.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-2-5&quot; name=&quot;line-2-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-6&quot; name=&quot;line-2-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CommandsService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-7&quot; name=&quot;line-2-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;demo.fhir.2&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-8&quot; name=&quot;line-2-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-9&quot; name=&quot;line-2-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;None&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-10&quot; name=&quot;line-2-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-11&quot; name=&quot;line-2-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Connection to use&lt;/span&gt;
&lt;a id=&quot;line-2-12&quot; name=&quot;line-2-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;FHIR.Sample&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-13&quot; name=&quot;line-2-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-14&quot; name=&quot;line-2-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hl7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fhir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-15&quot; name=&quot;line-2-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-16&quot; name=&quot;line-2-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# First, create a new patient&lt;/span&gt;
&lt;a id=&quot;line-2-17&quot; name=&quot;line-2-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;patient&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Patient&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-18&quot; name=&quot;line-2-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-19&quot; name=&quot;line-2-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Save the patient in the FHIR server&lt;/span&gt;
&lt;a id=&quot;line-2-20&quot; name=&quot;line-2-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;patient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-2-21&quot; name=&quot;line-2-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-22&quot; name=&quot;line-2-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Create a new appointment object&lt;/span&gt;
&lt;a id=&quot;line-2-23&quot; name=&quot;line-2-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;appointment&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;resource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Appointment&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-24&quot; name=&quot;line-2-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-25&quot; name=&quot;line-2-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Who will attend it&lt;/span&gt;
&lt;a id=&quot;line-2-26&quot; name=&quot;line-2-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;participant&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-2-27&quot; name=&quot;line-2-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;s1&quot;&gt;&amp;#39;actor&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;patient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-2-28&quot; name=&quot;line-2-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;s1&quot;&gt;&amp;#39;status&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;accepted&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-29&quot; name=&quot;line-2-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-2-30&quot; name=&quot;line-2-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-31&quot; name=&quot;line-2-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Fill out the information about the appointment&lt;/span&gt;
&lt;a id=&quot;line-2-32&quot; name=&quot;line-2-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;appointment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;booked&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-33&quot; name=&quot;line-2-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;appointment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;participant&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;participant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-2-34&quot; name=&quot;line-2-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;appointment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;2022-11-11T11:11:11.111+00:00&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-35&quot; name=&quot;line-2-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;appointment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;2022-12-22T22:22:22.222+00:00&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-36&quot; name=&quot;line-2-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-37&quot; name=&quot;line-2-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Save the appointment in the FHIR server&lt;/span&gt;
&lt;a id=&quot;line-2-38&quot; name=&quot;line-2-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;appointment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;learning-what-fhir-resources-to-use&quot;&gt;Learning what FHIR resources to use&lt;/h2&gt;
&lt;p&gt;The &quot;R&quot; in FHIR stands for &quot;Resources&quot; and the sample code above uses resources such a Patient or Appointment but how does
one learn what other resources exist and what they look like? In other words, how does one learn the underlying data model?&lt;/p&gt;
&lt;p&gt;First, you need to get familiar with the spec itself which, in addition to textual information, offers visualizations
of the data model. For instance, here is the description of the &lt;a href=&quot;https://hl7.org/fhir/observation.html&quot;&gt;Observation object&lt;/a&gt;,
including details such as all the attributes an Observation is composed of as well as their multiplicities.&lt;/p&gt;
&lt;p&gt;Secondly, do spend time with FHIR servers such as &lt;a href=&quot;https://simplifier.net&quot;&gt;Simplifier&lt;/a&gt;. Use Zato services to create test
resources, look them up and compare the results with what the spec says. There is no substitute for experimentation when
learning a new data model.&lt;/p&gt;
&lt;h2 id=&quot;fhir-security&quot;&gt;FHIR security&lt;/h2&gt;
&lt;p&gt;Outgoing FHIR connections can be secured in several ways, depending on what a given FHIR requires:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;With Basic Auth definitions&lt;/li&gt;
&lt;li&gt;With OAuth definitions&lt;/li&gt;
&lt;li&gt;With SSL/TLS. If the server is not a public one (e.g. it is in a private network with a private IP address), you may need
  to upload the server&#x27;s certificate to Zato first if you plan to use SSL/TLS because, without it, the server&#x27;s certificate
  may be rejected.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;mllp-hl7-v2-and-v3&quot;&gt;MLLP, HL7 v2 and v3&lt;/h2&gt;
&lt;p&gt;While FHIR is what new deployments use, it is worth to add that there are still other HL7 versions frequently
seen in integrations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Version 2, using its own MLLP protocol&lt;/li&gt;
&lt;li&gt;Version 3, using XML&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both of them can be used in Zato services, in both directions. For instance, it is possible to both receive HL7 v2 messages
as well as to send them to external applications. It is also possible to send v2 messages using REST in addition to MLLP.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-python/hl7-v2-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-python/hl7-v2-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
➤ Read more about using &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;Python in API integrations&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/tutorials/main/01.html&quot;&gt;Start the tutorial&lt;/a&gt; which will guide you how to design and build Python API services for interoperability, integrations and automation
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 16 Dec 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/hl7-fhir-api-integrations-python.html</guid></item><item><title>New API integration tutorial in Python</title><link>https://zato.io/en/blog/api-integration-tutorial.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/api-integration-tutorial.html&quot;&gt;New API integration tutorial in Python&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-12-09, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;
&lt;p&gt;Do you know what
&lt;a href=&quot;https://zato.io/en/industry/airports/index.html&quot;&gt;airports&lt;/a&gt;,
&lt;a href=&quot;https://zato.io/en/industry/telecom/index.html&quot;&gt;telecom operators&lt;/a&gt;,
&lt;a href=&quot;https://zato.io/en/industry/defense/index.html&quot;&gt;defense forces&lt;/a&gt;
and
&lt;a href=&quot;https://zato.io/en/industry/healthcare/index.html&quot;&gt;health care organizations&lt;/a&gt;
have in common?&lt;/p&gt;
&lt;p&gt;They all rely heavily on deep-backend software systems which are integrated and automated using principled methodologies,
innovative techniques and well-defined implementation frameworks.&lt;/p&gt;
&lt;p&gt;If you&#x27;d like to learn how to integrate and automate such complex systems correctly, head over to the new
&lt;a href=&quot;https://zato.io/en/tutorials/main/01.html&quot;&gt;API integration tutorial&lt;/a&gt;
that will show you how to do it in Python too.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/en/docs/4.1/gfx/api/tutorial/tutorial-achieve.webp&quot; style=&quot;width:700px&quot; /&gt;&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot; Returns user details by the person&amp;#39;s name.&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;api.my-service&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# I/O definition&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;-name&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;user_type&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;account_no&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;account_balance&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# For later use&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;partner&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# REST connections&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;crm_conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;CRM&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;billing_conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Billing&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Prepare requests&lt;/span&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;crm_request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;UserName&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;billing_params&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;USER&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get data from CRM&lt;/span&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;crm_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;crm_conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;crm_request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get data from Billing&lt;/span&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;billing_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;billing_conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;billing_params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Extract the business information from both systems&lt;/span&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;user_type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;crm_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;UserType&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;account_no&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;crm_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;AccountNumber&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;account_balance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;billing_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;ACC_BALANCE&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-40&quot; name=&quot;line-0-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-41&quot; name=&quot;line-0-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;cid:&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; Returning user details for &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-42&quot; name=&quot;line-0-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-43&quot; name=&quot;line-0-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Now, produce the response for our caller&lt;/span&gt;
&lt;a id=&quot;line-0-44&quot; name=&quot;line-0-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-45&quot; name=&quot;line-0-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;          &lt;span class=&quot;s1&quot;&gt;&amp;#39;user_type&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-46&quot; name=&quot;line-0-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;          &lt;span class=&quot;s1&quot;&gt;&amp;#39;account_no&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;account_no&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-47&quot; name=&quot;line-0-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;          &lt;span class=&quot;s1&quot;&gt;&amp;#39;account_balance&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;account_balance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-48&quot; name=&quot;line-0-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-49&quot; name=&quot;line-0-49&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-49&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;49 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-50&quot; name=&quot;line-0-50&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-50&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;50 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/intro/ira.png&quot; /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;h2 id=&quot;quick-links&quot;&gt;Quick links&lt;/h2&gt;
&lt;p&gt;➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/screenshots.html&quot;&gt;API programming screenshots&lt;/a&gt;
&lt;br/&gt;
➤ Here&#x27;s the &lt;a href=&quot;https://zato.io/en/tutorials/main/01.html&quot;&gt;API integration tutorial&lt;/a&gt; again
&lt;br/&gt;
➤ More &lt;a href=&quot;https://zato.io/en/docs/4.1/dev/index.html&quot;&gt;API programming examples in Python&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 09 Dec 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/api-integration-tutorial.html</guid></item><item><title>IMAP OAuth2 Microsoft 365 Integration</title><link>https://zato.io/en/blog/imap-oauth2-microsoft365.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/imap-oauth2-microsoft365.html&quot;&gt;IMAP OAuth2 Microsoft 365 Integration&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-11-19, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-imap/ms365.jpg&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;This is the first in a series of articles about automation of and integrations with Microsoft 365 cloud products
using Python and Zato.&lt;/p&gt;
&lt;p&gt;We start off with IMAP automation by showing how to
create a scheduled Python service that periodically pulls latest emails from Outlook using OAuth2-based connections.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-imap/ms365-menu.png&quot;/&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-imap/ms365-form.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;imap-and-oauth2&quot;&gt;IMAP and OAuth2&lt;/h2&gt;
&lt;p&gt;Microsoft 365 requires for all IMAP connections to use OAuth2. This can be challenging to configure
in server-side automation and orchestration processes so Zato offers an easy way that lets you read and send emails
without a need for getting into low-level OAuth2 details.&lt;/p&gt;
&lt;p&gt;Consider a common orchestration scenario - a business partner sends automated emails with attachments that
need to be parsed, some information needs to be extracted and processed accordingly.&lt;/p&gt;
&lt;p&gt;Before OAuth2, an automation process would receive from Azure administrators a dedicated IMAP account with a username
and password.&lt;/p&gt;
&lt;p&gt;Now, however, in addition to creating an IMAP account, administrators will need to create and configure a few more
resources that the orchestration service will use. Note that the password to the IMAP account will never be used.&lt;/p&gt;
&lt;p&gt;Administrators need to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Register an Azure client app representing your service that uses IMAP&lt;/li&gt;
&lt;li&gt;Grant this app a couple of Microsoft Graph application permissions:&lt;/li&gt;
&lt;li&gt;Mail.ReadWrite&lt;/li&gt;
&lt;li&gt;Mail.Send&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Next, administrators need to give you a few pieces of information about the app:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Application (client) ID&lt;/li&gt;
&lt;li&gt;Tenant (directory) ID&lt;/li&gt;
&lt;li&gt;Client secret&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Additionally, you still need to receive the IMAP username (an e-mail address). It is just that you do not need its
corresponding password.&lt;/p&gt;
&lt;h2 id=&quot;in-dashboard&quot;&gt;In Dashboard&lt;/h2&gt;
&lt;p&gt;The first step is to create a new connection in your Zato Dashboard - this will establish an OAuth2-using connection
that Zato will manage and your Python code will not have to do anything else,
all the underlying OAuth2 tokens will keep refreshing as needed, the platform will take care of everything.&lt;/p&gt;
&lt;p&gt;Having received the configuration details from Azure administrators, you can open your Zato Dashboard and navigate
to IMAP connections:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-imap/ms365-imap-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Fill out the form as below, choosing &quot;Microsoft 365&quot; as the server type. The other type, &quot;Generic IMAP&quot; is used for
the classical case of IMAP with a username and password:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-imap/ms365-imap-create-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Change the secret and click Ping to confirm that the connection is configured correctly:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-imap/ms365-imap-secret-ping.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;in-python&quot;&gt;In Python&lt;/h2&gt;
&lt;p&gt;Use the code below to receive emails. Note that it merely needs to refer to a connection definition by its
name and there is no need for any usage of OAuth2 here:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Connect to a Microsoft 365 IMAP connection by its name ..&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My Automation&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. get all messages matching filter criteria (&amp;quot;unread&amp;quot; by default)..&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. and access each of them.&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is everything that is needed for integrations with IMAP using Microsoft 365 although we can still go further.
For instance, to create a scheduled job to periodically invoke the service, go to the Scheduler job
in Dashboard:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-imap/imap-scheduler-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;In this case, we decide to have a job that runs once per hour:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-imap/imap-scheduler-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;As expected, clicking OK will suffice for the job to start in background. It is as simple as that.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Tue, 19 Nov 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/imap-oauth2-microsoft365.html</guid></item><item><title>Web scraping API integrations</title><link>https://zato.io/en/blog/web-scraping-api-integrations.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/web-scraping-api-integrations.html&quot;&gt;Web scraping API integrations&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-11-13, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;In systems-to-systems integrations, there comes an inevitable time when we have to employ some kind of a web scraping tool
to integrate with a particular application. Despite its not being our first choice, it is good to know what to use
at such a time - in this article, I provide a gentle introduction to my favorite tool of this kind,
called &lt;a href=&quot;https://playwright.dev/&quot;&gt;Playwright&lt;/a&gt;, followed by sample Python code that integrates it with an API service.&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-web-scraping/browsers.png&quot;/&gt;
&lt;/center&gt;

&lt;p&gt;Naturally, in the context of backend integrations, web scraping should be avoided and, generally, it should be considered
the last resort. The basic issue here is that while the UI term contains the &quot;interface&quot; part, it is not really the &quot;Application
Programming&quot; Interface that we would like to have.&lt;/p&gt;
&lt;p&gt;It is not that the UI cannot be programmed against. After all, a web browser does just that, it takes a web page and renders
it as expected. Same goes for desktop or mobile applications. Also, anyone integrating with mainframe computers will recognize
that this is basically what &lt;a href=&quot;https://en.wikipedia.org/wiki/3270_emulator&quot;&gt;3270&lt;/a&gt; can be used for too.&lt;/p&gt;
&lt;p&gt;Rather, the fundamental issue is that web scraping goes against
the principles of separation of layers and roles across frontend, middleware and backend, which in turn means that authors
of resources (e.g. HTML pages) do not really expect for many people to access them in automated ways.&lt;/p&gt;
&lt;p&gt;Perhaps they actually should expect it, and web pages should finally start to resemble genuine knowledge graphs,
easy to access by humans, be it manually or through automation tools, but the reality today is that it is not the case
and, in comparison with backend systems, the whole of the web scraping space is relatively brittle, which is why we shun
this approach in integrations.&lt;/p&gt;
&lt;p&gt;Yet, another part of reality, particularly in enterprise integrations, is that people may be sometimes given access to a frontend
application on an internal network and that is it. No API, no REST, no JSON, no POST data, no real data formats,
and one is simply supposed to fill out forms as part of a business process.&lt;/p&gt;
&lt;p&gt;Typically, such a situation will result in an integration gap. There will be fully automated parts in the business process
preceding this gap, with multiple systems coordinated towards a specific goal and there will be subsequent steps in the process,
also fully automated.&lt;/p&gt;
&lt;p&gt;Or you may be given access only to a specific frontend and only through VPN via a single remote Windows desktop. Getting access
to a REST API may take months or may be never realized because of some high level licensing issues. This is not uncommon in the
real life.&lt;/p&gt;
&lt;p&gt;Such a gap can be a jarring and sore point, truly ruining the whole, otherwise fluid, integration process. This creates a tension
and to resolve the tension, we can, should all the attempts to find a real API fail, finally resort to web scraping.&lt;/p&gt;
&lt;p&gt;It is mostly in this context that I am looking at Playwright below -  the tool is good and it has many other uses that go beyond
the scope of this text, and it is well worth knowing it, for instance for frontend testing of your backend systems, but, when
we deal with API integrations, we should not overdo with web scraping.&lt;/p&gt;
&lt;p&gt;Needless to say, if web scraping is what you do primarily, your perspective will be somewhat different - you will not need
any explanation of why it is needed or when, and you may be only looking for a way to enclose up your web scraping code
in API services. This article will explain that too.&lt;/p&gt;
&lt;h2 id=&quot;introducing-playwright&quot;&gt;Introducing Playwright&lt;/h2&gt;
&lt;p&gt;The nice part of Playwright is that we can use it to visually prepare a draft of Python code that will scrape a given resource.
That is, instead of programming it in Python, we go to an address, fill out a form, click buttons and otherwise use everything
as usually and Playwright generates for us code that will be later used in integrations.&lt;/p&gt;
&lt;p&gt;That code will require a bit of clean-up work, which I will talk about below, but overall it works very nicely and is certainly useful.
The result is not one of these do-not-touch auto-generated pieces of code that are better left to their own.&lt;/p&gt;
&lt;p&gt;While there are
&lt;a href=&quot;https://zato.io/en/blog/jira-python-api.html&quot;&gt;better ways to integrate with Jira&lt;/a&gt;,
I chose that application as an example of Playwright&#x27;s usage simply because I cannot show you any internal
application in a public blog post.&lt;/p&gt;
&lt;p&gt;Below, there are two windows. One is Playwright&#x27;s emulating a Blackberry device to open a resource. I was clicking around,
I provided an email address and then I clicked the same email field once more. To the right, based on my actions, we can find
the generated Python code, which I consider quite good and readable.&lt;/p&gt;
&lt;p&gt;The Playwright Inspector, the tool that gave us the code, will keep recording all of our actions until we click the &quot;Record&quot; button
which then allows us to click the button next to &quot;Record&quot; which is &quot;Copy code to clipboard&quot;. We can then save the code
to a separate file and run it on demand, automatically.&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-web-scraping/playwright-inspector.png&quot;/&gt;
&lt;/center&gt;

&lt;p&gt;But first, we will need to install Playwright.&lt;/p&gt;
&lt;h2 id=&quot;installing-and-starting-playwright&quot;&gt;Installing and starting Playwright&lt;/h2&gt;
&lt;p&gt;The tools is written in TypeScript and can be installed using npx, which in turn is part of NodeJS.&lt;/p&gt;
&lt;p&gt;Afterwards,
the &quot;playwright install&quot; call is needed as well because that will potentially install runtime dependencies, such as
Chrome libraries.&lt;/p&gt;
&lt;p&gt;Finally, we install Playwright using pip as well because we want to access with Python. Note that if you are installing
Playwright under Zato, the &quot;/path/to/pip&quot; will be typically &quot;/opt/zato/code/bin/pip&quot;.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;npx&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-g&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;--yes&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;playwright&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;playwright&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;/path/to/pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;playwright
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;We can now start it as below. I am using BlackBerry as an example of what Playwright is capable of.
Also, it is usually more convenient to use a mobile version of a site when the main window and Inspector are opened
side by side, but you may prefer to use Chrome, Firefox or anything else.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;playwright&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;codegen&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;https://example.atlassian.net/jira&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;--device&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;BlackBerry Z30&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That is practically everything as using Playwright to generate code in our context goes. Open the tool, fill out forms,
copy code to a Python module, done.&lt;/p&gt;
&lt;p&gt;What is still needed, though, is cleaning up the resulting code and embedding it in an API integration process.&lt;/p&gt;
&lt;h2 id=&quot;code-clean-up&quot;&gt;Code clean-up&lt;/h2&gt;
&lt;p&gt;After you keep using Playwright for a while with longer forms and pages, you will note that the generated code
tends to accumulate parts that repeat.&lt;/p&gt;
&lt;p&gt;For instance, in the module below, which I already cleaned up, the same &quot;[placeholder=\&quot;Enter email\&quot;]&quot; reference
to the email field is used twice, even if a programmer developing this could would prefer to introduce
a variable for that.&lt;/p&gt;
&lt;p&gt;There is not a good answer to the question of what to do about it. On the one hand, obviously, being programmers we would prefer
not to repeat that kind of details. On the other hand, if we clean up the code too much, this may result in too much
of a maintenance burden because we need to keep it mind that we do not really want to invest to much in web scraping and,
should there be a need to repeat the whole process, we do not want to end up with Playwright&#x27;s code auto-generated from scratch
once more, without any of our clean-up.&lt;/p&gt;
&lt;p&gt;A good compromise position is to at least extract any kind of credentials from the code to environment variables or
a similar place and to remove some of the code comments that Playwright generates. The result
as below is what it should like at the end. Not too much effort without leaving the whole code as it was originally either.&lt;/p&gt;
&lt;p&gt;Save the code below as &quot;play1.py&quot; as this is what the API service below will use.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# stdlib&lt;/span&gt;
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;a id=&quot;line-2-5&quot; name=&quot;line-2-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-6&quot; name=&quot;line-2-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Playwright&lt;/span&gt;
&lt;a id=&quot;line-2-7&quot; name=&quot;line-2-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;playwright.sync_api&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Playwright&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sync_playwright&lt;/span&gt;
&lt;a id=&quot;line-2-8&quot; name=&quot;line-2-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-9&quot; name=&quot;line-2-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-10&quot; name=&quot;line-2-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;Email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;APP_EMAIL&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;zato@example.com&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-11&quot; name=&quot;line-2-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;Password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;APP_PASSWORD&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-12&quot; name=&quot;line-2-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;Headless&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;APP_HEADLESS&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;a id=&quot;line-2-13&quot; name=&quot;line-2-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-14&quot; name=&quot;line-2-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;playwright&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Playwright&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-15&quot; name=&quot;line-2-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-16&quot; name=&quot;line-2-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;browser&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;playwright&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;chromium&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;launch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headless&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Headless&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# type: ignore&lt;/span&gt;
&lt;a id=&quot;line-2-17&quot; name=&quot;line-2-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;browser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-2-18&quot; name=&quot;line-2-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-19&quot; name=&quot;line-2-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Open new page&lt;/span&gt;
&lt;a id=&quot;line-2-20&quot; name=&quot;line-2-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;page&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_page&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-2-21&quot; name=&quot;line-2-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-22&quot; name=&quot;line-2-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Open project boards&lt;/span&gt;
&lt;a id=&quot;line-2-23&quot; name=&quot;line-2-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;page&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;goto&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://example.atlassian.net/jira/software/projects/ABC/boards/1&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-24&quot; name=&quot;line-2-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;page&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;goto&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://id.atlassian.com/login?continue=https%3A&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%2F%2F&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;example.atlassian.net&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%2F&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;login&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%3F&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;redirectCount%3D1&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%26d&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;est-url%3D&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%252F&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;jira&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%252F&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;software&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%252F&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;projects&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%252F&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ABC&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%252F&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;boards&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%252F&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%26a&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;pplication%3Djira&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-25&quot; name=&quot;line-2-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-26&quot; name=&quot;line-2-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Fill out the email&lt;/span&gt;
&lt;a id=&quot;line-2-27&quot; name=&quot;line-2-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;page&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;locator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;[placeholder=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Enter email&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;]&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-2-28&quot; name=&quot;line-2-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;page&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;locator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;[placeholder=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Enter email&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;]&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-29&quot; name=&quot;line-2-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-30&quot; name=&quot;line-2-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Click #login-submit&lt;/span&gt;
&lt;a id=&quot;line-2-31&quot; name=&quot;line-2-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;page&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;locator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;#login-submit&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;click&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-2-32&quot; name=&quot;line-2-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-33&quot; name=&quot;line-2-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sync_playwright&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;playwright&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-34&quot; name=&quot;line-2-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;playwright&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;web-scraping-as-a-standalone-activity&quot;&gt;Web scraping as a standalone activity&lt;/h2&gt;
&lt;p&gt;We have the generated code so the first thing to do with it is to run it from command line. This will result
in a new Chrome window&#x27;s accessing Jira - it is Chrome, not Blackberry, because that is the default for Playwright.&lt;/p&gt;
&lt;p&gt;The window will close soon enough but this is fine, that code only demonstrates a principle, it is not
a full integration task.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/path/to/play1.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It is also useful that we can run the same Python module from our IDE, giving us the ability to step through
the code line by line, observing what changes when and why.&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-web-scraping/vscode-debug.png&quot;/&gt;
&lt;/center&gt;

&lt;h2 id=&quot;web-scraping-as-an-api-service&quot;&gt;Web scraping as an API service&lt;/h2&gt;
&lt;p&gt;Finally, we are ready to invoke the standalone module from an API service, as in the following code that
we are also going to make available as a REST channel.&lt;/p&gt;
&lt;p&gt;A couple of notes about the Python service below:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We invoke Playwright in a subprocess, as &lt;a href=&quot;https://zato.io/en/docs/4.1/dev/examples/shell-commands.html&quot;&gt;a shell command&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;We accept input through &lt;a href=&quot;https://zato.io/en/docs/4.1/dev/model/index.html&quot;&gt;data models&lt;/a&gt; although we do not provide
  any output definition because it is not needed here&lt;/li&gt;
&lt;li&gt;When we invoke Playwright, we set the APP_HEADLESS to True which will ensure that it does not attempt to actually
  display a Chrome window. After all, we intend for this service to run on Linux servers, in backend,
  and such a thing will be unlikely to work in this kind of an environment.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Other than that, this is a straightforward Zato service - it receives input, carries out its work and a reply
is returned to the caller (here, empty).&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-4-1&quot; name=&quot;line-4-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-4-2&quot; name=&quot;line-4-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-3&quot; name=&quot;line-4-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# stdlib&lt;/span&gt;
&lt;a id=&quot;line-4-4&quot; name=&quot;line-4-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;dataclasses&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dataclass&lt;/span&gt;
&lt;a id=&quot;line-4-5&quot; name=&quot;line-4-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-6&quot; name=&quot;line-4-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-4-7&quot; name=&quot;line-4-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-4-8&quot; name=&quot;line-4-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-9&quot; name=&quot;line-4-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-4-10&quot; name=&quot;line-4-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-11&quot; name=&quot;line-4-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;nd&quot;&gt;@dataclass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-4-12&quot; name=&quot;line-4-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;WebScrapingDemoRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-4-13&quot; name=&quot;line-4-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;
&lt;a id=&quot;line-4-14&quot; name=&quot;line-4-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;
&lt;a id=&quot;line-4-15&quot; name=&quot;line-4-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-16&quot; name=&quot;line-4-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-4-17&quot; name=&quot;line-4-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-18&quot; name=&quot;line-4-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;WebScrapingDemo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-4-19&quot; name=&quot;line-4-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;demo.web-scraping&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-4-20&quot; name=&quot;line-4-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-21&quot; name=&quot;line-4-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SimpleIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-4-22&quot; name=&quot;line-4-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;WebScrapingDemoRequest&lt;/span&gt;
&lt;a id=&quot;line-4-23&quot; name=&quot;line-4-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-24&quot; name=&quot;line-4-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-4-25&quot; name=&quot;line-4-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-26&quot; name=&quot;line-4-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Path to a Python installation that Playwright was installed under&lt;/span&gt;
&lt;a id=&quot;line-4-27&quot; name=&quot;line-4-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;py_path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/python&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-4-28&quot; name=&quot;line-4-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-29&quot; name=&quot;line-4-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Path to a Playwright module with code to invoke&lt;/span&gt;
&lt;a id=&quot;line-4-30&quot; name=&quot;line-4-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;playwright_path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/the-playwright-module.py&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-4-31&quot; name=&quot;line-4-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-32&quot; name=&quot;line-4-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# This is a template script that we will invoke in a subprocess&lt;/span&gt;
&lt;a id=&quot;line-4-33&quot; name=&quot;line-4-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;command_template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-4-34&quot; name=&quot;line-4-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s2&quot;&gt;        APP_EMAIL=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{app_email}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; APP_PASSWORD=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{app_password}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; APP_HEADLESS=True &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{py_path}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{playwright_path}&lt;/span&gt;
&lt;a id=&quot;line-4-35&quot; name=&quot;line-4-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s2&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-4-36&quot; name=&quot;line-4-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-37&quot; name=&quot;line-4-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# This is our input data&lt;/span&gt;
&lt;a id=&quot;line-4-38&quot; name=&quot;line-4-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# type: WebScrapingDemoRequest&lt;/span&gt;
&lt;a id=&quot;line-4-39&quot; name=&quot;line-4-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-40&quot; name=&quot;line-4-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Extract credentials from the input ..&lt;/span&gt;
&lt;a id=&quot;line-4-41&quot; name=&quot;line-4-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;
&lt;a id=&quot;line-4-42&quot; name=&quot;line-4-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;
&lt;a id=&quot;line-4-43&quot; name=&quot;line-4-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-44&quot; name=&quot;line-4-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. build the full command, taking all the config into account ..&lt;/span&gt;
&lt;a id=&quot;line-4-45&quot; name=&quot;line-4-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;command_template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;a id=&quot;line-4-46&quot; name=&quot;line-4-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;app_email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-47&quot; name=&quot;line-4-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;app_password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-48&quot; name=&quot;line-4-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;py_path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;py_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-49&quot; name=&quot;line-4-49&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-49&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;49 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;playwright_path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;playwright_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-50&quot; name=&quot;line-4-50&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-50&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;50 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-4-51&quot; name=&quot;line-4-51&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-51&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;51 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-52&quot; name=&quot;line-4-52&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-52&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;52 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. invoke the command in a subprocess  ..&lt;/span&gt;
&lt;a id=&quot;line-4-53&quot; name=&quot;line-4-53&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-53&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;53 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;commands&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;invoke&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-4-54&quot; name=&quot;line-4-54&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-54&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;54 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-55&quot; name=&quot;line-4-55&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-55&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;55 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. if it was not a success, log the details received ..&lt;/span&gt;
&lt;a id=&quot;line-4-56&quot; name=&quot;line-4-56&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-56&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;56 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_ok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-4-57&quot; name=&quot;line-4-57&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-57&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;57 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Exit code -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exit_code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-4-58&quot; name=&quot;line-4-58&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-58&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;58 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Stderr -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stderr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-4-59&quot; name=&quot;line-4-59&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-59&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;59 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Stdout -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-4-60&quot; name=&quot;line-4-60&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-60&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;60 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-4-61&quot; name=&quot;line-4-61&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-61&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;61 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, the REST channel:&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-web-scraping/rest-menu.png&quot;/&gt;
&lt;/center&gt;

&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-web-scraping/rest-form.png&quot;/&gt;
&lt;/center&gt;

&lt;p&gt;The last thing to do is to invoke the service - I am using curl from the command line below but it could very well
be Postman or a similar option.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-5-1&quot; name=&quot;line-5-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;localhost:17010/demo/web-scraping&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-d&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;{&amp;quot;email&amp;quot;:&amp;quot;hello@example.com&amp;quot;, &amp;quot;password&amp;quot;:&amp;quot;abc&amp;quot;}&amp;#39;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There will be no Chrome window this time around because we run Playwright in the headless mode. There will be no output
from curl either because we do not return anything from the service but in server logs we will find details such as below.&lt;/p&gt;
&lt;p&gt;We can learn from the log that the command took close to 4 seconds to complete,
that the exit code was 0 (indicating success) and that is no stdout or stderr at all.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-6-1&quot; name=&quot;line-6-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;INFO&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Command&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;
&lt;a id=&quot;line-6-2&quot; name=&quot;line-6-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;nv&quot;&gt;APP_EMAIL&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;hello@example.com&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;APP_PASSWORD&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;abc&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;APP_HEADLESS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;True
&lt;a id=&quot;line-6-3&quot; name=&quot;line-6-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;/path/to/python
&lt;a id=&quot;line-6-4&quot; name=&quot;line-6-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;/path/to/the-playwright-module.py
&lt;a id=&quot;line-6-5&quot; name=&quot;line-6-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;completed&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;:00:03.844157,
&lt;a id=&quot;line-6-6&quot; name=&quot;line-6-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;exit_code&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-&amp;gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;len-out&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Bytes&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;len-err&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Bytes&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-6-7&quot; name=&quot;line-6-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;cid&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-&amp;gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zcmdc5422816b2c6ff9f10742134
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;We are now ready to continue to work on it - for instance, you will notice that the password is visible in logs
and this should not be allowed.&lt;/p&gt;
&lt;p&gt;But, all such works are extra in comparison with the main theme - we have Playwright, which is a a tool that allows
us to quickly integrate with frontend applications and we can automate it through API services. Just as expected.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Wed, 13 Nov 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/web-scraping-api-integrations.html</guid></item><item><title>Meaningful automation in Python</title><link>https://zato.io/en/blog/python-automation-integrations.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/python-automation-integrations.html&quot;&gt;Meaningful automation in Python&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-11-04, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;This article is an introduction to meaningful automation, integrations and interoperability with Zato, service-oriented thinking and Python.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/intro/high-level.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/&quot;&gt;Zato&lt;/a&gt; is &lt;strong&gt;a convenient and secure, Python-based, open-source, service-oriented platform for automation, integrations and interoperability.&lt;/strong&gt;
It is used to connect distributed systems or data sources and to build API-focused, middleware and backend applications.&lt;/p&gt;
&lt;p&gt;The platform is designed and built specifically with Python users in mind - often working in, and for, industries such as
&lt;a href=&quot;https://zato.io/en/industry/telecom/index.html&quot;&gt;telecommunications&lt;/a&gt;,
&lt;a href=&quot;https://zato.io/en/industry/defense/index.html&quot;&gt;defense&lt;/a&gt;,
&lt;a href=&quot;https://zato.io/en/industry/healthcare/index.html&quot;&gt;health care&lt;/a&gt;
and others that require automation, integrations and interoperability of multiple systems and processes.&lt;/p&gt;
&lt;p&gt;Sample real-world, mission-critical Zato environments include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Systems for &lt;strong&gt;telecommunication operators&lt;/strong&gt; integrating CRM, ERP, Charging Systems, Billing and other &lt;strong&gt;OSS/BSS&lt;/strong&gt;
  applications internal or external to the operators, including &lt;strong&gt;network automation&lt;/strong&gt; of &lt;strong&gt;packet brokers&lt;/strong&gt;
  and other &lt;strong&gt;network visibility&lt;/strong&gt; and &lt;strong&gt;cybersecurity&lt;/strong&gt; tools from &lt;a href=&quot;https://www.keysight.com/us/en/home.html&quot;&gt;Keysight&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Enterprise services buses&lt;/strong&gt; for &lt;strong&gt;government&lt;/strong&gt;, helping in the &lt;strong&gt;digital transformation&lt;/strong&gt; of &lt;strong&gt;legacy&lt;/strong&gt; systems
  and processes towards &lt;strong&gt;modern capabilities&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;AI&lt;/strong&gt;, &lt;strong&gt;ML&lt;/strong&gt; and &lt;strong&gt;data science&lt;/strong&gt; systems that analyze and improve &lt;strong&gt;acquisition&lt;/strong&gt; and &lt;strong&gt;supply chain&lt;/strong&gt; activities in
  &lt;strong&gt;government&lt;/strong&gt; processes&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Applied observability&lt;/strong&gt; automation that enables &lt;strong&gt;meaningful decision making&lt;/strong&gt; through
  the orchestration and coordination of the collection, distribution and presentation of data spread across
  a pool of independent systems&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Platforms for &lt;strong&gt;health care&lt;/strong&gt; and  &lt;strong&gt;public administration&lt;/strong&gt; systems, helping to achieve &lt;strong&gt;data interoperability&lt;/strong&gt; through the
  integration of independent data sources, databases and health information exchanges (HIE)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Global &lt;strong&gt;IoT&lt;/strong&gt; platforms for &lt;strong&gt;hybrid integrations&lt;/strong&gt; of medical devices and software both in the &lt;strong&gt;cloud&lt;/strong&gt; and &lt;strong&gt;on premises&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Cybersecurity&lt;/strong&gt; automation, including &lt;strong&gt;IT/OT hardware&lt;/strong&gt; and software assets&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Robotic process automation (RPA)&lt;/strong&gt; of &lt;strong&gt;message flows&lt;/strong&gt; and &lt;strong&gt;events&lt;/strong&gt; produced by early warning systems&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Zato offers connectors to all the popular technologies and vendors, such as REST, Cloud, task scheduling, Microsoft 365,
Salesforce, Atlassian, SAP, Odoo, SQL, HL7, FHIR, AMQP, IBM MQ, LDAP, Redis, MongoDB, WebSockets, SOAP, Caching and many more.&lt;/p&gt;
&lt;p&gt;Running in the cloud, on premises, or under Docker, Kubernetes and other container technologies, Zato services are
optimized for high performance and security - it is easily possible to run hundreds and thousands of services on typical server
instances as offered by Amazon, Google Cloud, Azure or other cloud providers.&lt;/p&gt;
&lt;p&gt;Zato servers offer high availability and no-downtime deployment. Servers form clusters that are used to scale
systems both horizontally and vertically.&lt;/p&gt;
&lt;p&gt;The product is commercial open-source software with
&lt;a href=&quot;https://zato.io/en/services/index.html&quot;&gt;training, professional services and enterprise 24x7x365 support&lt;/a&gt; available.&lt;/p&gt;
&lt;h2 id=&quot;a-platform-and-language-for-interesting-reusable-and-atomic-services&quot;&gt;A platform and language for interesting, reusable and atomic services&lt;/h2&gt;
&lt;p&gt;Zato promotes the design of, and helps you build, solutions composed of services
that are &lt;strong&gt;interesting, reusable and atomic (IRA)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/intro/ira.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;What does it really mean in practice that something is interesting, reusable and atomic? In particular,
how do we define what is &lt;strong&gt;interesting&lt;/strong&gt;?&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/intro/service-interesting.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Each &lt;strong&gt;interesting&lt;/strong&gt; service should make its users want to keep using it more and more. People should immediately see
the value of using the service in their processes. An interesting service strikes everyone as immediately useful in wider
contexts, preferably with few or no conditions, prerequisites and obligations.&lt;/p&gt;
&lt;p&gt;An interesting service is aesthetically pleasing, both in terms of its technical usage as well as its
relevance to, and potential applicability in, fields broader than originally envisioned. If people check the service and say
&quot;I know, we will definitely use it&quot; or &quot;Why don&#x27;t we use it&quot; you know that the service is interesting.
If they say &quot;Oh no, not this one again&quot; or &quot;No, thanks, but no&quot; then it is the opposite.&lt;/p&gt;
&lt;p&gt;Note that focus here is on the &lt;strong&gt;value&lt;/strong&gt; that the service brings for the user. You constantly need to keep in mind
that people generally want to use services only if they allow them to fulfill their plans or execute some bigger ideas.
Perhaps they already have them in mind and they are only looking for technical means of achieving that or perhaps
it is your services that will make a person realize that something is possible at all, but the point is the same,
your service should serve a grander purpose.&lt;/p&gt;
&lt;p&gt;This mindset, of wanting to build things that are useful and interesting is not specific to Python or, indeed,
to software and technology. Even if you are designing and implementing services for your own purposes,
you need to act as if you were a consultant that can always see a bigger vision, a bigger architecture, and who
can envision results that are still ahead in the future while at the same time not forgetting that it is always
a series of small interesting actions, that everyone can relate to, that lead to success.&lt;/p&gt;
&lt;p&gt;A curious observation can be made, particularly when you consider all the various aspects of the &lt;strong&gt;digital transformation&lt;/strong&gt;
that companies and organizations go through, is that many people to whom the services are addressed, or who sponsor
their development, are surprised when they see what automation and integrations are capable.&lt;/p&gt;
&lt;p&gt;Put differently, many people can only begin to visualize bigger designs once they see in practice smaller, practical
results that further their missions, careers and otherwise help them at work. This is why, again, the focus on being
interesting is essential.&lt;/p&gt;
&lt;p&gt;At the same, it can be at times advantageous to you that people will not see automation or integrations coming. That lets you
take the lead and build a center of such a fundamental shift around yourself. This is a great position to be in,
a blue ocean of possibilities, because it means little to no competition inside an organization that you are a part of.&lt;/p&gt;
&lt;p&gt;If you are your own audience, that is, if you build services for your own
purposes, the same principles apply and it is easy to observe that thinking in services lets you build a toolbox of reusable,
complementary capabilities, a portfolio, that you can take with you as you progress in your career. For instance, your services,
and your work, can concentrate on a particular vendor and with a set of services that automate their products,
you will be always able to put that into use, shorting your own development time, no matter who employs you and in what way.&lt;/p&gt;
&lt;p&gt;Regardless of who the clients that you build the solutions for are, observe that automation and integrations with services
are evolutionary and incremental in their nature, at least initially. Yes, the resulting value can often be revolutionary
but you do not intend to incur any massive changes until there are clear, interesting results available. Trying to integrate
and change existing systems at the same time is doable, but not trivial, and it is best left to later stages, once your
automation gets the necessary buy-in from the organization.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/intro/service-reusable.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Services should be ready to be used in different, independent processes. The processes can be strictly business ones, such as
processing of orders or payments, or they can be of a deep, technical nature, e.g. automating cybersecurity hardware. What matters
in either case is that &lt;strong&gt;reusability breeds both flexibility and stability&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;There is inherent flexibility in being able to compose bigger processes out of smaller blocks with clearly defined boundaries,
which can easily translate to increased competitive advantage when services are placed into more and more areas.
A direct result of this is a &lt;strong&gt;reduction in R&amp;amp;D time&lt;/strong&gt; as, over time, you are able to choose from a collection
of loosely-coupled components, the services, that hide implementation details of a particular system or technology
that they automate or integrate with.&lt;/p&gt;
&lt;p&gt;Through their continued use in different processes, services can reduce
overall implementation risks that are always part of any kind of software development - you will know that you can keep
reusing stable functionality that has been already well tested and that is used elsewhere.&lt;/p&gt;
&lt;p&gt;Because services are reusable, there is no need for gigantic, pure waterfall-style implementations of automation and integrations
in an organization. Each individual project can contribute a smaller set of services that, as a whole, constitute the whole
integrated environment. Conversely, each new project can start to reuse services delivered by the previous ones,
hence allowing you to quickly, incrementally, prove the value of the investment in service-oriented thinking.&lt;/p&gt;
&lt;p&gt;To make them reusable, services are designed in a way that hides their implementation details. Users only need to know how
to invoke the service; the specific systems or processes it automates or integrates are not necessarily
important for them to know as long as a specific business goal is achieved. Thanks to that, both services and what
they integrate can be replaced without disrupting other parts - in reality, this is exactly what happens - systems with
various kinds of data will be changed or modernized but the service will stay the same and the user will not notice anything.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/intro/service-atomic.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Each service fulfills a single, atomic business need. Each service is deployed independently and, as a whole, they constitute
an implementation of business processes taking place in your company or organization. Note that the definition of what the
business need is, again, specific to your own needs. In purely market-oriented integrations, this may mean, for instance,
the opening of a bank account. In IT or OT automation, on the other hand, it may mean the reconfiguration of a specific device.&lt;/p&gt;
&lt;p&gt;That services are atomic also means that they are discrete and that their functionality is finely grained. You will recognize
whether a design goes in this direction if consider the names of the services for a moment. An atomic service will invariably
use a short name consisting of a single verb and noun. For instance, &quot;Create Customer Account&quot;, &quot;Stop Firewall&quot;,
&quot;Conduct Feasibility Study&quot;, it is easy to see that we cannot break them down into smaller part, they are atomic.&lt;/p&gt;
&lt;p&gt;At the same time, you will keep creating composite services that invoke other services; this is natural and as expected
but you will not consider services such as &quot;Create Customer Account and Set Up a SIM Card&quot; as atomic ones because, in that form,
they will not be very reusable, and a major part of why being atomic is important is that it promotes reusability. For instance,
having separate services to create customer accounts, independently of setting up their SIM cards, is that one can without
difficulty foresee situations when an account is created but a SIM card is purchased at a later time and, conversely,
surely one customer account should be able to potentially have multiple SIM cards. Think of it as being similar to LEGO bricks
where just a few basic shapes can form millions of interesting combinations.&lt;/p&gt;
&lt;p&gt;The point about service naming conventions is well worth remembering because this lets you maintain a vocabulary
that is common to both technical and business people. A technical person will understand that such naming is akin to the CRUD
convention from the web programming world while a business person will find it easy to map the meaning to a specific
business function within a broader business process.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/static/img/intro/service-python.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;With Zato, you use Python to focus on the business logic exclusively and the platform takes care of scalability, availability
 communications protocols, messaging, security or routing. This lets you concentrate only on what is the very core of systems
 integrations - making sure their services are interesting, reusable and atomic.&lt;/p&gt;
&lt;p&gt;Python is the perfect choice for this job because it hits the sweet spot under several key headings:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;It is a very high level language, with a syntax close to how grammar of various spoken languages works,
  which makes it easy to translate business requirements into implementation&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It is a solid, mainstream and full-featured, real programming language rather than a domain-specific one which
  means that it offers a great degree of flexibility and choice in expressing their needs&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It is difficult to find universities without Python courses. Most people entering the workforce already know Python,
  it is a new career language. In fact, it is becoming more and more difficult to find new talent who would not prefer
  to use Python.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Yet, one does not need to be a developer or a full-time programmer to use Python. In fact, most people who use Python
  are not programmers at all. They are specialists in other fields who also need to use a programming language to
  automate or integrate their work in a meaningful way.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Many Python users come from backgrounds in network and cybersecurity engineering - fields that naturally require a lot of
  automation using a real language that is convenient and easy to get started with&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Many Python users are scientists with a background in AI, ML and data science, applying their domain-specific knowledge
  in processes that, by their very nature, require them to collect and integrate data from independent sources,
  which again leads to automation and integrations&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Many Python users have a strong web programming background which means that it takes little effort
  to take a step further, towards automation and integrations. In turn, this means that it is easy
  to find good people for API projects.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Many Python users know multiple programming languages - this is very useful in the context of integration projects
  where one is typically faced with dozens of technologies, vendors or integration methods and techniques.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Lower maintenance costs - thanks to the language&#x27;s unique design, Python programmers
  tend to produce code that is easy to read and understand. From the perspective of multi-year maintenance,
  reading and analyzing code, rather than writing it, is what most programmers do most of the time,
  making sense to use a language that makes it easy to carry out the most common tasks.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In short, Python can be construed as executable pseudo-code with many of its users already having roots in
modern server-side programming so Zato, both from a technical and strategic perspective, is a natural choice for
both simple and complex, sophisticated automation, integration and interoperability solutions as a platform built in the
language and designed for Python people from day one.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 04 Nov 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/python-automation-integrations.html</guid></item><item><title>Salesforce API integrations and connected apps</title><link>https://zato.io/en/blog/salesforce-credentials.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/salesforce-credentials.html&quot;&gt;Salesforce API integrations and connected apps&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-10-28, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;This instalment in a series of articles about API integrations with Salesforce
covers connected apps - how to create them
and how to obtain their credentials needed to exchange REST messages with Salesforce.&lt;/p&gt;
&lt;p&gt;In Salesforce&#x27;s terminology, a connected app is, essentially, an API client. It has credentials, a set of permissions,
and it works on behalf of a user in an automated manner.&lt;/p&gt;
&lt;p&gt;In particular, the kind of a connected app that I am going to create below is one that can be used in backend, server-side
integrations that operate without any direct input from end users or administrators, i.e. the app is created once, its permissions
and credentials are set once, and then it is able to work uninterrupted in the background, on server side.&lt;/p&gt;
&lt;p&gt;Server-side systems are quite unlike other kinds of apps, such as mobile ones, that assume there is a human operator involved -
they have their own work characteristics, related yet different, and I am not going to cover them here.&lt;/p&gt;
&lt;p&gt;Note that permission types and their scopes are a separate, broad subject and they will described in a separate how-to article.&lt;/p&gt;
&lt;p&gt;Finally, I assume that you are either an administrator in a Salesforce organization or that you are preparing information
for another person with similar grants in Salesforce.&lt;/p&gt;
&lt;p&gt;Conceptually, there is nothing particularly unusual about Salesforce connected apps, it is just its own mini-world
of jargon and, at the end of the day, it simply enables you to invoke APIs that Salesforce is built on. It is just that knowing
where to click, what to choose and how to navigate the user interface can be a daunting challenge that this article hopes
to make easier to overcome.&lt;/p&gt;
&lt;h2 id=&quot;the-steps&quot;&gt;The steps&lt;/h2&gt;
&lt;p&gt;For an automated, server-side connected app to make use of Salesforce APIs, the requirements are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Having access to username/password credentials&lt;/li&gt;
&lt;li&gt;Creating a connected app&lt;/li&gt;
&lt;li&gt;Granting permissions to the app (not covered in this article)&lt;/li&gt;
&lt;li&gt;Obtaining a customer key and customer secret for the app&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You will note that there are four credentials in total:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Username&lt;/li&gt;
&lt;li&gt;Password&lt;/li&gt;
&lt;li&gt;Customer key&lt;/li&gt;
&lt;li&gt;Customer secret&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also, depending on what chapter of the Salesforce documentation you are reading, you will note that the customer key
can be also known as &quot;client_id&quot; whereas another name for the customer secret is &quot;client_secret&quot;. These two pairs
mean the same.&lt;/p&gt;
&lt;h2 id=&quot;access-to-usernamepassword-credentials&quot;&gt;Access to username/password credentials&lt;/h2&gt;
&lt;p&gt;For starters, you need to have an account in Salesforce, a combination of username + password that you can log in with
and on whose behalf the connected app will be created:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/app-login.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;creating-a-connected-app&quot;&gt;Creating a connected app&lt;/h2&gt;
&lt;p&gt;Once you are logged in, go to Setup in the top right-hand corner:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/app-setup.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;In the search box, look up &quot;app manager&quot;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/app-search-manager.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Next, click the &quot;New Connected App&quot; button to the right:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/app-new-connected-button.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Fill out the basic details such as &quot;Connect App Name&quot; and make sure that you select &quot;Enable OAuth Settings&quot;. Then,
given that in this document we are not dealing with the subject of permissions at all, grant full access to the connected
app and finally click &quot;Save&quot; at the bottom of the page.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/app-full-access.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;obtaining-a-customer-key-and-customer-secret&quot;&gt;Obtaining a customer key and customer secret&lt;/h2&gt;
&lt;p&gt;We have a connected app but we still do not know what its customer key and secret are. To reveal it, go to the &quot;App Manager&quot;
once more, either via the search box or using the menu on the left hand side.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/app-manager-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Find your app in the list and click &quot;View&quot; in the list of actions. Observe that it is &quot;View&quot;, not &quot;Edit&quot; or &quot;Manage&quot;, where
you can check what the credentials are:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/app-view.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;The customer key and secret van be now revealed in the &quot;API (Enable OAuth Settings)&quot; section:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-salesforce/app-view-secrets.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;This concludes the process - you have a connected app and all the credentials needed now.&lt;/p&gt;
&lt;h2 id=&quot;testing&quot;&gt;Testing&lt;/h2&gt;
&lt;p&gt;Seeing as this document is part of a series of how-tos in the context of Zato, if you would like to integrate with Salesforce in
Python, at this point you will be able to follow the steps in
&lt;a href=&quot;https://zato.io/en/blog/salesforce-python.html&quot;&gt;another&lt;/a&gt;
where everything is detailed separately.&lt;/p&gt;
&lt;p&gt;Just as a quick teaser, it would look akin to the below.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Salesforce REST API endpoint to invoke&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/sobjects/Campaign/&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Build the request to Salesforce based on what we received&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;  &lt;span class=&quot;s1&quot;&gt;&amp;#39;Name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;  &lt;span class=&quot;s1&quot;&gt;&amp;#39;Segment__c&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;segment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Create a reference to our connection definition ..&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;salesforce&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;salesforce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My Salesforce Connection&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# .. obtain a client to Salesforce ..&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salesforce&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# type: SalesforceClient&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# .. create the campaign now.&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;On a much lower level, however, if you would just like to quickly test out whether you configured the connected app correctly,
you can invoke from command line a Salesforce REST endpoint that will return an OAuth token, as below.&lt;/p&gt;
&lt;p&gt;Note that, as I mentioned it previously, client_id is the same as customer key and client_secret is the same as customer secret.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;https://example.my.salesforce.com/services/oauth2/token&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;   &lt;/span&gt;-H&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;X-PrettyPrint: 1&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--header&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Content-Type: application/x-www-form-urlencoded&amp;#39;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--data-urlencode&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;grant_type=password&amp;#39;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-1-5&quot; name=&quot;line-1-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--data-urlencode&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;username=hello@example.com&amp;#39;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-1-6&quot; name=&quot;line-1-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--data-urlencode&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;password=my.password&amp;#39;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-1-7&quot; name=&quot;line-1-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--data-urlencode&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;client_id=my.customer.key&amp;#39;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-1-8&quot; name=&quot;line-1-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--data-urlencode&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;client_secret=my.client.secret&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The result will be, for instance:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;access_token&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;008e0000000PTzLPb!4Vzm91PeIWJo.IbPzoEZf2ygEM.6cavCt0YwAGSM&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;instance_url&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://example.my.salesforce.com&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://login.salesforce.com/id/008e0000000PTzLPb/0081fSUkuxPDrir000j1&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-2-5&quot; name=&quot;line-2-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;token_type&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Bearer&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-2-6&quot; name=&quot;line-2-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;issued_at&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;1649064143961&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-2-7&quot; name=&quot;line-2-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;signature&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;dwb6rwNIzl76kZq8lQswsTyjW2uwvTnh=&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-2-8&quot; name=&quot;line-2-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Above, we have an OAuth bearer token on output - this can be used in subsequent, business REST calls to Salesforce but how to
do it exactly in practice is left for another article.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 28 Oct 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/salesforce-credentials.html</guid></item><item><title>HL7 FHIR Security with Basic Auth, OAuth and SSL/TLS</title><link>https://zato.io/en/blog/hl7-fhir-security.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/hl7-fhir-security.html&quot;&gt;HL7 FHIR Security with Basic Auth, OAuth and SSL/TLS&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-10-21, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;h2 id=&quot;hl7-fhir-security&quot;&gt;HL7 FHIR Security&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Preliminary reading&lt;/strong&gt;: &lt;a href=&quot;https://zato.io/en/docs/4.1/dev/healthcare/hl7/fhir/index.html&quot;&gt;HL7 FHIR Integrations in Python&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/fhir-security.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;FHIR servers offer their APIs using REST, which in turn means that they are HTTP servers under the hood. As a result,
a few common security mechanisms can be employed to secure access to the servers when you invoke them.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Basic Auth&lt;/li&gt;
&lt;li&gt;OAuth&lt;/li&gt;
&lt;li&gt;SSL/TLS encryption&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you integrate with a FHIR server, consult with its maintainers what of these, if any, should be used.&lt;/p&gt;
&lt;p&gt;Note that Basic Auth and OAuth, when used over HTTP, are mutually exclusive. The HTTP protocol reserves only one header,
called Authorization, for the authorization credentials and there is no standard way in the protocol to use more than
one authorization mechanism.&lt;/p&gt;
&lt;p&gt;On the other hand, the SSL/TLS encryption is independent of the credentials used and can be employed with Basic Auth,
OAuth, or in scenarios when no authorization header is sent at all.&lt;/p&gt;
&lt;p&gt;This is why, when you create or update a FHIR connection, you can set Basic Auth or OAuth and SSL/TLS options independently,
as in the screenshot below:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/fhir-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/fhir-form-2.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;basic-auth&quot;&gt;Basic Auth&lt;/h2&gt;
&lt;p&gt;Basic Auth is a combination of username and password credentials. They are allocated in advance by the maintainers of a FHIR
server.&lt;/p&gt;
&lt;p&gt;To use them in your integrations, create a new Basic Auth definition in the Dashboard, set its password, and assign it to an
existing or new outgoing FHIR connection. No restarts nor reloads are required.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/sec-basic-auth-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/sec-basic-auth-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/sec-basic-auth-password.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;oauth&quot;&gt;OAuth&lt;/h2&gt;
&lt;p&gt;Authentication with OAuth is built around a notion of short-lived tokens, which are simple strings. Your Zato server has
credentials, much like a username and password although they are called a client ID and secret, based on which an authentication
server issues tokens that let Zato prove that in fact it does have the correct credentials and that it is allowed to invoke
a particular API as it is defined through scopes.&lt;/p&gt;
&lt;p&gt;Scopes can be likened to permissions to access a subset of resources from a FHIR server. When Zato receives a token from
an authentication server the token is inherently linked to specific scopes within which it can interact with the FHIR server.&lt;/p&gt;
&lt;p&gt;That tokens are short-lived means that they need to be refreshed periodically, e.g. at least once per hour Zato needs to
ask the authentication server for a new token based on its credentials. This process takes place under the hood and requires
no configuration on your part.&lt;/p&gt;
&lt;p&gt;To use OAuth in your integrations, create a new OAuth definition in the Dashboard, set its secret, and assign it to an
existing or new outgoing FHIR connection. No restarts nor reloads are required.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/sec-oauth-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/sec-oauth-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/sec-oauth-password.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;ssltls-encryption&quot;&gt;SSL/TLS encryption&lt;/h2&gt;
&lt;p&gt;If the FHIR server that a connection points to uses SSL/TLS then a question arises of how to validate the certificate of the
Certificate Authority (CA) that signed the certificate that the FHIR server uses. There are several options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Skip validation - the certificate will not be validated at all and it will be always accepted.&lt;/li&gt;
&lt;li&gt;Default bundle - the certificate will have to belong to one of the publicly recognized CAs. The bundle contains the same
  certificates that common web browsers do so this option is good if the FHIR server is available in the public Internet,
  e.g. https://fhir.example.com&lt;/li&gt;
&lt;li&gt;Custom bundle - if the FHIR server&#x27;s certificate was signed by an internal, non-public CA then the CA&#x27;s certificate bundle,
  in the PEM format, can be uploaded through the Dashboard to make it possible to choose it when the FHIR connection is being
  created or updated.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/tls-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/tls-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-fhir-security/tls-ca-field.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 21 Oct 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/hl7-fhir-security.html</guid></item><item><title>API testing in pure English</title><link>https://zato.io/en/blog/api-testing-in-pure-english.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/api-testing-in-pure-english.html&quot;&gt;API testing in pure English&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-10-07, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;
&lt;h2 id=&quot;how-to-test-apis-in-pure-english&quot;&gt;How to test APIs in pure English&lt;/h2&gt;
&lt;p&gt;Do you have 20 minutes to learn how to test APIs in pure English, without any programming needed?&lt;/p&gt;
&lt;p&gt;Great, the &lt;a href=&quot;https://zato.io/en/docs/4.1/api-testing/tutorial/01.html&quot;&gt;API testing tutorial is here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Right after you complete it, you&#x27;ll be able to write API tests as the one below.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/en/docs/4.1/gfx/api-testing/demo.webp&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;next-steps&quot;&gt;Next steps:&lt;/h2&gt;
&lt;p&gt;➤  Read about &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;how to use Python to build and integrate enterprise APIs&lt;/a&gt; that your tests will cover
&lt;br/&gt;
➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 07 Oct 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/api-testing-in-pure-english.html</guid></item><item><title>Akenza IoT Python WebSockets</title><link>https://zato.io/en/blog/akenza-iot-python-websockets.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/akenza-iot-python-websockets.html&quot;&gt;Akenza IoT Python WebSockets&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-09-16, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;
&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;https://akenza.io/&quot;&gt;Akenza&lt;/a&gt; IoT platform, on its own, excels in collecting and managing data from a myriad of IoT devices.
However, it is integrations with other systems, such as enterprise resource planning (ERP), customer
relationship management (CRM) platforms, workflow management or environmental monitoring tools that enable a complete
view of the entire organizational landscape.&lt;/p&gt;
&lt;p&gt;Complementing Akenza&#x27;s capabilities, and enabling the smooth integrations, is the versatility of Python programming.
Given how flexible Python is, the language is a natural choice when looking for a bridge between Akenza
and the unique requirements of an organization looking to connect its intelligent infrastructure.&lt;/p&gt;
&lt;p&gt;This article is about combining the two, Akenza and Python. At the end of it, you will have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A bi-directional connection to Akenza using Python and WebSockets&lt;/li&gt;
&lt;li&gt;A Python service subscribed to and receiving events from IoT devices through Akenza&lt;/li&gt;
&lt;li&gt;A Python service that will be sending data to IoT devices through Akenza&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since WebSocket connections are persistent, their usage enhances the responsiveness of IoT applications
which in turn helps to exchange occurs in real-time, thus fostering a dynamic and agile integrated ecosystem.&lt;/p&gt;
&lt;h2 id=&quot;python-and-akenza-websocket-connections&quot;&gt;Python and Akenza WebSocket connections&lt;/h2&gt;
&lt;p&gt;First, let&#x27;s have a look at full Python code - to be discussed later.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt; &lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;WSXAdapter&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###############################################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###############################################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.generic.api.outconn.wsx.common&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OnClosed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; \
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;OnConnected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OnMessageReceived&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###############################################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###############################################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;DemoAkenza&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;WSXAdapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Our name&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;demo.akenza&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;on_connected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;OnConnected&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;None&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Akenza OnConnected -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###############################################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;on_message_received&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;OnMessageReceived&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;None&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Confirm what we received&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Akenza OnMessageReceived -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# This is an indication that we are connected ..&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;type&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;connected&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. for testing purposes, use a fixed asset ID ..&lt;/span&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;asset_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;str&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;abc123&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. build our subscription message ..&lt;/span&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;type&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;subscribe&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;subscriptions&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;assetId&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;asset_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;topic&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;*&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}]}&lt;/span&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-40&quot; name=&quot;line-0-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-41&quot; name=&quot;line-0-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-42&quot; name=&quot;line-0-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-43&quot; name=&quot;line-0-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. if we are here, it means that we received a message other than type &amp;quot;connected&amp;quot;.&lt;/span&gt;
&lt;a id=&quot;line-0-44&quot; name=&quot;line-0-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Akenza message (other than &amp;quot;connected&amp;quot;) -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-45&quot; name=&quot;line-0-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-46&quot; name=&quot;line-0-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-47&quot; name=&quot;line-0-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-48&quot; name=&quot;line-0-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;on_closed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;OnClosed&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;None&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-49&quot; name=&quot;line-0-49&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-49&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;49 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Akenza OnClosed -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ctx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-50&quot; name=&quot;line-0-50&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-50&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;50 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-51&quot; name=&quot;line-0-51&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-51&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;51 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-52&quot; name=&quot;line-0-52&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-52&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;52 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################################&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, deploy the code to &lt;a href=&quot;https://zato.io/&quot;&gt;Zato&lt;/a&gt; and create a new outgoing WebSocket connection. Replace the API key with your own
and make sure to set the data format to JSON.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-akenza/create-websocket-akenza-connection-python.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;receiving-messages-from-websockets&quot;&gt;Receiving messages from WebSockets&lt;/h2&gt;
&lt;p&gt;The WebSocket Python services that you author have three methods of interest, each reacting to specific events:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;on_connected&lt;/strong&gt; - Invoked as soon as a WebSocket connection has been opened. Note that this is a low-level event and,
  in the case of Akenza, it does not mean yet that you are able to send or receive messages from it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;on_message_received&lt;/strong&gt; - The main method that you will be spending most time with. Invoked each time a remote WebSocket sends,
  or pushes, an event to your service. With Akenza, this method will be invoked each time Akenza has something to
  inform you about, e.g. that you subscribed to messages, that&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;on_closed&lt;/strong&gt; - Invoked when a WebSocket has been closed. It is no longer possible to use a WebSocket once it has been closed.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let&#x27;s focus on &lt;strong&gt;on_message_received&lt;/strong&gt;, which is where the majority of action takes place. It receives a single parameter
of type OnMessageReceived which describes the context of the received message. That is, it is in the &quot;ctx&quot; that you will
both the current request as well as a handle to the WebSocket connection through which you can reply to the message.&lt;/p&gt;
&lt;p&gt;The two important attributes of the context object are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;ctx.data&lt;/strong&gt; - A dictionary of data that Akenza sent to you&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;ctx.conn&lt;/strong&gt; - The underlying WebSocket connection through which the data was sent and through you can send a response&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, the logic from lines 30-40 is clear:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, we check if Akenza confirmed that we are connected (type==&#x27;connected&#x27;). You need to check the type of a message each
  time Akenza sends something to you and react to it accordingly.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Next, because we know that we are already connected (e.g. our API key was valid) we can subscribe to events from a given
  IoT asset. For testing purposes, the asset ID is given directly in the source code but, in practice, this information
  would be read from a configuration file or database.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Finally, for messages of any other type we simply log their details. Naturally, a full integration would handle them
  per what is required in given circumstances, e.g. by transforming and pushing them to other applications or management
  systems.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A sample message from Akenza will look like this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;INFO - WebSocketClient -  Akenza message (other than &amp;quot;connected&amp;quot;) -&amp;gt; {&amp;#39;type&amp;#39;: &amp;#39;subscribed&amp;#39;,
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&amp;#39;replyTo&amp;#39;: None, &amp;#39;timeStamp&amp;#39;: &amp;#39;2023-11-20T13:32:50.028Z&amp;#39;,
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&amp;#39;subscriptions&amp;#39;: [{&amp;#39;assetId&amp;#39;: &amp;#39;abc123&amp;#39;, &amp;#39;topic&amp;#39;: &amp;#39;*&amp;#39;, &amp;#39;tagId&amp;#39;: None, &amp;#39;valid&amp;#39;: True}],
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&amp;#39;message&amp;#39;: None}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;how-to-send-messages-to-websockets&quot;&gt;How to send messages to WebSockets&lt;/h2&gt;
&lt;p&gt;An aspect not to be overlooked is communication in the other direction, that is, sending of messages to WebSockets.
For instance, you may have services invoked through REST APIs, or perhaps from a scheduler, and their job will be to
transform such calls into configuration commands for IoT devices.&lt;/p&gt;
&lt;p&gt;Here is the core part of such a service, reusing the same Akenza WebSocket connection:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt; &lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-2-5&quot; name=&quot;line-2-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-6&quot; name=&quot;line-2-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################################&lt;/span&gt;
&lt;a id=&quot;line-2-7&quot; name=&quot;line-2-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################################&lt;/span&gt;
&lt;a id=&quot;line-2-8&quot; name=&quot;line-2-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-9&quot; name=&quot;line-2-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;DemoAkenzaSend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-10&quot; name=&quot;line-2-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-11&quot; name=&quot;line-2-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Our name&lt;/span&gt;
&lt;a id=&quot;line-2-12&quot; name=&quot;line-2-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;demo.akenza.send&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-13&quot; name=&quot;line-2-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-14&quot; name=&quot;line-2-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;None&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-15&quot; name=&quot;line-2-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-16&quot; name=&quot;line-2-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# The connection to use&lt;/span&gt;
&lt;a id=&quot;line-2-17&quot; name=&quot;line-2-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Akenza&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-18&quot; name=&quot;line-2-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-19&quot; name=&quot;line-2-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get a connection ..&lt;/span&gt;
&lt;a id=&quot;line-2-20&quot; name=&quot;line-2-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wsx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-21&quot; name=&quot;line-2-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-22&quot; name=&quot;line-2-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. and send data through it.&lt;/span&gt;
&lt;a id=&quot;line-2-23&quot; name=&quot;line-2-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Hello&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-24&quot; name=&quot;line-2-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-25&quot; name=&quot;line-2-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################################&lt;/span&gt;
&lt;a id=&quot;line-2-26&quot; name=&quot;line-2-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################################&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that responses to the messages sent to Akenza will be received using your first service&#x27;s
&lt;strong&gt;on_message_received&lt;/strong&gt; method - WebSockets-based messaging is inherently asynchronous
and the channels are independent.&lt;/p&gt;
&lt;p&gt;Now, we have a complete picture of real-time, IoT connectivity with Akenza and WebSockets. We are able
to establish persistent, responsive connections to assets, we can subscribe to and send messages to devices,
and that lets us build intelligent automation and integration architectures that make use of powerful, emerging technologies.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 16 Sep 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/akenza-iot-python-websockets.html</guid></item><item><title>Automating telecommunications networks with Python and SFTP</title><link>https://zato.io/en/blog/sftp.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/sftp.html&quot;&gt;Automating telecommunications networks with Python and SFTP&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2024-07-29, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;
&lt;p&gt;In telecommunications, the Secure File Transfer Protocol (SFTP) serves as a critical mechanism
for secure and reliable file exchange between different network components devices, and systems,
whether it is updating configurations, network monitoring, exchanging customer data, or facilitating software updates.
Conversely, Python is an ideal tool for the automation of telecommunications networks thanks to its readability and versatility.&lt;/p&gt;
&lt;p&gt;Let&#x27;s dive into how to employ the two effectively and efficiently using the &lt;a href=&quot;https://zato.io&quot;&gt;Zato&lt;/a&gt; integration and automation platform.&lt;/p&gt;
&lt;h2 id=&quot;dashboard&quot;&gt;Dashboard&lt;/h2&gt;
&lt;p&gt;The first step is to define a new SFTP connection in your Dashboard, as in the screenshots below.&lt;/p&gt;
&lt;p&gt;The form lets you provide all the default options that apply to each SFTP connection - remote host, what protocol to use,
whether file metadata should be preserved during transfer, logging level and other details that you would typically provide.&lt;/p&gt;
&lt;p&gt;Simply fill it out with the same details that you would use if it were command line-based SFTP connections.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/sftp-3.1/sftp-dashboard.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/sftp-3.1/create.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;pinging&quot;&gt;Pinging&lt;/h2&gt;
&lt;p&gt;The next thing, right after the creation of a new connection, is to ping it to check if the server is responding.&lt;/p&gt;
&lt;p&gt;Pinging opens a new SFTP connection and runs the ping command - in the screenshot above it was &lt;strong&gt;ls .&lt;/strong&gt; -
a practically no-op command whose sole purpose is to let the connection confirm that commands in fact can be executed,
which proves the correctness of the configuration.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/sftp-3.1/ping1.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;This will either returns details of why a connection could not be established or the response time if it was successful.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/sftp-3.1/ping2.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;cloud-sftp-console&quot;&gt;Cloud SFTP console&lt;/h2&gt;
&lt;p&gt;Having validated the configuration by pinging it, we can now execute SFTP commands straight in Dashboard from a command console:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/sftp-3.1/shell-link.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Any SFTP command, or even a series of commands, can be sent and responses retrieved immediately. It is also possible to increase the logging level
for additional SFTP protocol-level details.&lt;/p&gt;
&lt;p&gt;This makes it possible to rapidly prototype file transfer functionality as a series of scripts that can be next moved as they are to Python-based services.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/sftp-3.1/shell-command.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;python-automation&quot;&gt;Python automation&lt;/h2&gt;
&lt;p&gt;Now, in Python, your API automation services have access to an extensive array of capabilities -
from executing transfer commands individually or in batches to the usage of SFTP scripts previously
created in your Dashboard.&lt;/p&gt;
&lt;p&gt;Here is how Python can be used in practice:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MySFTPService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Connection to use&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;My SFTP Connection&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get a handle to the connection object&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sftp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Execute an arbitrary script with one or more SFTP commands, like in web-admin&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;my_script&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;ls -la /remote/path&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;my_script&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Ping a remote server to check if it responds&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ping&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Download an entry, possibly recursively&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;download&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/remote/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/local/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Like .download but remote path must point to a file (exception otherwise)&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;download_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/remote/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/local/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Makes the contents of a remote file available on output&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/remote/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Uploads a local file or directory to remote path&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/local/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/remote/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Writes input data out to a remote file&lt;/span&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;My data&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/remote/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Create a new directory&lt;/span&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create_directory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/new/directory&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-40&quot; name=&quot;line-0-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-41&quot; name=&quot;line-0-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Create a new symlink&lt;/span&gt;
&lt;a id=&quot;line-0-42&quot; name=&quot;line-0-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create_symlink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/new/symlink&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-43&quot; name=&quot;line-0-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-44&quot; name=&quot;line-0-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Create a new hard-link&lt;/span&gt;
&lt;a id=&quot;line-0-45&quot; name=&quot;line-0-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create_hardlink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/new/hardlink&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-46&quot; name=&quot;line-0-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-47&quot; name=&quot;line-0-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Delete an entry, possibly recursively, no matter what kind it is&lt;/span&gt;
&lt;a id=&quot;line-0-48&quot; name=&quot;line-0-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/delete&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-49&quot; name=&quot;line-0-49&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-49&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;49 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-50&quot; name=&quot;line-0-50&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-50&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;50 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Like .delete but path must be a directory&lt;/span&gt;
&lt;a id=&quot;line-0-51&quot; name=&quot;line-0-51&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-51&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;51 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete_directory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/delete&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-52&quot; name=&quot;line-0-52&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-52&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;52 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-53&quot; name=&quot;line-0-53&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-53&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;53 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Like .delete but path must be a file&lt;/span&gt;
&lt;a id=&quot;line-0-54&quot; name=&quot;line-0-54&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-54&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;54 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/delete&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-55&quot; name=&quot;line-0-55&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-55&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;55 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-56&quot; name=&quot;line-0-56&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-56&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;56 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Like .delete but path must be a symlink&lt;/span&gt;
&lt;a id=&quot;line-0-57&quot; name=&quot;line-0-57&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-57&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;57 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete_symlink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/delete&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-58&quot; name=&quot;line-0-58&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-58&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;58 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-59&quot; name=&quot;line-0-59&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-59&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;59 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get information about an entry, e.g. modification time, owner, size and more&lt;/span&gt;
&lt;a id=&quot;line-0-60&quot; name=&quot;line-0-60&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-60&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;60 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;info&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/remote/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-61&quot; name=&quot;line-0-61&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-61&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;61 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-62&quot; name=&quot;line-0-62&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-62&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;62 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;last_modified&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-63&quot; name=&quot;line-0-63&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-63&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;63 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;owner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-64&quot; name=&quot;line-0-64&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-64&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;64 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-65&quot; name=&quot;line-0-65&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-65&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;65 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size_human&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-66&quot; name=&quot;line-0-66&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-66&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;66 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;permissions_oct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-67&quot; name=&quot;line-0-67&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-67&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;67 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-68&quot; name=&quot;line-0-68&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-68&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;68 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# A boolean flag indicating if path is a directory&lt;/span&gt;
&lt;a id=&quot;line-0-69&quot; name=&quot;line-0-69&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-69&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;69 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_directory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/remote/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-70&quot; name=&quot;line-0-70&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-70&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;70 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-71&quot; name=&quot;line-0-71&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-71&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;71 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# A boolean flag indicating if path is a file&lt;/span&gt;
&lt;a id=&quot;line-0-72&quot; name=&quot;line-0-72&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-72&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;72 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/remote/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-73&quot; name=&quot;line-0-73&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-73&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;73 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-74&quot; name=&quot;line-0-74&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-74&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;74 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# A boolean flag indicating if path is a symlink&lt;/span&gt;
&lt;a id=&quot;line-0-75&quot; name=&quot;line-0-75&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-75&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;75 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_symlink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/remote/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-76&quot; name=&quot;line-0-76&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-76&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;76 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-77&quot; name=&quot;line-0-77&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-77&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;77 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# List contents of a directory - items are in the same format that .get_info uses&lt;/span&gt;
&lt;a id=&quot;line-0-78&quot; name=&quot;line-0-78&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-78&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;78 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;items&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/remote/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-79&quot; name=&quot;line-0-79&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-79&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;79 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-80&quot; name=&quot;line-0-80&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-80&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;80 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Move (rename) remote files or directories&lt;/span&gt;
&lt;a id=&quot;line-0-81&quot; name=&quot;line-0-81&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-81&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;81 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;move&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/from/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/to/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-82&quot; name=&quot;line-0-82&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-82&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;82 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-83&quot; name=&quot;line-0-83&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-83&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;83 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# An alias to .move&lt;/span&gt;
&lt;a id=&quot;line-0-84&quot; name=&quot;line-0-84&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-84&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;84 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/from/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/to/path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-85&quot; name=&quot;line-0-85&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-85&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;85 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-86&quot; name=&quot;line-0-86&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-86&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;86 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Change mode of entry at path&lt;/span&gt;
&lt;a id=&quot;line-0-87&quot; name=&quot;line-0-87&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-87&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;87 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;chmod&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;600&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/entry&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-88&quot; name=&quot;line-0-88&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-88&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;88 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-89&quot; name=&quot;line-0-89&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-89&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;89 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Change owner of entry at path&lt;/span&gt;
&lt;a id=&quot;line-0-90&quot; name=&quot;line-0-90&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-90&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;90 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;chown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;myuser&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/entry&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-91&quot; name=&quot;line-0-91&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-91&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;91 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-92&quot; name=&quot;line-0-92&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-92&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;92 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Change group of entry at path&lt;/span&gt;
&lt;a id=&quot;line-0-93&quot; name=&quot;line-0-93&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-93&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;93 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;chgrp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;mygroup&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/path/to/entry&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;Given how important SFTP is in telecommunications, having a convenient and easy way to automate it using Python is an essential
ability in a network engineer&#x27;s skill-set.&lt;/p&gt;
&lt;p&gt;Thanks to the SFTP connections in Zato, you can prototype SFTP scripts in Dashboard and employ them in API services right after that.
To complement it, a full Python API is available for programmatic access to remote file servers.&lt;/p&gt;
&lt;p&gt;Combined, the features make
it possible to create scalable and reusable file transfer services in a quick and efficient manner using the most convenient
programming language, Python.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤  &lt;a href=&quot;https://zato.io/en/industry/telecom/index.html&quot;&gt;Click here&lt;/a&gt; to read more about using Python and Zato in telecommunications
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/network-packet-broker.html&quot;&gt;What is a Network Packet Broker? How to automate networks in Python?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 29 Jul 2024 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/sftp.html</guid></item><item><title>Integrating with WordPress and Elementor API webhooks</title><link>https://zato.io/en/blog/wordpress-webhooks.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/wordpress-webhooks.html&quot;&gt;Integrating with WordPress and Elementor API webhooks&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2023-04-21, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;Consider this scenario:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You have a WordPress instance, possibly installed in your own internal network&lt;/li&gt;
&lt;li&gt;With WordPress, you use Elementor, a popular website builder&lt;/li&gt;
&lt;li&gt;A user fills out a form that you prepared using Elementor, e.g. the user provides his or her email and username
  to create an account in your CRM&lt;/li&gt;
&lt;li&gt;Now, after WordPress processes this information accordingly, you also need to send it all
  to a remote backend system that only accepts JSON messages&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The concern here is that WordPress alone will not send it to the backend system.&lt;/p&gt;
&lt;p&gt;Hence, we are going to use an Elementor-based webhook that will invoke Zato which will be acting
as an integration layer. In Zato, we will use Python to transform the results of what was submitted in the form -
in order to deliver it to the backend API system using a REST call.&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-wordpress/flow.png&quot;/&gt;
&lt;/center&gt;

&lt;h2 id=&quot;creating-a-channel&quot;&gt;Creating a channel&lt;/h2&gt;
&lt;p&gt;A Zato channel is a way to describe the configuration of a particular API endpoint. In this case, to accept data from WordPress,
we are going to use REST channels:&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-wordpress/rest-menu.png&quot;/&gt;
&lt;/center&gt;

&lt;p&gt;In the screenshot below, note particularly the highlighted data format field. Typically, REST channels will use JSON, but here,
we need to use &quot;Form data&quot; because this is what we are getting from Elementor.&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-wordpress/rest-form.png&quot;/&gt;
&lt;/center&gt;

&lt;p&gt;Now, we can add the actual code to accept the data and to communicate with the remote, backend system.&lt;/p&gt;
&lt;h2 id=&quot;python-code&quot;&gt;Python code&lt;/h2&gt;
&lt;p&gt;Here is the Python code and what follows is an explanation of how it works:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Field configuration&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;field_email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;fields[email][value]&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;field_username&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;fields[username][value]&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CreateAccount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# The input that we expect from WordPress, i.e. what fields it needs to send&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field_email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field_username&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# This is a dictionary object with data from WordPress ..&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. so we can use dictionary access to extract values received ..&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;email&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field_email&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field_username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. now, we can create a JSON request for the backend system ..&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. again, using a regular Python dictionary ..&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;api_request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;s1&quot;&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;s1&quot;&gt;&amp;#39;Username&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Obtain a connection to the backend system ..&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;CRM&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. invoke that system ..&lt;/span&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Invoke the resource providing all the information on input&lt;/span&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;api_request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. and log the response received ..&lt;/span&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Backend response -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The format of data that Elementor will use is of a specific nature. It is not JSON and the field names are not sent directly
either.&lt;/p&gt;
&lt;p&gt;That is, if your form has fields such as &quot;email&quot; and &quot;username&quot;, what the webhook sends is named differently. The names
will be, respectively:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;fields[email][value]&lt;/li&gt;
&lt;li&gt;fields[username][value]&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If it were JSON, we could say that instead of this ..&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;email&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;hello@example.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;username&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;.. the webhook was sending to you that:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;fields[email][value]&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;hello@example.com&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;fields[username][value]&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The above format explains why in the Python code below we are extracting all the input fields from WordPress
using the &quot;self.request.input&quot; object using its dictionary access syntax method.&lt;/p&gt;
&lt;p&gt;Normally, if the field was plain &quot;username&quot;,
we would be doing &quot;self.request.input.username&quot; but this is not available in this case because of the naming
conventions of the fields from Elementor.&lt;/p&gt;
&lt;p&gt;Now, the only remaining part is the definition of the outgoing REST connection that service
should use.&lt;/p&gt;
&lt;h2 id=&quot;outgoing-rest-connections&quot;&gt;Outgoing REST connections&lt;/h2&gt;
&lt;p&gt;Create an outgoing REST connection as below - this time around, note that the data format is JSON.&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-wordpress/out-menu.png&quot;/&gt;
&lt;/center&gt;

&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-wordpress/out-form.png&quot;/&gt;
&lt;/center&gt;

&lt;h2 id=&quot;using-the-rest-channel&quot;&gt;Using the REST channel&lt;/h2&gt;
&lt;p&gt;In your WordPress dashboard, create a webhook using Elementor and point it to the channel created earlier,
e.g. make Elementor invoke an address such as http://10.157.11.39:11223/api/wordpress/create-account&lt;/p&gt;
&lt;p&gt;Each time a form is submitted, its contents will go to Zato, your service will transform it to JSON
and the backend CRM system will be invoked.&lt;/p&gt;
&lt;p&gt;And this is everything - you have just integrated WordPress, Elementor webhooks and an external API backend system
in Python.&lt;/p&gt;
&lt;h2 id=&quot;more-resources&quot;&gt;More resources&lt;/h2&gt;
&lt;p&gt;➤ Python &lt;a href=&quot;https://zato.io/en/tutorials/index.html&quot;&gt;API integration tutorials&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/integration-platform.html&quot;&gt;What is an integration platform?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/python-ipaas.html&quot;&gt;Python Integration platform as a Service (iPaaS)&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/en/docs/4.1/intro/esb-soa.html&quot;&gt;What is an Enterprise Service Bus (ESB)? What is SOA?&lt;/a&gt;
&lt;br/&gt;
➤ &lt;a href=&quot;https://zato.io/articles/open-source-ipaas.html&quot;&gt;Open-source iPaaS&lt;/a&gt; in Python&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Fri, 21 Apr 2023 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/wordpress-webhooks.html</guid></item><item><title>How to invoke REST APIs from Zato services</title><link>https://zato.io/en/blog/invoke-rest-api.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/invoke-rest-api.html&quot;&gt;How to invoke REST APIs from Zato services&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2022-08-23, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;This Zato article is a companion to
&lt;a href=&quot;https://zato.io/en/blog/rest-api-channels.html&quot;&gt;an earlier post&lt;/a&gt;
- previously, we covered accepting REST API calls and now we will look at how Zato services can invoke external REST endpoints.&lt;/p&gt;
&lt;h2 id=&quot;outgoing-connections&quot;&gt;Outgoing connections&lt;/h2&gt;
&lt;p&gt;Similar to how channels are responsible for granting access to your services via REST or other communication means,
it is outgoing connections (outconns, as an abbreviation) that let the services access resources external to Zato, including REST APIs.&lt;/p&gt;
&lt;p&gt;Here is a sample definition of a REST outgoing connection:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-invoke-rest-api/outconn-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-invoke-rest-api/outconn-create.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;The Python implementation will follow soon but, for now, let&#x27;s observe that keeping the two separate has a couple of prominent advantages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The same outgoing connection can be used by multiple services&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The configuration is maintained in one place only - any change is immediately reflected on all servers and services can make use of the new configuration without any interruptions&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Most of the options of REST outconns have the same meaning as with channels but &lt;strong&gt;TLS CA certs&lt;/strong&gt; may require particular attention. This option dictates what happens if a REST endpoint
is invoked using HTTPS rather than HTTP, how the remote end&#x27;s TLS certificate is checked.&lt;/p&gt;
&lt;p&gt;The option can be one of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Default bundle - a built-in bundle of CA certificates will be used for validation. This is the same bundle that Mozilla uses and is a good choice if the API you are invoking is a well-known, public one with endpoints signed by one of the public certificate authorities.&lt;/li&gt;
&lt;li&gt;If you upload your own CA certificates, they can be used for validation of external REST APIs - for instance,
  your company or a business partner may have their own internal CAs&lt;/li&gt;
&lt;li&gt;Skip validation - no validation will be performed at all, any TLS certificate will be accepted, including self-signed ones. Usually, this option should not be used for non-development purposes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;python-code&quot;&gt;Python code&lt;/h2&gt;
&lt;p&gt;A sample service making use of the outgoing connection is below.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GetUserDetails&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot; Returns details of a user by the person&amp;#39;s name.&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;api.user.get-details&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# In practice, this would be an input parameter&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;user_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;john.doe&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Name of the connection to use&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;My REST Endpoint&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get a connection object&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# A single dictionary with all the parameters,&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Zato will know where each one goes to.&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;s1&quot;&gt;&amp;#39;app_id&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Zato&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;s1&quot;&gt;&amp;#39;app_version&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;4.1&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# We are responsible for catching exceptions&lt;/span&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Invoke the endpoint&lt;/span&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Log the response&lt;/span&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Response `&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;`&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# We caught an exception - log its details&lt;/span&gt;
&lt;a id=&quot;line-0-40&quot; name=&quot;line-0-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-41&quot; name=&quot;line-0-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Endpoint could not be invoked due to `&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;`&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;First, we obtain a connection handle, then the endpoint is invoked and a response is processed, which in this case
means merely outputting its contents to server logs.&lt;/p&gt;
&lt;p&gt;In the example, we use a constant user name and query string but in practice, they would be likely produced basing on user input.&lt;/p&gt;
&lt;p&gt;Note the &#x27;params&#x27; dictionary - when you invoke this service, Zato will know that &#x27;name&#x27; should go to the URL path
but all the remaining parameters will go to the request&#x27;s query string. Again, this gives you additional flexibility,
e.g. if the endpoint&#x27;s URL changes from path parameters to query string, the service will continue to work without any changes.&lt;/p&gt;
&lt;p&gt;Observe, too, that we are responsible for catching and handling potential exceptions arising from invoking REST endpoints.&lt;/p&gt;
&lt;p&gt;Finally - because the outgoing connection&#x27;s data format is JSON, you are not required to de-/serialize it yourself,
the contents of &#x27;response.data&#x27; is already a Python dict read from a JSON response.&lt;/p&gt;
&lt;p&gt;At this point, the service is ready to be invoked - let&#x27;s say, through REST, AMQP or from the scheduler -
and when you do it, here is the output that will be seen in server logs:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;INFO - Response `{&amp;#39;user_id&amp;#39;: 123, &amp;#39;username&amp;#39;: &amp;#39;john.doe&amp;#39;, &amp;#39;display_name&amp;#39;: &amp;#39;John Doe&amp;#39;}`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, you can extend it to invoke other systems, get data from an SQL database or integrate with other APIs.&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Tue, 23 Aug 2022 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/invoke-rest-api.html</guid></item><item><title>How to integrate with Confluence APIs</title><link>https://zato.io/en/blog/confluence-python-api.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/confluence-python-api.html&quot;&gt;How to integrate with Confluence APIs&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2022-06-21, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;In
&lt;a href=&quot;https://zato.io/en/blog/jira-python-api.html&quot;&gt;a previous article&lt;/a&gt;,
I talked about Jira, and if you are a Jira user, chances are that you also use Confluence as they often go hand in hand,
Jira as a ticketing application and Confluence as an enterprise knowledge management system.&lt;/p&gt;
&lt;p&gt;From the perspective of integrations, connecting to Confluence and invoking its APIs looks and feels practically
the same as with Jira:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You need an API token&lt;/li&gt;
&lt;li&gt;You fill out a form in Zato Dashboard&lt;/li&gt;
&lt;li&gt;You create a Python service that offers methods such as get_page_by_title, attach_file, update_page_property and similar.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let&#x27;s go through it all step-by-step, starting off with the creation of an API token.&lt;/p&gt;
&lt;h2 id=&quot;creating-an-atlassian-api-token&quot;&gt;Creating an Atlassian API token&lt;/h2&gt;
&lt;p&gt;To invoke Confluence, you use an API token that can be shared with other Atlassian products, such as Jira. If you do not have
one already, here is how to create it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Log in to Confluence or Jira&lt;/li&gt;
&lt;li&gt;Visit the address where API tokens can be managed: https://id.atlassian.com/manage-profile/security/api-tokens&lt;/li&gt;
&lt;li&gt;Click &quot;Create API Token&quot; and provide a name for the token, such as &quot;Zato Integrations&quot;&lt;/li&gt;
&lt;li&gt;Copy the token somewhere as, once it has been created, you will not be able to retrieve it later on. The only way to change
  a token is to revoke it and create a new one.&lt;/li&gt;
&lt;/ul&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-confluence/confluence-new-token.png&quot;/&gt;
&lt;/center&gt;

&lt;h2 id=&quot;creating-a-confluence-connection&quot;&gt;Creating a Confluence connection&lt;/h2&gt;
&lt;p&gt;In your Zato Dashboard, go to Cloud -&amp;gt; Atlassian -&amp;gt; Confluence:&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-confluence/menu-confluence.png&quot;/&gt;
&lt;/center&gt;

&lt;p&gt;Click &quot;Create a new connection&quot; and fill out the form below. The username is the same as the email
address that you log in to Confluence or Jira with.&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-confluence/create-form.png&quot;/&gt;
&lt;/center&gt;

&lt;p&gt;Now, click &quot;Change API Token&quot; and enter the token created in the previous section:&lt;/p&gt;
&lt;center&gt;
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-confluence/change-token.png&quot;/&gt;
&lt;/center&gt;

&lt;h2 id=&quot;invoking-confluence&quot;&gt;Invoking Confluence&lt;/h2&gt;
&lt;p&gt;Authoring a Zato service that invokes Confluence follows a pattern that will feel familiar no matter what kind
of an API you integrate with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Obtain a connection to remote resource&lt;/li&gt;
&lt;li&gt;Invoke it&lt;/li&gt;
&lt;li&gt;Process the response the resource returned&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the case of the code below, we are merely logging the response from Confluence. In a bigger integration,
we would process it accordingly, e.g. parts of the output could be synchronized with Jira or another system.&lt;/p&gt;
&lt;p&gt;Note the &#x27;client.get_all_pages_from_space&#x27; method below - the client will offer other methods as well, e.g. get_space,
get_page_as_pdf or ways to run CQL (Confluence Query Language) directly. Use auto-completion in your IDE to discover all the
methods available.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.common.typing_&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cast_&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.connection.confluence_&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ConfluenceClient&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GetAllPages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Name of the Confluence space that our pages are in&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;space&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;ABC&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Name of the connection definition to use&lt;/span&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;My Confluence Connection&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. create a reference to our connection definition ..&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;confluence&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cloud&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;confluence&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. obtain a client to Confluence ..&lt;/span&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;confluence&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# type: ConfluenceClient&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Cast to enable code completion&lt;/span&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cast_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;ConfluenceClient&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Get all pages from our space&lt;/span&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;pages&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_all_pages_from_space&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;space&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Pages received -&amp;gt; &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ###########################################################################&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That is all - you have create an Atlassian API token, a Zato Confluence connection and you have integrated with Confluence
in Python!&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Tue, 21 Jun 2022 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/confluence-python-api.html</guid></item><item><title>Enterprise API integrations under Windows</title><link>https://zato.io/en/blog/windows-api-integrations.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/windows-api-integrations.html&quot;&gt;Enterprise API integrations under Windows&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2021-09-15, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;If you are on Windows, looking for an integration platform to connect your APIs, systems, applications, backend resources or mobile apps, I am happy to let you know that Zato
now supports Windows natively in addition to Linux.&lt;/p&gt;
&lt;p&gt;You can use the platform to connect your systems, to offer new APIs on top of existing server-side resources, to secure your applications, to connect IoT devices,
to move and distribute static files or to grant backend access to online users - these are just a few examples of how Zato is typically used. Read on for more details
on how to install it under Windows.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-windows/dashboard.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;installing-zato&quot;&gt;Installing Zato&lt;/h2&gt;
&lt;p&gt;The native Windows port is new in
&lt;a href=&quot;https://zato.io/en/docs/4.1&quot;&gt;Zato 4.1&lt;/a&gt; - download an .msi package for your Python version and install it by following the
&lt;a href=&quot;https://zato.io/en/docs/4.1/admin/guide/install/windows.html&quot;&gt;steps here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The end result will be a &#x27;zato&#x27; command line tool, as below:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-windows/zato-version.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-first-integration-cluster&quot;&gt;The first integration cluster&lt;/h2&gt;
&lt;p&gt;Run the command below to create your first cluster. It is called &quot;qs-1&quot; because this is the first quickstart cluster in this system:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.2-windows/zato-quickstart.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Note the indicated user name (admin) and the password - after the cluster is started, you will be able to use the credentials to log in to your Dashboard in a moment.&lt;/p&gt;
&lt;p&gt;Let&#x27;s start the cluster in this case - it will open a new PowerShell or cmd.exe window with all the logs in foreground.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;nb&quot;&gt;PS &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:\&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:\&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Administrator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;qs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;zato-qs-start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bat&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, you can log in to Dashboard at &lt;a href=&quot;http://localhost:8183&quot;&gt;http://localhost:8183&lt;/a&gt; to look around and familiarize yourself with the GUI.&lt;/p&gt;
&lt;p&gt;That is practically everything, the cluster is up and running, there is a server, Dashboard and a background scheduler. You are ready to begin
&lt;a href=&quot;https://zato.io/en/tutorials/main/01.html&quot;&gt;the tutorial&lt;/a&gt;
now.&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Wed, 15 Sep 2021 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/windows-api-integrations.html</guid></item><item><title>Diving deep into REST API channels</title><link>https://zato.io/en/blog/rest-api-channels.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/rest-api-channels.html&quot;&gt;Diving deep into REST API channels&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2021-01-04, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;We begin in 2021 with a deep dive into Zato REST API channels. What are they? How to use them efficiently? How can they configured for maximum flexibility? Read on to learn all the details.&lt;/p&gt;
&lt;h2 id=&quot;a-sample-service&quot;&gt;A sample service&lt;/h2&gt;
&lt;p&gt;First, let&#x27;s have a look at a sample service that we want to make available to API clients.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GetUserDetails&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot; Returns details of a selected user.&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;api.user.get-details&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SimpleIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;input_required&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;user_name&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;output_required&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;email&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;user_type&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Log what we are about to do.&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Returning details of `&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;`&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# In real code, we would look up the details in a database,&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# but not necessarily in a cache - read the article why it is not needed.&lt;/span&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;details&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;s1&quot;&gt;&amp;#39;email&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;my.user@example.com&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;s1&quot;&gt;&amp;#39;user_type&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;ABC&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Return the response now.&lt;/span&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;details&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The first thing that may strike you is that the code is on a very high level - it just has access to a user_name and some data is returned but there is no mention of REST, no data serialization, caching or anything that is not the business functionality of returning user details.&lt;/p&gt;
&lt;p&gt;This is by design. In Zato, services focus on what they actually need to do and the lower-level details are left to the platform. In other words, the service does not need to be concerned with peculiarities of a given transport method, it just has its input to process and output to produce. It is channels in front of a service that deal with all such aspects and the service concentrates on higher level logic.&lt;/p&gt;
&lt;p&gt;This makes it possible to employ the same service in other contexts - for instance, we are describing REST channels today but the very same service could be invoked from the scheduler, through AMQP, IBM MQ or via other channels, including multiple REST ones, helping you in this way design a reusable Service-Oriented Architecture (SOA).&lt;/p&gt;
&lt;p&gt;With that in mind, we can advance to REST channels now.&lt;/p&gt;
&lt;h2 id=&quot;rest-api-channels&quot;&gt;REST API channels&lt;/h2&gt;
&lt;p&gt;In Zato web-admin, a definition of a sample REST channel making use of our service may look like below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/rest-api-channels/rest-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/rest-api-channels/rest-create.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Now that we have created a new channel, we can invoke it to confirm that it works as expected.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;%&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;localhost:17010/api/v1/user/my.username&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;email&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;my.user@example.com&amp;quot;&lt;/span&gt;,&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;user_type&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;ABC&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;%
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In server logs:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;INFO - api.user.get-details - Returning details of `my.username`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Everything is fine and we can proceed.&lt;/p&gt;
&lt;p&gt;Just one note about channels, remember that there can be many channels pointing to the same service - this lets you reuse the services in various scenarios, e.g. you can have a separate REST channel with its own security definition for each external application connecting to your APIs.&lt;/p&gt;
&lt;p&gt;Whenever you add, modify or delete a channel, the service as such is unchanged, nor are any other channels. Conversely, when you update a service, for instance adding new functionality, all channels using it will automatically invoke the new version of the service.&lt;/p&gt;
&lt;p&gt;Channels come with good defaults when you create them but it is always possible to customize them to one&#x27;s particular needs. Let&#x27;s go step by step through each attribute of a channel&#x27;s definition.&lt;/p&gt;
&lt;h2 id=&quot;basic-information&quot;&gt;Basic information&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt; - Each channel has a unique name which can be arbitrary, depending on your naming conventions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Active&lt;/strong&gt; - An inactive channel cannot be invoked; doing so will yield a 404 error.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;url-path-query-string&quot;&gt;URL path &amp;amp; query string&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;URL path&lt;/strong&gt; - URL paths need to be unique. Each can contain one or more patterns to match input parameters - this is why in our service we were able to reference self.request.input.user_name - it was extracted from the URL path.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Match slash&lt;/strong&gt; - Sometimes, URL path parameters sent from API clients will contain the slash character which normally is used to separate path components. This checkbox controls whether path patterns should match a slash or not.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;URL params&lt;/strong&gt; - QS over path vs. Path over QS. Usually, applications will send parameters in one place only, e.g. only in the URL path or in query string parameters. But what if an application has good reasons to send parameters in both the query string and URL path, for instance /api/v1/user/my.username?user_name=my.other.username - this happens from time to time and this setting lets one control which of the two will take precedence.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Merge to request&lt;/strong&gt; - Used if parameters are sent via query string in addition to the URL path. If checked, such query string parameters will be accessible through self.request.input, otherwise, they will exist only in self.request.http.GET.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Params priority&lt;/strong&gt; - This is similar to the options above but it will control the behavior if parameters are sent in both JSON message body as well as in URL path or query string - it lets one decide which will have higher priority and which will become available in self.request.input.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;http-metadata-data-format&quot;&gt;HTTP metadata &amp;amp; data format&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Method&lt;/strong&gt; - it is possible to specify that only specific HTTP method can be used to invoke the channel. This is not always needed. For instance, the service above can work just fine with either GET or POST, depending on what the caller prefers. Conceptually, this is a GET request but some API clients will always use POST so this is why filling out this field is not always needed or advised.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A service can handle multiple methods either as a whole and a channel can dispatch requests to specific parts of the service depending on which method is used, i.e. you can add handle_GET, handle_POST and other such methods independently, resulting, for instance, in a User service that handles CRUD via respective handle_* methods.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Encoding&lt;/strong&gt; - Can be set to &quot;gzip&quot; to enable compression of responses from the channel.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Data format&lt;/strong&gt; - Can be one of JSON, XML or HL7 to enable auto-de/serialization of requests and responses. Note that the original request, prior to any processing, is always available in self.request.raw_request.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Accept header&lt;/strong&gt; - To what Accept HTTP headers the channel should react. Note that, just like with methods, it is possible for the service to &lt;a href=&quot;https://zato.io/en/blog/http-accept-method-headers.html&quot;&gt;handle each header separately&lt;/a&gt;, which lets one have the same service produce different responses depending on what the client&#x27;s Accept header dictates.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;api-services-security&quot;&gt;API services &amp;amp; security&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Service&lt;/strong&gt; - The service that is mounted on this channel and which will be given incoming requests on input, as in the code example above. The same service may be mounted on multiple channels.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Security definition&lt;/strong&gt; - What kind of an authentication mechanism this channel requires. Can be one of Basic Auth, API key, JWT, Vault, WS-Security or XPath. Each channel may have a different security definition assigned and the same definition can be assigned to multiple channels. Note that, to avoid any misunderstandings, you need to explicitly choose &quot;No security definition&quot; if the channel should not handle authentication itself, perhaps because the service should do it on its own, i.e. it is not possible to forget to choose something here and leave a channel unsecured by mistake.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;RBAC&lt;/strong&gt; - A channel can also use Role-Based Access Control definitions where each API client is assigned fine-grained permissions to individual methods and roles, possibly hierarchical one, which control if a particular client can invoke the channel&#x27;s service. For instance, some API clients may be allowed to only read (GET) data whereas different ones will be able to create, update and delete it too (POST, PATCH and DELETE).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;api-caching&quot;&gt;API caching&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Cache type&lt;/strong&gt; - Optionally, can be set to either built-in or Memcached. Requests matching previous ones will be automatically served from a specific cache assigned to the channel. With the built-in cache, the response is served from RAM directly, resulting in very fast responses. It is possible to browse, modify or delete the cached data, as below:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/rest-api-channels/cache-list.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/rest-api-channels/cache-entry.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;api-rate-limiting&quot;&gt;API rate limiting&lt;/h2&gt;
&lt;p&gt;The rate limiting stanza was not expanded previously so let&#x27;s do it now to add &lt;a href=&quot;https://zato.io/en/blog/api-rate-limiting-intro.html&quot;&gt;a rate limiting definition&lt;/a&gt; to our channel. As usual, the limits can be set separately for each channel.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/rest-api-channels/rate-limit.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;In this particular case, clients connecting from the internal network will be allowed to issue 30 request per minute but connections from localhost can invoke it 50k times an hour. And everyone else is limited to 100 requests a day.&lt;/p&gt;
&lt;h2 id=&quot;message-log&quot;&gt;Message log&lt;/h2&gt;
&lt;p&gt;Just like with rate limiting, these options were not expanded in the initial screenshot so here they are. Each channel can keep N last messages received, sent or both. It is also possible to say that only the first X kilobytes of a given message are to be stored - some messages may be too large for it to be practical to keep them in their entirety. When the log becomes full, the oldest messages are discarded, making room for newer ones.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/rest-api-channels/message-log.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Stored messages can be browsed in web-admin, immediately letting one know what a given channel receives and sends.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/rest-api-channels/message-log-entry-list.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Such a message log is a feature common to other elements of Zato, e.g. HL7 or WebSocket connections have their own message logs too.&lt;/p&gt;
&lt;h2 id=&quot;documentation-and-openapi&quot;&gt;Documentation and OpenAPI&lt;/h2&gt;
&lt;p&gt;It is good that we have a REST channel but how do we let others know about it? On the one hand, you can simply notify your partners and clients through documentation, wiki pages or other non-automated means.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/rest-api-channels/apidocs-index.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/rest-api-channels/apidocs-service.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;And by the way, if you need a WSDL for SOAP clients, the generated documentation includes it too.&lt;/p&gt;
&lt;h2 id=&quot;invoking-rest-apis&quot;&gt;Invoking REST APIs&lt;/h2&gt;
&lt;p&gt;This is everything about REST channels today but one question may be still open. If channels are means for handling incoming connections then how does one make requests to REST API endpoints external to Zato? How to invoke other other people&#x27;s microservices?&lt;/p&gt;
&lt;p&gt;The answer is that this is what Zato outgoing connections are for
and we will cover
REST outgoing connections
in a future post in a way similar to how we went through REST channels in this one.&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 04 Jan 2021 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/rest-api-channels.html</guid></item><item><title>Understanding the fan-out / fan-in API integration pattern</title><link>https://zato.io/en/blog/patterns-fan-out-fan-in.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/patterns-fan-out-fan-in.html&quot;&gt;Understanding the fan-out / fan-in API integration pattern&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2020-12-21, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;h2 id=&quot;what-is-fan-out-fan-in&quot;&gt;What is fan-out / fan-in?&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/pattern-fan-out-fan-in/arch.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;The core idea is this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A source system requests some kind of information from your Zato service&lt;/li&gt;
&lt;li&gt;The source system understands that the process of gathering this information may take time. This may be because the backend systems are slow to reply or there are many of them and the person using the source system will not actively wait for the reply, e.g. no one will want to wait 30 or 60 seconds in such a case.&lt;/li&gt;
&lt;li&gt;Zato accepts the initial request and returns to the initial system a &lt;strong&gt;correlation ID (CID)&lt;/strong&gt;, a random string that tells the system &quot;I received your request, here, save this CID somewhere, and when I have the result, I will give it to you along with that CID to make it possible for you to understand a reply to which request it is&quot;&lt;/li&gt;
&lt;li&gt;At this point the initial system knows that the response will arrive at some point in the future and it stores the CID in a datastore of choice, it can be in Redis, MongoDB, an SQL database or simply in RAM, this is completely up to the system&lt;/li&gt;
&lt;li&gt;The system does not block the connection it made to Zato anymore now - this is important - it does not wait for the response to be sent as part of the same TCP exchange of messages&lt;/li&gt;
&lt;li&gt;What exactly the system does instead of blocking depends on the protocol used to connect with Zato. If it is HTTP, it can possibly close the connection in the knowledge that Zato will invoke one of its callback endpoints once the results are ready. If it is AMQP, IBM or Zero MQ, then the system already listens for data in some reply queues.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The above concludes the initial phase and Zato can now carry out the rest of the work:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Your Zato service uses &lt;strong&gt;self.patterns.fanout&lt;/strong&gt; to invoke as many data sources as required to collect the information originally request&lt;/li&gt;
&lt;li&gt;A data source may mean a database of any sort, an external application or perhaps another service that in turn may invoke other applications, systems, services or fan-out / fan-in patterns as well&lt;/li&gt;
&lt;li&gt;The service initially using self.patterns.fanout tells the pattern what callback service to invoke once all the data sources returned their responses. The pattern is also given the CID so that the callback service knows what it was too.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, the data-collecting services and data sources do their job. What it means is purely up to a given integration process, perhaps some SQL databases are consulted, maybe Cassandra queries run and maybe a list of REST endpoints is invoked, any protocol or data format can be used.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What Zato does in the meantime is keeping track of which of the data sources already replied and when they all have, Zato will invoke the callback service&lt;/li&gt;
&lt;li&gt;The callback service is given on input all the responses along with the original CID&lt;/li&gt;
&lt;li&gt;What the callback service will process the responses, e.g. by transforming them into a common format combining them into a single message&lt;/li&gt;
&lt;li&gt;Finally, the callback service invokes the callback endpoint that the initial system awaits on - for instance, it may publish the response to an AMQP queue or it may invoke a REST endpoint. Note that the technology used here can be independent of the one used initially - as an example, we can very well have the very first system use WebSockets for requests and IBM MQ for responses.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thus, we can see why it is called fan-out / fan-in:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First, the flow of information &lt;strong&gt;fans out&lt;/strong&gt; to applications and systems containing the data needed&lt;/li&gt;
&lt;li&gt;Next, the flow &lt;strong&gt;fans in&lt;/strong&gt; through Zato to the application that requested the data&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;when-to-use-it&quot;&gt;When to use it?&lt;/h2&gt;
&lt;p&gt;The pattern can be considered each time there is a rather long-running integration process that requires communication with more than one system.&lt;/p&gt;
&lt;p&gt;This raises a question of what is long-running? The answer lies in whether there is a human being waiting for the results or not. Generally, people can wait 1-2 seconds for a response before growing impatient. Hence, if the process takes 30 seconds or more, they should not be made to wait as this can only lead to dissatisfaction.&lt;/p&gt;
&lt;p&gt;Yet, even if there is no real person for the result, it is usually not a good idea to wait for results too long as that is a blocking process and blocking may mean consuming up resources unnecessarily, which in turn may lead to wasted CPU and, ultimately, energy.&lt;/p&gt;
&lt;p&gt;This kind of processes is found when the data sources are &lt;em&gt;uneven&lt;/em&gt; in the sense that some or all of them may use different technologies or because they may each return responses with different delays. For instance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Some data sources may include reporting databases that generate reports on demand - such an act may require many seconds or minutes to complete&lt;/li&gt;
&lt;li&gt;Some data sources may belong to different organizational units, e.g. an association of independent business organizations may request data from some of them and each may use its own system, database or endpoint, each with different a response time&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Another trait of such processes is that the parallel paths are independent - if they are separate and each potentially takes a significant amount of time then we can just as well run them in parallel rather than serially, saving in this way time from the caller&#x27;s perspective.&lt;/p&gt;
&lt;h2 id=&quot;how-does-it-look-like-in-python&quot;&gt;How does it look like in Python?&lt;/h2&gt;
&lt;p&gt;An example service using the pattern may look like below.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The service receives a user_id on input and is to return a credit scoring based on that&lt;/li&gt;
&lt;li&gt;Three services, each representing a single backend system, are invoked in parallel&lt;/li&gt;
&lt;li&gt;Once all the responses are available, a callback service is invoked - this is the service that needs to deliver the combined response to the original caller&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that this particular code happens to use AMQP in the callback service but this is just for illustration purposes and any other technology can be used just as well.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GetUserCreditScoring&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# A dictionary of services to invoke along with requests they receive&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;targets&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;s1&quot;&gt;&amp;#39;crm.get-user&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;s1&quot;&gt;&amp;#39;erp.get-user-information&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;USER_ID&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;s1&quot;&gt;&amp;#39;scoring.get-score&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;uid&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Invoke all the services and get the CID&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;patterns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fanout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;invoke&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;callbacks&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Let the caller know what the CID is&lt;/span&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;cid&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;GetUserCreditScoringAsyncCallbac&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# AMQP connection to use&lt;/span&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;out_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;AsyncResponses&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# AMQP exchange and routing key to use&lt;/span&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/exchange&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;route_key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;zato.responses&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# The actual data to send - we assume that we send it&lt;/span&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# just as we received it, without any transformations.&lt;/span&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raw_request&lt;/span&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outgoing&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amqp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;out_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;route_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;more-options&quot;&gt;More options&lt;/h2&gt;
&lt;p&gt;Be sure to check &lt;a href=&quot;https://zato.io/en/docs/4.1/dev/index.html&quot;&gt;details of the pattern&lt;/a&gt; in the documentation to understand what other options and metadata are available for your services.&lt;/p&gt;
&lt;p&gt;In particular, note that there is another type callback not shown in this article. The code above has only one, final callback when all of the data is already available. But what if you need to report progress each of the sub-tasks completed? This is when per-invocation callbacks come in handy, check the samples in the documentation for more information.&lt;/p&gt;
&lt;h2 id=&quot;more-patterns&quot;&gt;More patterns&lt;/h2&gt;
&lt;p&gt;Fan-out / fan-in is just one of the patterns that Zato ships with. The most prominent ones are listed below:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/en/docs/4.1/dev/index.html&quot;&gt;Parallel execution&lt;/a&gt; - Similar to fan-out / fan-in in that it can be used for communication with multiple systems in parallel, the key difference being that this pattern is used when a final callback is needed, e.g. when there is a need to update many independent systems but there is no need for a combined response&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/en/docs/4.1/dev/index.html&quot;&gt;Invoke/retry&lt;/a&gt; - used when there is a need to invoke a resource and handle potential failures in a transparent way, e.g. a system may be down temporarily and with this pattern it is possible to repeat the invocation at a later time, according to a specific schedule&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 21 Dec 2020 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/patterns-fan-out-fan-in.html</guid></item><item><title>Configuring REST channels for CORS</title><link>https://zato.io/en/blog/rest-channels-cors.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/rest-channels-cors.html&quot;&gt;Configuring REST channels for CORS&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2020-12-14, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/rest-channels-cors/form.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;terminology&quot;&gt;Terminology&lt;/h2&gt;
&lt;p&gt;CORS, as an acronym, has several parts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;C&lt;/strong&gt;ross-&lt;strong&gt;O&lt;/strong&gt;rigin&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;R&lt;/strong&gt;esource&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;S&lt;/strong&gt;haring&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the context of REST APIs, which predominantly means JSON or XML served usually with POST or other calls, this can be simplified to the below.&lt;/p&gt;
&lt;p&gt;Origin means a combination of a URL scheme, hostname and port number. For instance, https://example.com is one origin whereas https://example.com:8443 is a different one (ports differ). Similarly,
https://www.example.net is different than https://api.example.net (subdomains differ). Also, http:// vs. https:// is a different URL scheme and that means a different origin too even if domains and ports were the same.&lt;/p&gt;
&lt;p&gt;Resource, here, is a REST API endpoint that is accessible via HTTP to JavaScript calls such as XMLHttpRequest (XHR). Note that XHR is not the only mechanism used but, because it is the most popular one in practice today, this article will concern with XHR only.&lt;/p&gt;
&lt;p&gt;Sharing is the act of making resources available to XHR calls.&lt;/p&gt;
&lt;p&gt;Finally, we deal with cross-origin sharing which means that JavaScript code and the REST endpoint will be served from different origins. E.g. https://www.example.com for the frontend where XHR calls come from whereas https://api.example.com is used for the REST endpoints.&lt;/p&gt;
&lt;p&gt;Putting it together, in the most commonly found case, we have a frontend web page served from one domain and a REST API served from another domain and we want for the frontend to make XHR calls to the REST endpoints. CORS is the technique employed to make it happen. Without CORS, we would encounter a restriction called Same-Origin Policy (SOP) which would prevent the calls from succeeding.&lt;/p&gt;
&lt;p&gt;However, note that the restriction does not apply to, for instance, resources loaded via &lt;code&gt;&amp;lt;script src=&quot;...&quot;&amp;gt;&lt;/code&gt; elements. This is why libraries like JQuery can be hot-linked to using CDNs or other locations but regular calls to one&#x27;s REST APIs may require CORS configuration. Likewise, browser extensions may be exempt from SOP.&lt;/p&gt;
&lt;p&gt;In short, in CORS, we deal with XHR and similar mechanisms specifically and other features that browsers have to offer may require it or not - do not be surprised if SOP and CORS are used in one place but not in another, outside of the realm of REST APIs invoked from pages served by web servers which is what this article covers.&lt;/p&gt;
&lt;p&gt;Also, note that it is the web browser that CORS and SOP are enforced by - it means that if an endpoint is accessed via another HTTP client, such as curl, the restrictions will not apply.&lt;/p&gt;
&lt;h2 id=&quot;two-types-of-cors-calls-in-rest-apis&quot;&gt;Two types of CORS calls in REST APIs&lt;/h2&gt;
&lt;p&gt;A browser will issue two types of XHR calls:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple ones, usually not used in REST APIs built around JSON or XML&lt;/li&gt;
&lt;li&gt;Complex ones, called pre-flighted ones, most often used with JSON or XML&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With simple calls, an XHR call is made and certain specific headers will need to exist for the XHR caller to be able to read the response from the API server.&lt;/p&gt;
&lt;p&gt;With complex ones, the browser first sends a short OPTIONS request (pre-flight), asking the server if the actual request can be sent. If the response is satisfactory, the browser will send a second request, this time with the real data that the XHR user meant to send.&lt;/p&gt;
&lt;p&gt;Note that CORS is handled by browsers automatically. For instance, when an XHR POST call is issued, it is the browser that sends OPTIONS under the hood and the frontend developer does not control whether it happens or not.&lt;/p&gt;
&lt;p&gt;Thus, the server&#x27;s job is to return headers expected in a given type of a CORS-using invocation. The headers tell the browser whether it can proceed and if so, the browser continues in the process, ultimately returning the response from an API call to JavaScript code.&lt;/p&gt;
&lt;p&gt;Keep in mind that, from the browser&#x27;s perspective, CORS is not about preventing an XHR caller from invoking specific APIs. Rather, it is about preventing responses to such calls from reaching to the XHR caller. This means that in server logs you may notice GET, OPTIONS, POST or other invocations even if the browser does not deliver them to JavaScript.&lt;/p&gt;
&lt;p&gt;At this point, it is best to read the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS&quot;&gt;Mozilla article about CORS&lt;/a&gt;. It goes into all the details and, in fact, given that it is concerned with the web as a whole, some parts of it do not translate directly into REST APIs and Zato but the knowledge is required nevertheless to make sure that the configuration is correct.&lt;/p&gt;
&lt;p&gt;The rest of this blog post will assume that you now know what to configure and only a way to do it with Zato needs to be shown.&lt;/p&gt;
&lt;h2 id=&quot;configuring-zato-for-cors&quot;&gt;Configuring Zato for CORS&lt;/h2&gt;
&lt;p&gt;Configuration of Zato services can be condensed to two main choices:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We can use the after_handle &lt;a href=&quot;https://zato.io/en/docs/4.1/dev/index.html&quot;&gt;response hook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;We can add handle_OPTIONS&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Consider the code below. It uses after_handle - this is a method that is invoked each time the handle method has just finished. We can take advantage of it to inject response HTTP headers.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Business implementation goes here&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;after_handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# We only allow requests from this particular origin&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;allow_from_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Access-Control-Allow-Origin&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;allow_from_value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;https://www.example.com&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;allow_from_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;allow_from&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, the same but using handle_OPTIONS.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-1-5&quot; name=&quot;line-1-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-6&quot; name=&quot;line-1-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyService2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-7&quot; name=&quot;line-1-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-8&quot; name=&quot;line-1-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-9&quot; name=&quot;line-1-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Business implementation goes here&lt;/span&gt;
&lt;a id=&quot;line-1-10&quot; name=&quot;line-1-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;a id=&quot;line-1-11&quot; name=&quot;line-1-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-12&quot; name=&quot;line-1-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle_OPTIONS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-13&quot; name=&quot;line-1-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-14&quot; name=&quot;line-1-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# We only allow requests from this particular origin&lt;/span&gt;
&lt;a id=&quot;line-1-15&quot; name=&quot;line-1-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;allow_from_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Access-Control-Allow-Origin&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-1-16&quot; name=&quot;line-1-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;allow_from_value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;https://www.example.com&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-1-17&quot; name=&quot;line-1-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-18&quot; name=&quot;line-1-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;allow_from_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;allow_from&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The difference between the two is not large. Mainly, after_handle runs regardless whether the channel is invoked using REST, SOAP, IBM MQ, AMQP, WebSockets or any other possible which means that in some cases it may be superfluous.&lt;/p&gt;
&lt;p&gt;On the other hand, with REST channels, after_handle runs no matter what input HTTP verb the request is using while handle_OPTIONS reacts to OPTIONS only so after_handle may be used for both simple and pre-flight CORS configuration.&lt;/p&gt;
&lt;p&gt;All things considered, which one to use will be a choice to make based on a given integration scenario - both are applicable, depending on specific requirements.&lt;/p&gt;
&lt;p&gt;Note also that in the code above each service has its own CORS configuration. Yet, it is likely that the same configuration should be shared by multiple services. Simple Python inheritance will work here nicely:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-2-5&quot; name=&quot;line-2-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-6&quot; name=&quot;line-2-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;BaseService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-7&quot; name=&quot;line-2-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-8&quot; name=&quot;line-2-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;after_handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-9&quot; name=&quot;line-2-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-10&quot; name=&quot;line-2-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# We only allow requests from this particular origin&lt;/span&gt;
&lt;a id=&quot;line-2-11&quot; name=&quot;line-2-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;allow_from_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Access-Control-Allow-Origin&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-12&quot; name=&quot;line-2-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;allow_from_value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;https://www.example.com&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-13&quot; name=&quot;line-2-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-14&quot; name=&quot;line-2-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;allow_from_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;allow_from&lt;/span&gt;
&lt;a id=&quot;line-2-15&quot; name=&quot;line-2-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-16&quot; name=&quot;line-2-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyChildService1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BaseService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-17&quot; name=&quot;line-2-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-18&quot; name=&quot;line-2-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-19&quot; name=&quot;line-2-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Business implementation goes here&lt;/span&gt;
&lt;a id=&quot;line-2-20&quot; name=&quot;line-2-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;a id=&quot;line-2-21&quot; name=&quot;line-2-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-22&quot; name=&quot;line-2-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyChildService2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BaseService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-23&quot; name=&quot;line-2-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-24&quot; name=&quot;line-2-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-25&quot; name=&quot;line-2-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Business implementation goes here&lt;/span&gt;
&lt;a id=&quot;line-2-26&quot; name=&quot;line-2-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or, with handle_OPTIONS:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-3-2&quot; name=&quot;line-3-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-3&quot; name=&quot;line-3-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-3-4&quot; name=&quot;line-3-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-3-5&quot; name=&quot;line-3-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-6&quot; name=&quot;line-3-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;BaseService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-7&quot; name=&quot;line-3-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-8&quot; name=&quot;line-3-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle_OPTIONS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-9&quot; name=&quot;line-3-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-10&quot; name=&quot;line-3-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# We only allow requests from this particular origin&lt;/span&gt;
&lt;a id=&quot;line-3-11&quot; name=&quot;line-3-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;allow_from_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Access-Control-Allow-Origin&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-3-12&quot; name=&quot;line-3-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;allow_from_value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;https://www.example.com&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-3-13&quot; name=&quot;line-3-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-14&quot; name=&quot;line-3-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;allow_from_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;allow_from&lt;/span&gt;
&lt;a id=&quot;line-3-15&quot; name=&quot;line-3-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-16&quot; name=&quot;line-3-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyChildService1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BaseService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-17&quot; name=&quot;line-3-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-18&quot; name=&quot;line-3-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-19&quot; name=&quot;line-3-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Business implementation goes here&lt;/span&gt;
&lt;a id=&quot;line-3-20&quot; name=&quot;line-3-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;a id=&quot;line-3-21&quot; name=&quot;line-3-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-22&quot; name=&quot;line-3-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyChildService2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BaseService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-23&quot; name=&quot;line-3-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-24&quot; name=&quot;line-3-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-25&quot; name=&quot;line-3-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Business implementation goes here&lt;/span&gt;
&lt;a id=&quot;line-3-26&quot; name=&quot;line-3-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, the same configuration is accessible to more than one service and if anything needs to be changed, it is done in the base service.&lt;/p&gt;
&lt;p&gt;Observe that the code above uses &#x27;Access-Control-Allow-Origin&#x27; only but CORS employs other headers as well - you just put them all in self.response.headers, it is a regular Python dictionary with keys mapping to HTTP header names and values to header values.&lt;/p&gt;
&lt;p&gt;This is everything that is needed to configure Zato for CORS-using REST API calls - choose the method most suitable (after_handle or handle_OPTIONS), assign headers to self.response.headers, hot-deploy your service and that is it!&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 14 Dec 2020 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/rest-channels-cors.html</guid></item><item><title>Multi-protocol file transfer integrations</title><link>https://zato.io/en/blog/file-transfer.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/file-transfer.html&quot;&gt;Multi-protocol file transfer integrations&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2020-12-07, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;In many domains, transfer of static and batch files is an important part of systems integrations and a large number of applications produce and expect data in the form of files rather than network-based APIs. In this article, we shall see how
Zato
makes multi-protocol integrations of this kind possible in a way that is secure, scalable and easy to extend in Python.&lt;/p&gt;
&lt;p&gt;File transfer is often found in scenarios such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Mass-transfer of invoices, e.g. an ERP may produce an hourly list of new ones to process&lt;/li&gt;
&lt;li&gt;Batch-transfer of patient data in healthcare systems&lt;/li&gt;
&lt;li&gt;Publication of updates to data such as stocks or exchange rates&lt;/li&gt;
&lt;li&gt;Secure exchange of orders with external business partners, e.g. using files encrypted with PGP&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are many more scenarios but what they all have in common is that in each such data flow there may be a single producer and multiple recipients of information, each of them preferring to use different technologies.&lt;/p&gt;
&lt;p&gt;For instance, a single file saved to a Windows share may go to a REST endpoint, an IBM MQ or AMQP queue, an AWS S3 bucket and to e-mail recipients, each of which may be an independent application or business entity and each may use a different data format, e.g. what is CSV initially may need to be transformed to JSON, XML and PDF, depending on the receiver.&lt;/p&gt;
&lt;p&gt;Let&#x27;s see how Zato helps in implementation of processes of this kind.&lt;/p&gt;
&lt;h2 id=&quot;file-transfer-channels&quot;&gt;File transfer channels&lt;/h2&gt;
&lt;p&gt;The core Zato concept in file integrations is that of file transfer channels - reusable definitions pointing to producers and consumers of data along with accompanying details, such as a schedule, file patterns to use, what encoding the data is in and more.&lt;/p&gt;
&lt;p&gt;Zato will connect to the data source automatically and handle each new or modified file according to the channel&#x27;s configuration, i.e. by parsing and distributing it to data recipients, allowing one to apply any transformations or enrichment as required, and optionally deleting the data file from the source location afterwards.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/arch.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;In the Zato Dashboard, a file transfer channel may be defined as below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/file-transfer-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Let&#x27;s consider the following sample definition. In this particular case:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The data source is
&lt;a href=&quot;https://zato.io/en/blog/sftp.html&quot;&gt;an SFTP connection definition&lt;/a&gt;
called CRM&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;New or changed files are processed according to
&lt;a href=&quot;https://zato.io/en/blog/python-scheduler.html&quot;&gt;a schedule&lt;/a&gt; configured for a job called Transfer Invoices Job&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Multiple input directories and glob file patterns can be used&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Among of data recipients are REST outgoing connections - any file picked up from the source location will be sent to a REST endpoint directly as-is, without any programming needed&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A file can be sent to
  [a service]/en/docs/4.1/intro/esb-soa.html) - and the service may transform or enrich the file as needed, e.g. it may change its data format, invoke more APIs to obtain additional data, combine it all and send the result to one or more recipients&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/file-transfer-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Note the flexibility and reusability - the same data source, schedule and recipients can be configured to take part in multiple file integration processes without influencing each other.&lt;/p&gt;
&lt;p&gt;In fact, the same services and endpoints may independently participate in both file and online API integrations.&lt;/p&gt;
&lt;h2 id=&quot;sample-process&quot;&gt;Sample process&lt;/h2&gt;
&lt;p&gt;To showcase how file transfer works in practice, let&#x27;s implement an example process:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An external application periodically produces customer orders as CSV&lt;/li&gt;
&lt;li&gt;The CSV files are made available on SFTP that Zato can access&lt;/li&gt;
&lt;li&gt;They are to be checked once a minute&lt;/li&gt;
&lt;li&gt;Each file needs to be sent to a REST endpoint as-is, an AMQP queue as JSON and as an Excel e-mail attachment to selected people&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/sample-arch.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;initial-dashboard-configuration&quot;&gt;Initial Dashboard configuration&lt;/h2&gt;
&lt;p&gt;We need to configure a few Zato objects for the new file transfer to use, check below for details of how to do it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://zato.io/en/blog/sftp.html&quot;&gt;An SFTP connection&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://zato.io/en/blog/python-scheduler.html&quot;&gt;A scheduler&#x27;s job&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A REST connection definition&lt;/li&gt;
&lt;li&gt;An AMQP connection definition&lt;/li&gt;
&lt;li&gt;An SMTP connection definition&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Simply fill out a form such as the ones below, click OK and you are done. No server restarts are needed.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/scheduler-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/rest-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/smtp-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/smtp-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/amqp-menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/amqp-form.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;rest-recipients-are-special&quot;&gt;REST recipients are special&lt;/h2&gt;
&lt;p&gt;Because so many new integrations are based around REST, recipients of this kind are treated specially by file transfer channels in that there is no programming required for files to be transferred to REST endpoints.&lt;/p&gt;
&lt;p&gt;When you create a file transfer channel, simply assign one or more REST endpoints to it and Zato will send all the files to them as soon as they are picked up from the data source.&lt;/p&gt;
&lt;p&gt;As to other recipient types, we will use the Python-based service below.&lt;/p&gt;
&lt;h2 id=&quot;python-code&quot;&gt;Python code&lt;/h2&gt;
&lt;p&gt;Let&#x27;s quickly implement a service that will transform and send the files to AMQP and SMTP recipients.&lt;/p&gt;
&lt;p&gt;The service will receive its input in an attribute called self.request.raw_request - we will transform it to the required data formats and send to both AMQP and SMTP.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;  1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;  2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;  3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# stdlib&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;  4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;io&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;  5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;  6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# For Excel files&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;  7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;openpyxl&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Workbook&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;  8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;openpyxl.writer.excel&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;save_workbook&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;  9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.common.api&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SMTPMessage&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.common.json_&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;HandleNewOrders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;api.file-transfer.handle-new-orders&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# All of our input data, including metadata assigned by Zato&lt;/span&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raw_request&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Full path, including directory and file name&lt;/span&gt;
&lt;a id=&quot;line-0-26&quot; name=&quot;line-0-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;full_path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;full_path&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-27&quot; name=&quot;line-0-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-28&quot; name=&quot;line-0-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Channel the file was received through&lt;/span&gt;
&lt;a id=&quot;line-0-29&quot; name=&quot;line-0-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;channel_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;channel_name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-30&quot; name=&quot;line-0-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-31&quot; name=&quot;line-0-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Data received, already parsed by our channel&lt;/span&gt;
&lt;a id=&quot;line-0-32&quot; name=&quot;line-0-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;data&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-33&quot; name=&quot;line-0-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-34&quot; name=&quot;line-0-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Log info that we are ready&lt;/span&gt;
&lt;a id=&quot;line-0-35&quot; name=&quot;line-0-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Processing file `&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;` from `&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;`&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-36&quot; name=&quot;line-0-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-37&quot; name=&quot;line-0-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Send to the CRM using AMQP first ..&lt;/span&gt;
&lt;a id=&quot;line-0-38&quot; name=&quot;line-0-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;#self.send_orders_to_crm(data)&lt;/span&gt;
&lt;a id=&quot;line-0-39&quot; name=&quot;line-0-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-40&quot; name=&quot;line-0-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Send an email now ..&lt;/span&gt;
&lt;a id=&quot;line-0-41&quot; name=&quot;line-0-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;notify_new_orders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-42&quot; name=&quot;line-0-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-43&quot; name=&quot;line-0-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# We are done!&lt;/span&gt;
&lt;a id=&quot;line-0-44&quot; name=&quot;line-0-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-45&quot; name=&quot;line-0-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-46&quot; name=&quot;line-0-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-47&quot; name=&quot;line-0-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;send_orders_to_crm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-48&quot; name=&quot;line-0-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot; Converts input orders to JSON and sends them to the CRM using AMQP.&lt;/span&gt;
&lt;a id=&quot;line-0-49&quot; name=&quot;line-0-49&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-49&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 49 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-0-50&quot; name=&quot;line-0-50&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-50&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 50 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# A list of orders to be sent as JSON&lt;/span&gt;
&lt;a id=&quot;line-0-51&quot; name=&quot;line-0-51&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-51&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 51 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;orders&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;a id=&quot;line-0-52&quot; name=&quot;line-0-52&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-52&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 52 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-53&quot; name=&quot;line-0-53&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-53&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 53 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Process each input CSV row ..&lt;/span&gt;
&lt;a id=&quot;line-0-54&quot; name=&quot;line-0-54&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-54&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 54 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-55&quot; name=&quot;line-0-55&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-55&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 55 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-56&quot; name=&quot;line-0-56&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-56&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 56 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. extract information from each line ..&lt;/span&gt;
&lt;a id=&quot;line-0-57&quot; name=&quot;line-0-57&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-57&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 57 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;order_no&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-58&quot; name=&quot;line-0-58&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-58&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 58 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;customer_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-59&quot; name=&quot;line-0-59&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-59&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 59 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;order_amount&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-60&quot; name=&quot;line-0-60&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-60&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 60 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-61&quot; name=&quot;line-0-61&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-61&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 61 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. create a dict representing each order ..&lt;/span&gt;
&lt;a id=&quot;line-0-62&quot; name=&quot;line-0-62&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-62&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 62 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-0-63&quot; name=&quot;line-0-63&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-63&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 63 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;s1&quot;&gt;&amp;#39;order_no&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order_no&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-64&quot; name=&quot;line-0-64&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-64&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 64 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;s1&quot;&gt;&amp;#39;customer_id&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customer_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-65&quot; name=&quot;line-0-65&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-65&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 65 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;s1&quot;&gt;&amp;#39;order_amount&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;order_amount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-0-66&quot; name=&quot;line-0-66&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-66&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 66 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-0-67&quot; name=&quot;line-0-67&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-67&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 67 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-68&quot; name=&quot;line-0-68&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-68&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 68 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. append the dict to already existing ones.&lt;/span&gt;
&lt;a id=&quot;line-0-69&quot; name=&quot;line-0-69&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-69&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 69 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;n&quot;&gt;orders&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;order&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-70&quot; name=&quot;line-0-70&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-70&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 70 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-71&quot; name=&quot;line-0-71&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-71&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 71 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Convert the list of orders into a JSON string&lt;/span&gt;
&lt;a id=&quot;line-0-72&quot; name=&quot;line-0-72&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-72&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 72 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;json_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dumps&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;orders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-73&quot; name=&quot;line-0-73&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-73&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 73 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-74&quot; name=&quot;line-0-74&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-74&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 74 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Details of the AMQP connection to use ..&lt;/span&gt;
&lt;a id=&quot;line-0-75&quot; name=&quot;line-0-75&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-75&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 75 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;My AMQP Connection&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-76&quot; name=&quot;line-0-76&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-76&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 76 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/orders.new&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-77&quot; name=&quot;line-0-77&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-77&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 77 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;routing_key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;zato&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-78&quot; name=&quot;line-0-78&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-78&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 78 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-79&quot; name=&quot;line-0-79&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-79&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 79 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. and now, we can use the already converted message using AMQP.&lt;/span&gt;
&lt;a id=&quot;line-0-80&quot; name=&quot;line-0-80&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-80&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 80 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outgoing&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;amqp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;routing_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-81&quot; name=&quot;line-0-81&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-81&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 81 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-82&quot; name=&quot;line-0-82&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-82&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 82 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ##############################################################################&lt;/span&gt;
&lt;a id=&quot;line-0-83&quot; name=&quot;line-0-83&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-83&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 83 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-84&quot; name=&quot;line-0-84&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-84&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 84 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;notify_new_orders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-85&quot; name=&quot;line-0-85&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-85&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 85 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-86&quot; name=&quot;line-0-86&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-86&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 86 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Create a new workbook ..&lt;/span&gt;
&lt;a id=&quot;line-0-87&quot; name=&quot;line-0-87&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-87&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 87 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;workbook&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Workbook&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-0-88&quot; name=&quot;line-0-88&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-88&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 88 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-89&quot; name=&quot;line-0-89&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-89&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 89 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. create a new worksheet for orders ..&lt;/span&gt;
&lt;a id=&quot;line-0-90&quot; name=&quot;line-0-90&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-90&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 90 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;sheet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;workbook&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create_sheet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;New orders&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-91&quot; name=&quot;line-0-91&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-91&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 91 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-92&quot; name=&quot;line-0-92&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-92&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 92 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. iterate over all CSV orders ..&lt;/span&gt;
&lt;a id=&quot;line-0-93&quot; name=&quot;line-0-93&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-93&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 93 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row_idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-94&quot; name=&quot;line-0-94&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-94&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 94 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-95&quot; name=&quot;line-0-95&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-95&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 95 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# .. now, iterate over all columns ..&lt;/span&gt;
&lt;a id=&quot;line-0-96&quot; name=&quot;line-0-96&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-96&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 96 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;column_idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-97&quot; name=&quot;line-0-97&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-97&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 97 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-98&quot; name=&quot;line-0-98&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-98&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 98 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;c1&quot;&gt;# .. create a new cell in the sheet ..&lt;/span&gt;
&lt;a id=&quot;line-0-99&quot; name=&quot;line-0-99&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-99&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 99 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;sheet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cell&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;column&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;column_idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;row_idx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-100&quot; name=&quot;line-0-100&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-100&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;100 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-101&quot; name=&quot;line-0-101&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-101&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;101 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. our in-memory buffer for the Excel file ..&lt;/span&gt;
&lt;a id=&quot;line-0-102&quot; name=&quot;line-0-102&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-102&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;102 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BytesIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-0-103&quot; name=&quot;line-0-103&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-103&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;103 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-104&quot; name=&quot;line-0-104&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-104&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;104 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. save the workbook to RAM ..&lt;/span&gt;
&lt;a id=&quot;line-0-105&quot; name=&quot;line-0-105&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-105&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;105 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;save_workbook&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;workbook&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-106&quot; name=&quot;line-0-106&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-106&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;106 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-107&quot; name=&quot;line-0-107&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-107&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;107 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. rewind to the beginning ..&lt;/span&gt;
&lt;a id=&quot;line-0-108&quot; name=&quot;line-0-108&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-108&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;108 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seek&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-109&quot; name=&quot;line-0-109&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-109&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;109 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-110&quot; name=&quot;line-0-110&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-110&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;110 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. get the Excel file ..&lt;/span&gt;
&lt;a id=&quot;line-0-111&quot; name=&quot;line-0-111&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-111&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;111 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;excel_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-0-112&quot; name=&quot;line-0-112&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-112&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;112 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-113&quot; name=&quot;line-0-113&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-113&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;113 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. do not forget to close the buffer now that we do not need it.&lt;/span&gt;
&lt;a id=&quot;line-0-114&quot; name=&quot;line-0-114&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-114&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;114 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-0-115&quot; name=&quot;line-0-115&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-115&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;115 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-116&quot; name=&quot;line-0-116&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-116&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;116 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# We have the Excel file so we can send it as an e-mail attachment now.&lt;/span&gt;
&lt;a id=&quot;line-0-117&quot; name=&quot;line-0-117&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-117&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;117 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-118&quot; name=&quot;line-0-118&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-118&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;118 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# In practice, this would be kept in a config file,&lt;/span&gt;
&lt;a id=&quot;line-0-119&quot; name=&quot;line-0-119&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-119&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;119 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Redis, SQL or another config source.&lt;/span&gt;
&lt;a id=&quot;line-0-120&quot; name=&quot;line-0-120&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-120&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;120 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;email_to&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;hello@example.com&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-121&quot; name=&quot;line-0-121&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-121&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;121 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;email_cc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;my.cc.1@example.com&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;my.cc.2@example.com&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;a id=&quot;line-0-122&quot; name=&quot;line-0-122&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-122&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;122 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;email_from&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;zato@example.com&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-123&quot; name=&quot;line-0-123&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-123&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;123 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;email_body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&amp;lt;h1&amp;gt;New orders&amp;lt;/h1&amp;gt;&amp;lt;br/&amp;gt;New orders are in the attachment.&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-124&quot; name=&quot;line-0-124&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-124&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;124 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;file_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;new_orders.xlsx&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-0-125&quot; name=&quot;line-0-125&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-125&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;125 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-126&quot; name=&quot;line-0-126&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-126&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;126 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Construct a new message ..&lt;/span&gt;
&lt;a id=&quot;line-0-127&quot; name=&quot;line-0-127&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-127&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;127 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SMTPMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-0-128&quot; name=&quot;line-0-128&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-128&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;128 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-129&quot; name=&quot;line-0-129&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-129&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;129 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. we send an HTML file ..&lt;/span&gt;
&lt;a id=&quot;line-0-130&quot; name=&quot;line-0-130&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-130&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;130 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_html&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;True&lt;/span&gt;
&lt;a id=&quot;line-0-131&quot; name=&quot;line-0-131&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-131&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;131 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-132&quot; name=&quot;line-0-132&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-132&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;132 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. assign details ..&lt;/span&gt;
&lt;a id=&quot;line-0-133&quot; name=&quot;line-0-133&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-133&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;133 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;email_to&lt;/span&gt;
&lt;a id=&quot;line-0-134&quot; name=&quot;line-0-134&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-134&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;134 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;email_cc&lt;/span&gt;
&lt;a id=&quot;line-0-135&quot; name=&quot;line-0-135&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-135&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;135 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;from_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;email_from&lt;/span&gt;
&lt;a id=&quot;line-0-136&quot; name=&quot;line-0-136&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-136&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;136 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;email_body&lt;/span&gt;
&lt;a id=&quot;line-0-137&quot; name=&quot;line-0-137&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-137&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;137 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-138&quot; name=&quot;line-0-138&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-138&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;138 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. attach the file ..&lt;/span&gt;
&lt;a id=&quot;line-0-139&quot; name=&quot;line-0-139&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-139&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;139 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;attach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;file_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;excel_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-140&quot; name=&quot;line-0-140&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-140&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;140 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-141&quot; name=&quot;line-0-141&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-141&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;141 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. obtain a connection to the SMTP server ..&lt;/span&gt;
&lt;a id=&quot;line-0-142&quot; name=&quot;line-0-142&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-142&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;142 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;email&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;smtp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My SMTP Connection&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;
&lt;a id=&quot;line-0-143&quot; name=&quot;line-0-143&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-143&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;143 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-144&quot; name=&quot;line-0-144&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-144&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;144 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# .. and finally, send the message across.&lt;/span&gt;
&lt;a id=&quot;line-0-145&quot; name=&quot;line-0-145&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-145&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;145 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-146&quot; name=&quot;line-0-146&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-146&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;146 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-147&quot; name=&quot;line-0-147&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-147&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;147 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# ############################################################################&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;creating-a-new-file-transfer-channel&quot;&gt;Creating a new file transfer channel&lt;/h2&gt;
&lt;p&gt;Now, we can create a new file transfer channel. After clicking OK, it will start to work.&lt;/p&gt;
&lt;p&gt;If there is anything that needs changing, click Edit in web-admin and enter new information, e.g. new directories to look for files in.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/file-transfer-3.2/sample-form.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;If anything changes in any of the pieces of configuration that the channel uses, such as AMQP, REST or anything else, the channel will reconfigure automatically, without a need for a manual update.&lt;/p&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;Here we are, using Zato, we have just created a multi-protocol file transfer hub, integrating SFTP, AMQP and e-mail.&lt;/p&gt;
&lt;p&gt;New protocols and recipients can be added at any time without disrupting existing file integrations - we can easily extend the service to transform and push the input files to SQL, Cassandra and Redis, for instance.&lt;/p&gt;
&lt;p&gt;And if new data sources are needed, just create new channels, start them in addition to the existing ones and they will begin to work immediately. It is just that easy!&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 07 Dec 2020 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/file-transfer.html</guid></item><item><title>Backing up and restoring Zato Single Sign-On data</title><link>https://zato.io/en/blog/single-sign-on-backup-restore.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/single-sign-on-backup-restore.html&quot;&gt;Backing up and restoring Zato Single Sign-On data&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2020-05-29, by Anielkis Herrera
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/anielkis.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;This article presents a procedure for backing up all of
Zato Single Sign-On (SSO)
data and restoring it later on.&lt;/p&gt;
&lt;p&gt;A single Zato server with SQLite is used for simplicity reasons but the same principles hold regardless of the size of one&#x27;s environment or the SQL database used.&lt;/p&gt;
&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;https://upcdn.io/kW15bqq/raw/root/en/docs/4.1/gfx/sso/intro.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;There are two data sources that SSO uses:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Run-time information, such as users, groups, and all the
  other objects
  , are stored in an &lt;strong&gt;SQL database&lt;/strong&gt; in tables prefixed with &lt;strong&gt;zato_sso_&lt;/strong&gt;, e.g. zato_sso_user or zato_sso_group.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Encryption keys are kept in a file called &lt;strong&gt;secrets.conf&lt;/strong&gt; - the same file is shared by all servers in a cluster&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thus, to make a backup:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Connect to an existing server via SSH&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Dump the SQL contents of SSO tables and related objects such as indexes&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make a copy of secrets.conf&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save everything in a safe place&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Conversely, to restore a backup:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Load the backup from the safe place&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Connect to a new Zato server via SSH&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Move the contents of the SQL dump to the database&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Replace the server&#x27;s secrets.conf with the one copied over earlier during backup&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;backing-up-sql-data&quot;&gt;Backing up SQL data&lt;/h2&gt;
&lt;p&gt;Assuming that a Zato server is in a directory called /home/zato/sso1/server, here is how to back up an SQLite database:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/home/zato/sso1/server
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;sqlite3&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato.db&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;.dump zato_sso_%&amp;quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&amp;gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato-sso-backup.sql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will create a file called &lt;strong&gt;zato-sso-backup.sql&lt;/strong&gt; the contents of which is the schema and rows of all the SSO objects.&lt;/p&gt;
&lt;p&gt;To make it easier to restore the backup later, open the file and add the following commands right after &quot;BEGIN TRANSACTION;&quot;&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;DROP&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;zato_sso_group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;DROP&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;zato_sso_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;DROP&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;zato_sso_user_group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;DROP&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;zato_sso_session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-1-5&quot; name=&quot;line-1-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;DROP&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;zato_sso_attr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-1-6&quot; name=&quot;line-1-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;DROP&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;zato_sso_linked_auth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;a id=&quot;line-1-7&quot; name=&quot;line-1-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;DROP&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;zato_sso_password_reset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The idea with the DROP statements is that when you are restoring SSO from a backup, these tables, albeit empty, will already exist, so we can just drop them to silence out any SQLite warnings.&lt;/p&gt;
&lt;h2 id=&quot;backing-up-secretsconf&quot;&gt;Backing up secrets.conf&lt;/h2&gt;
&lt;p&gt;Again, if the server is in /home/zato/sso1/server, the full path to secrets.conf is /home/zato/sso1/server/config/repo/secrets.conf - open the file and find a
section called &lt;strong&gt;[secret_keys]&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The section will have either one key called &lt;strong&gt;key1&lt;/strong&gt; or two keys, called &lt;strong&gt;key1&lt;/strong&gt; and &lt;strong&gt;sso_key1&lt;/strong&gt;, depending on when your environment was created - older
ones will only have key1 but newer ones have sso_key1 too.&lt;/p&gt;
&lt;p&gt;If sso_key1 exists, Zato will use it to encrypt SSO data in the database, preferring it over key1. But if there is only key1 then this is what Zato uses.&lt;/p&gt;
&lt;p&gt;Depending on which is available, make a copy of it. In a later step, it will be used as sso_key1 in a new environment. I.e. its new name
will be always sso_key1, no matter if in the source environment it was key1 or sso_key1.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;[secret_keys]&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;na&quot;&gt;key1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;P8ViJZs8hM...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;[secret_keys]&lt;/span&gt;
&lt;a id=&quot;line-3-2&quot; name=&quot;line-3-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;na&quot;&gt;key1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;P8ViJZs8hM...&lt;/span&gt;
&lt;a id=&quot;line-3-3&quot; name=&quot;line-3-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;na&quot;&gt;sso_key1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;rmoz7btA8...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;creating-a-new-server&quot;&gt;Creating a new server&lt;/h2&gt;
&lt;p&gt;We work under assumption that a new server will be created in a directory named /home/zato/sso2/server.&lt;/p&gt;
&lt;p&gt;Note that it should be a completely new instance in a new cluster. Do not start the server yet.&lt;/p&gt;
&lt;h2 id=&quot;restoring-sql-data&quot;&gt;Restoring SQL data&lt;/h2&gt;
&lt;p&gt;Move the zato-sso-backup.sql file to /home/zato/sso2/server and run the commands below:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-4-1&quot; name=&quot;line-4-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/home/zato/sso2/server
&lt;a id=&quot;line-4-2&quot; name=&quot;line-4-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;sqlite3&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato.db&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&amp;lt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato-sso-backup.sql
&lt;a id=&quot;line-4-3&quot; name=&quot;line-4-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$?&lt;/span&gt;
&lt;a id=&quot;line-4-4&quot; name=&quot;line-4-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Exit code 0 should be returned on output, indicating a successful operation.&lt;/p&gt;
&lt;h2 id=&quot;using-sso_key1-in-the-new-server&quot;&gt;Using sso_key1 in the new server&lt;/h2&gt;
&lt;p&gt;The secret key copied from the original server (sso_key1 if it existed, key1 otherwise) can be used in the new server in several ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It can be added to the new server&#x27;s secrets.conf:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-5-1&quot; name=&quot;line-5-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;[secret_keys]&lt;/span&gt;
&lt;a id=&quot;line-5-2&quot; name=&quot;line-5-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;na&quot;&gt;key1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Tr4nTMQlh...&lt;/span&gt;
&lt;a id=&quot;line-5-3&quot; name=&quot;line-5-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;na&quot;&gt;sso_key1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;lt;insert the key here&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;It can be provided as a command line argument to &quot;zato start&quot;:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-6-1&quot; name=&quot;line-6-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;start&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/home/zato/sso2/server&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;--sso-secret-key&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&amp;lt;insert&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;the&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;key&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;here&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;It can be exported to an environment variable and then used from command line (a variation of the second option):&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-7-1&quot; name=&quot;line-7-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-7-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;export&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;MY_SSO_SECRET_KEY
&lt;a id=&quot;line-7-2&quot; name=&quot;line-7-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-7-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;start&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/home/zato/sso2/server&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;--sso-secret-key&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$MY_SSO_SECRET_KEY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you use environment variables, ensure their names do not start with ZATO, case insensitively, they are reserved for system use.&lt;/p&gt;
&lt;h2 id=&quot;confirming-it-all&quot;&gt;Confirming it all&lt;/h2&gt;
&lt;p&gt;Now, the server can be started and we can confirm that the SSO data can be accessed by logging it to the system as one of its users, as below - output was reformatted for clarity:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-8-1&quot; name=&quot;line-8-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;sso&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;login&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/home/zato/sso2/server&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;my.user
&lt;a id=&quot;line-8-2&quot; name=&quot;line-8-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;User&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;logged&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
&lt;a id=&quot;line-8-3&quot; name=&quot;line-8-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;username&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;my.user&amp;#39;&lt;/span&gt;,
&lt;a id=&quot;line-8-4&quot; name=&quot;line-8-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;zusr6htg...&amp;#39;&lt;/span&gt;,
&lt;a id=&quot;line-8-5&quot; name=&quot;line-8-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;ust&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;gAAAAABe0M_Pf8cdBa6bimnjfVUt5CF...&amp;#39;&lt;/span&gt;,
&lt;a id=&quot;line-8-6&quot; name=&quot;line-8-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;creation_time&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;2020-05-29T09:03:11.459337&amp;#39;&lt;/span&gt;,
&lt;a id=&quot;line-8-7&quot; name=&quot;line-8-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;expiration_time&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;2020-05-29T10:03:11.459337&amp;#39;&lt;/span&gt;,
&lt;a id=&quot;line-8-8&quot; name=&quot;line-8-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;has_w_about_to_exp&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;False
&lt;a id=&quot;line-8-9&quot; name=&quot;line-8-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-8-10&quot; name=&quot;line-8-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;That concludes the process - the
SSO
data is now restored and the server can be fully used, just like the original one.&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Fri, 29 May 2020 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/single-sign-on-backup-restore.html</guid></item><item><title>Zato services as containers for Python functions and methods</title><link>https://zato.io/en/blog/service-container.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/service-container.html&quot;&gt;Zato services as containers for Python functions and methods&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2020-03-10, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;Acting as containers for enterprise APIs,
Zato
services are able to invoke each other to form higher-level processes and message flows. What if a service needs to invoke a hot-deployable Python function or method, though? Read on to learn details of how to accomplish it.&lt;/p&gt;
&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;
&lt;p&gt;Invoking another service is a simple matter - consider the two ones below. For simplicity, they are defined in the same Python module but they could be very well in different ones.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;service&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyAPI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;invoke&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;create.account&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;username&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;my.user&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CreateAccount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;I have been invoked with &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raw_request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;MyAPI invokes CreateAccount by its name - the nice thing about it is that it is possible to apply additional conditions to such invocations, e.g. CreateAccount can be rate-limited.&lt;/p&gt;
&lt;p&gt;On the other hand, invoking another service means simply executing a Python function call, an instance of the other service is created (a Python class instance) and then its &lt;strong&gt;handle&lt;/strong&gt; method is invoked with all the request data and metadata available through various &lt;strong&gt;self&lt;/strong&gt; attributes, e.g. self.request.http, self.request.input and similar.&lt;/p&gt;
&lt;p&gt;This also means that at times it is convenient not to have to write a whole Python class, however simple, only to invoke it with some parameters. This is what the next section us be about.&lt;/p&gt;
&lt;h2 id=&quot;invoking-python-methods&quot;&gt;Invoking Python methods&lt;/h2&gt;
&lt;p&gt;Let us change the Python code slightly.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;service&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyAPI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-5&quot; name=&quot;line-1-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;customer.account&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-1-6&quot; name=&quot;line-1-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-7&quot; name=&quot;line-1-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;response1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create_account&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-1-8&quot; name=&quot;line-1-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;response2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete_account&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-1-9&quot; name=&quot;line-1-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;response3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;update_account&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-1-10&quot; name=&quot;line-1-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-11&quot; name=&quot;line-1-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;CustomerAccount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-12&quot; name=&quot;line-1-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-13&quot; name=&quot;line-1-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;create_account&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-14&quot; name=&quot;line-1-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;a id=&quot;line-1-15&quot; name=&quot;line-1-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-16&quot; name=&quot;line-1-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;delete_account&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-17&quot; name=&quot;line-1-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;a id=&quot;line-1-18&quot; name=&quot;line-1-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-19&quot; name=&quot;line-1-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;update_account&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-20&quot; name=&quot;line-1-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There are still two services but the second one can be effectively treated as a container for regular Python methods and functions. It no longer has its handle method defined, though there is nothing preventing it from doing so if required, and all it really has is three Python functions (methods).&lt;/p&gt;
&lt;p&gt;Note, however, a fundamental difference with regards to how many services are needed to implement a fuller API.&lt;/p&gt;
&lt;p&gt;Previously, a service was needed for each action to do with customer accounts, e.g. CreateAccount, DeleteAccount, UpdateAccount etc. Now, there is only one service, called CustomerAccount, and other services invoke its individual methods.&lt;/p&gt;
&lt;p&gt;Such a multi-method service can be hot-deployed like any other which makes it a great way to group utility-like functionality in one place - such functions tend to be reused in many places, usually all over the code, so it is good to be able to update them at ease.&lt;/p&gt;
&lt;h2 id=&quot;code-completion&quot;&gt;Code completion&lt;/h2&gt;
&lt;p&gt;There is still one aspect to remember about - when a new instance is created through &lt;strong&gt;new_instance&lt;/strong&gt;, we would like to be able to have code auto-completion available.&lt;/p&gt;
&lt;p&gt;If the other service is in the same Python module, it suffices to use this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;customer.account&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# type: CustomerAccount&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;However, if the service whose methods are to be invoked is in a different Python module, we need to import for its name to be know to one&#x27;s IDE. Yet, we do not really want to import it, we just need its name.&lt;/p&gt;
&lt;p&gt;Hence, we guard the import with an if statement that never runs:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-3-2&quot; name=&quot;line-3-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;my.api&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CustomerAccount&lt;/span&gt;
&lt;a id=&quot;line-3-3&quot; name=&quot;line-3-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-3-4&quot; name=&quot;line-3-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyAPI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-5&quot; name=&quot;line-3-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-3-6&quot; name=&quot;line-3-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;instance&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new_instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;customer.account&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# type: CustomerAccount&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, everything is ready - you can hot-deploy services with arbitrary functions and invoke them like any other Python function or method, including having access to code-completion in your IDE.&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Tue, 10 Mar 2020 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/service-container.html</guid></item><item><title>Generating API documentation</title><link>https://zato.io/en/blog/apispec-multi.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/apispec-multi.html&quot;&gt;Generating API documentation&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2020-02-12, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;A recurring need in larger integration projects is generation of API documentation for users belonging to different, yet related, target groups. Read on to learn how to generate Zato-based API specifications for more than one group from a single source of information.&lt;/p&gt;
&lt;p&gt;A typical scenario is granting access to the same APIs to external and internal users - what they have in common is that all of them may want to access the same APIs yet not all of them should have access to documentation on the same level of details.&lt;/p&gt;
&lt;p&gt;For instance - external developers should only know what a given endpoint is for and how to use it but internal ones may also be given information about its inner workings, the kind of details that external users should never learn about.&lt;/p&gt;
&lt;p&gt;If documentation for two such groups is kept separately, it may require more maintenance effort than necessary - after all, if most of it is the same for everyone then it would make sense to keep it in one place and only add or remove details, depending on which group particular API documentation needs to be generated for.&lt;/p&gt;
&lt;p&gt;The
&lt;a href=&quot;https://zato.io/en/blog/apispec.html&quot;&gt;previous article&lt;/a&gt;
went through the process of generating API specifications step by step - this one goes even further by adding introducing the notion of &lt;strong&gt;tags&lt;/strong&gt; that drive which parts of documentation to generate or not.&lt;/p&gt;
&lt;h2 id=&quot;python-docstrings&quot;&gt;Python docstrings&lt;/h2&gt;
&lt;p&gt;Let us use one of the same services as previously - here is its basic form:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;RechargeCard&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot; Recharges a pre-paid card.&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    Amount must not be less than 1 and it cannot be greater than 10000.&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SimpleIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;input_required&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;number&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;amount&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;output_required&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;status&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The result, when generated as Sphinx, will be like below:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/apispec-multi/public.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Now, we would like to add some details that only internal users should have access to - this is how the docstring should be modified, assuming for a moment that there are two CRM systems in the company the usage of which depends on a particular end user&#x27;s account ..&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-1-5&quot; name=&quot;line-1-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-6&quot; name=&quot;line-1-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;RechargeCard&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-1-7&quot; name=&quot;line-1-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot; Recharges a pre-paid card.&lt;/span&gt;
&lt;a id=&quot;line-1-8&quot; name=&quot;line-1-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    Amount must not be less than 1 and it cannot be greater than 10000.&lt;/span&gt;
&lt;a id=&quot;line-1-9&quot; name=&quot;line-1-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-10&quot; name=&quot;line-1-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    #internal&lt;/span&gt;
&lt;a id=&quot;line-1-11&quot; name=&quot;line-1-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-12&quot; name=&quot;line-1-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    For user accounts starting with QM - MyCRM is queried.&lt;/span&gt;
&lt;a id=&quot;line-1-13&quot; name=&quot;line-1-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    For any other account - MyCRM-2 is queried.&lt;/span&gt;
&lt;a id=&quot;line-1-14&quot; name=&quot;line-1-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-1-15&quot; name=&quot;line-1-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-16&quot; name=&quot;line-1-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SimpleIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-1-17&quot; name=&quot;line-1-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;input_required&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;number&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;amount&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-1-18&quot; name=&quot;line-1-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;output_required&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;status&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;.. with the corresponding change in the output:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/apispec-multi/multi.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;What happened above was that we applied a tag called &lt;strong&gt;#internal&lt;/strong&gt; - anything that follows it is included in the output only if that very tag is requested when generating the documentation.&lt;/p&gt;
&lt;p&gt;Note that the tag name is arbitrary, it could be any other name. Note also that there may be more than tag in a docstring, e.g. &lt;strong&gt;#confidential&lt;/strong&gt;, &lt;strong&gt;#private&lt;/strong&gt; or anything else.&lt;/p&gt;
&lt;h2 id=&quot;command-line-usage&quot;&gt;Command-line usage&lt;/h2&gt;
&lt;p&gt;To actually include the #internal tag, the
&lt;a href=&quot;https://zato.io/en/docs/4.1&quot;&gt;zato apispec&lt;/a&gt;
command needs to be told about it explicitly, as below:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;apispec&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/path/to/server&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--dir&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/path/to/output/directory&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--include&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;api.*&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--tags&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;public,internal
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you do not give the command any tags, only the public part of the docstring, one without any tags, will be included in the resulting documentation.&lt;/p&gt;
&lt;p&gt;To make your clear to other developers, you can also directly use the tag &lt;strong&gt;public&lt;/strong&gt; in the command - this will make it easier to understand that you want to generate publicly available information and nothing else.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;apispec&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/path/to/server&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-3-2&quot; name=&quot;line-3-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--dir&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/path/to/output/directory&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-3-3&quot; name=&quot;line-3-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--include&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;api.*&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-3-4&quot; name=&quot;line-3-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;--tags&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;public
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;This is it, you are done now - you can keep your API documentation in one place now and include only the relevant parts of it depending on context - this ensures that no matter who the recipient of your documentation is, it will be always generated from a single source, thus ensuring that all the output will stay in sync.&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Wed, 12 Feb 2020 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/apispec-multi.html</guid></item><item><title>Windows commands and PowerShell scripts as API microservices</title><link>https://zato.io/en/blog/windows-command-powershell-api.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/windows-command-powershell-api.html&quot;&gt;Windows commands and PowerShell scripts as API microservices&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2019-07-23, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;This post goes through the steps of exposing Windows commands and PowerShell scripts as remote
Zato
API services that can be invoked by REST clients.&lt;/p&gt;
&lt;p&gt;This lets one access a fleet of Windows systems from a single place and makes it possible for Zato services to participate in Windows management processes.&lt;/p&gt;
&lt;p&gt;Note that Zato servers always run on Linux and no installation of any kind of software under Windows is necessary for Zato to connect to remote systems.&lt;/p&gt;
&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;
&lt;p&gt;Start by installing a library that implements the remote Windows connectivity:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/opt/zato/current
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;./bin/pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;pywinrm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Next, stop and start again any servers running, e.g.:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;stop&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/path/to/server
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;start&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/path/to/server
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;python-code&quot;&gt;Python code&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://zato.io/en/tutorials/devops/deployment.html&quot;&gt;Deploy&lt;/a&gt;
the following service to your Zato cluster - note its name, &lt;strong&gt;windows.remote.management&lt;/strong&gt;.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;__future__&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;absolute_import&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;division&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;print_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unicode_literals&lt;/span&gt;
&lt;a id=&quot;line-2-4&quot; name=&quot;line-2-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-5&quot; name=&quot;line-2-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# stdlib&lt;/span&gt;
&lt;a id=&quot;line-2-6&quot; name=&quot;line-2-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;traceback&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;format_exc&lt;/span&gt;
&lt;a id=&quot;line-2-7&quot; name=&quot;line-2-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-8&quot; name=&quot;line-2-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# pywinrm&lt;/span&gt;
&lt;a id=&quot;line-2-9&quot; name=&quot;line-2-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;winrm&lt;/span&gt;
&lt;a id=&quot;line-2-10&quot; name=&quot;line-2-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-11&quot; name=&quot;line-2-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-2-12&quot; name=&quot;line-2-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-2-13&quot; name=&quot;line-2-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-14&quot; name=&quot;line-2-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-15&quot; name=&quot;line-2-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;windows.remote.management&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-16&quot; name=&quot;line-2-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-17&quot; name=&quot;line-2-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SimpleIO&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-18&quot; name=&quot;line-2-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;input_required&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;type&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;data&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-19&quot; name=&quot;line-2-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;output_required&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;exec_code&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-20&quot; name=&quot;line-2-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;output_optional&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;status_code&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;stdout&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;stderr&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;details&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-21&quot; name=&quot;line-2-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;response_elem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;None&lt;/span&gt;
&lt;a id=&quot;line-2-22&quot; name=&quot;line-2-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;skip_empty_keys&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;True&lt;/span&gt;
&lt;a id=&quot;line-2-23&quot; name=&quot;line-2-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-24&quot; name=&quot;line-2-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-25&quot; name=&quot;line-2-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-26&quot; name=&quot;line-2-26&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-26&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;26 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Local aliases&lt;/span&gt;
&lt;a id=&quot;line-2-27&quot; name=&quot;line-2-27&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-27&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;27 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;input_type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;
&lt;a id=&quot;line-2-28&quot; name=&quot;line-2-28&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-28&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;28 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;input_data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;
&lt;a id=&quot;line-2-29&quot; name=&quot;line-2-29&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-29&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;29 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-30&quot; name=&quot;line-2-30&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-30&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;30 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Validate input - we support either regular commands&lt;/span&gt;
&lt;a id=&quot;line-2-31&quot; name=&quot;line-2-31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-31&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;31 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# or PowerShell scripts on input.&lt;/span&gt;
&lt;a id=&quot;line-2-32&quot; name=&quot;line-2-32&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-32&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;32 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input_type&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;cmd&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;ps&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-2-33&quot; name=&quot;line-2-33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-33&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;33 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exec_code&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;error&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-34&quot; name=&quot;line-2-34&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-34&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;34 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;details&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Invalid type&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-35&quot; name=&quot;line-2-35&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-35&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;35 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-36&quot; name=&quot;line-2-36&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-36&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;36 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Input was valid, we can try to execute the command now&lt;/span&gt;
&lt;a id=&quot;line-2-37&quot; name=&quot;line-2-37&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-37&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;37 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-38&quot; name=&quot;line-2-38&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-38&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;38 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-39&quot; name=&quot;line-2-39&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-39&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;39 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-40&quot; name=&quot;line-2-40&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-40&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;40 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-41&quot; name=&quot;line-2-41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-41&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;41 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;c1&quot;&gt;# Remote server details&lt;/span&gt;
&lt;a id=&quot;line-2-42&quot; name=&quot;line-2-42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-42&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;42 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;host&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;10.151.139.17&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-43&quot; name=&quot;line-2-43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-43&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;43 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-44&quot; name=&quot;line-2-44&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-44&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;44 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;c1&quot;&gt;# Credentials&lt;/span&gt;
&lt;a id=&quot;line-2-45&quot; name=&quot;line-2-45&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-45&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;45 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;myuser&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-46&quot; name=&quot;line-2-46&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-46&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;46 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;NZaIhMezvK00Y&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-47&quot; name=&quot;line-2-47&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-47&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;47 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-48&quot; name=&quot;line-2-48&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-48&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;48 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;c1&quot;&gt;# Establish a connection to the remote host&lt;/span&gt;
&lt;a id=&quot;line-2-49&quot; name=&quot;line-2-49&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-49&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;49 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;winrm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;a id=&quot;line-2-50&quot; name=&quot;line-2-50&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-50&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;50 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-51&quot; name=&quot;line-2-51&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-51&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;51 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;c1&quot;&gt;# Dynamically select a function to run,&lt;/span&gt;
&lt;a id=&quot;line-2-52&quot; name=&quot;line-2-52&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-52&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;52 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;c1&quot;&gt;# either for commands or PowerShell&lt;/span&gt;
&lt;a id=&quot;line-2-53&quot; name=&quot;line-2-53&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-53&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;53 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run_cmd&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input_type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;cmd&amp;#39;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run_ps&lt;/span&gt;
&lt;a id=&quot;line-2-54&quot; name=&quot;line-2-54&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-54&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;54 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-55&quot; name=&quot;line-2-55&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-55&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;55 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;c1&quot;&gt;# Run the function with input data given&lt;/span&gt;
&lt;a id=&quot;line-2-56&quot; name=&quot;line-2-56&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-56&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;56 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input_data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-2-57&quot; name=&quot;line-2-57&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-57&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;57 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-58&quot; name=&quot;line-2-58&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-58&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;58 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;c1&quot;&gt;# Status code is always available&lt;/span&gt;
&lt;a id=&quot;line-2-59&quot; name=&quot;line-2-59&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-59&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;59 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status_code&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status_code&lt;/span&gt;
&lt;a id=&quot;line-2-60&quot; name=&quot;line-2-60&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-60&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;60 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std_out&lt;/span&gt;
&lt;a id=&quot;line-2-61&quot; name=&quot;line-2-61&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-61&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;61 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stderr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std_err&lt;/span&gt;
&lt;a id=&quot;line-2-62&quot; name=&quot;line-2-62&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-62&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;62 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-63&quot; name=&quot;line-2-63&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-63&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;63 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;Exception&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-64&quot; name=&quot;line-2-64&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-64&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;64 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exec_code&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;error&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-2-65&quot; name=&quot;line-2-65&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-65&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;65 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;details&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;format_exc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-2-66&quot; name=&quot;line-2-66&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-66&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;66 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-2-67&quot; name=&quot;line-2-67&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-67&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;67 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;c1&quot;&gt;# Everything went fine&lt;/span&gt;
&lt;a id=&quot;line-2-68&quot; name=&quot;line-2-68&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-68&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;68 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-2-69&quot; name=&quot;line-2-69&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-69&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;69 &quot;&gt;&lt;/span&gt;&lt;/a&gt;                &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exec_code&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;ok&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;rest-channel&quot;&gt;REST channel&lt;/h2&gt;
&lt;p&gt;Create a new
REST channel
in web-admin and mount service windows.remote.management on it. Make sure to set data format to JSON.&lt;/p&gt;
&lt;h2 id=&quot;usage&quot;&gt;Usage&lt;/h2&gt;
&lt;p&gt;Let us invoke the service from command line, using curl. For clarity, the output of commands below is limited to a few lines.&lt;/p&gt;
&lt;p&gt;First, we will run a regular command to get a directory listing of drive C:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;http://api:password@localhost:11223/windows&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-d&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;{&amp;quot;type&amp;quot;:&amp;quot;cmd&amp;quot;, &amp;quot;data&amp;quot;:&amp;quot;dir c:&amp;quot;}&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-4-1&quot; name=&quot;line-4-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;status_code&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-2&quot; name=&quot;line-4-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;exec_code&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;ok&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-4-3&quot; name=&quot;line-4-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;stdout&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot; Volume in drive C has no label.\r\n&lt;/span&gt;
&lt;a id=&quot;line-4-4&quot; name=&quot;line-4-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s2&quot;&gt; Volume Serial Number is 1F76-3AB6\r\n\r\n&lt;/span&gt;
&lt;a id=&quot;line-4-5&quot; name=&quot;line-4-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s2&quot;&gt; Directory of C:\\Users\\Administrator\r\n\r\n07/22/2019  11:53 PM    &amp;lt;DIR&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;What if we provide an invalid drive name?&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-5-1&quot; name=&quot;line-5-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;http://api:password@localhost:11223/windows&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-d&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;{&amp;quot;type&amp;quot;:&amp;quot;cmd&amp;quot;, &amp;quot;data&amp;quot;:&amp;quot;dir z:&amp;quot;}&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-6-1&quot; name=&quot;line-6-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;status_code&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-6-2&quot; name=&quot;line-6-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;exec_code&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;ok&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;a id=&quot;line-6-3&quot; name=&quot;line-6-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;quot;stderr&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;The system cannot find the path specified.\r\n&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, invoke a PowerShell script, which in this case is a single-line one to check connection from the remote Windows system to example.com, but it could be much more complex, there are no limitations:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-7-1&quot; name=&quot;line-7-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-7-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;curl&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;http://api:password@localhost:11223/windows&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-d&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;a id=&quot;line-7-2&quot; name=&quot;line-7-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-7-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;{&amp;quot;type&amp;quot;:&amp;quot;ps&amp;quot;, &amp;quot;data&amp;quot;:&amp;quot;Test-Connection example.com&amp;quot;}&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This time, both stdout and stderr are returned but because the overall status_code is 0, we know that the invocation was successful.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-8-1&quot; name=&quot;line-8-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;status_code&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;,
&lt;a id=&quot;line-8-2&quot; name=&quot;line-8-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;exec_code&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;ok&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-8-3&quot; name=&quot;line-8-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;stdout&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;WIN-A3I92B... example.com     93.184.216.34&amp;quot;&lt;/span&gt;,
&lt;a id=&quot;line-8-4&quot; name=&quot;line-8-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;stderr&amp;quot;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;#&amp;lt; CLIXML\r\n&amp;lt;Objs Version=\&amp;quot;1.1.0.1\&amp;quot; ...&amp;quot;&lt;/span&gt;,
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The service is just a starting point and there are a couple ways to extend it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Details of remote servers, including credentials, should be kept separately&lt;/li&gt;
&lt;li&gt;Permissions, including ACLs, can be added to allow or disallow access to particular commands to selected REST users only&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Yet, even in this simple form, it already shows how easy it is to connect to Windows servers and turn remote commands into REST APIs microservices.&lt;/p&gt;
&lt;p&gt;On top of it, REST is but one of many formats that
Zato
supports - one could just as well design workflows around AMQP, ZeroMQ, IBM MQ, FTP or other protocols in addition to REST with no changes to Python code required.&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Tue, 23 Jul 2019 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/windows-command-powershell-api.html</guid></item><item><title>MongoDB connections</title><link>https://zato.io/en/blog/mongodb.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/mongodb.html&quot;&gt;MongoDB connections&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2019-03-26, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;One of the newest additions in Zato 3.1 are MongoDB connections - learn in this article how to create and use them in your Python API services.&lt;/p&gt;
&lt;h2 id=&quot;dashboard&quot;&gt;Dashboard&lt;/h2&gt;
&lt;p&gt;As with most parts of Zato, the most straightforward way to create a new connection definition is to fill out a form in web-admin.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/mongodb/menu.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Note that MongoDB connections pack in a lot of options and, to keep the user interface as lightweight as possible, only the most commonly used ones are displayed in the default view and the rest needs to be toggled as needed.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/mongodb/create.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;pinging&quot;&gt;Pinging&lt;/h2&gt;
&lt;p&gt;To confirm that the connection is configured correctly, including credentials to connect with, you can ping it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/mongodb/ping.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;If everything is set up correctly, a response such as the one below will be returned.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/mongodb/ping-result.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;python-api&quot;&gt;Python API&lt;/h2&gt;
&lt;p&gt;A sample Python service may look like below - the client returned by self.out.mongodb is an instance of
&lt;a href=&quot;https://github.com/mongodb/mongo-python-driver&quot;&gt;pymongo.MongoClient&lt;/a&gt;
so anything that the PyMongo library can do is achievable from Zato too.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;__future__&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;absolute_import&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;division&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;print_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unicode_literals&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;c1&quot;&gt;# Zato&lt;/span&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;zato.server.service&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Obtain a MongoDB client&lt;/span&gt;
&lt;a id=&quot;line-0-12&quot; name=&quot;line-0-12&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-12&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;12 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mongodb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My MongoDB Connection&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;
&lt;a id=&quot;line-0-13&quot; name=&quot;line-0-13&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-13&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;13 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-14&quot; name=&quot;line-0-14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-14&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;14 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Select a database&lt;/span&gt;
&lt;a id=&quot;line-0-15&quot; name=&quot;line-0-15&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-15&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;15 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;db&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;test&lt;/span&gt;
&lt;a id=&quot;line-0-16&quot; name=&quot;line-0-16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-16&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;16 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-17&quot; name=&quot;line-0-17&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-17&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;17 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Insert a document&lt;/span&gt;
&lt;a id=&quot;line-0-18&quot; name=&quot;line-0-18&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-18&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;18 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;my_collection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;insert_one&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My object&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;My data&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;a id=&quot;line-0-19&quot; name=&quot;line-0-19&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-19&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;19 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-20&quot; name=&quot;line-0-20&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-20&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;20 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Get all documents already stored&lt;/span&gt;
&lt;a id=&quot;line-0-21&quot; name=&quot;line-0-21&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-21&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;21 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;my_collection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;a id=&quot;line-0-22&quot; name=&quot;line-0-22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-22&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;22 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-23&quot; name=&quot;line-0-23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-23&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;23 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Print them out to logs&lt;/span&gt;
&lt;a id=&quot;line-0-24&quot; name=&quot;line-0-24&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-24&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;24 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;a id=&quot;line-0-25&quot; name=&quot;line-0-25&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-25&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;25 &quot;&gt;&lt;/span&gt;&lt;/a&gt;            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Item: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, in log files:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;INFO&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Item:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;_id&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;ObjectId&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;5c99f8aa5ecb8221dcb3ff73&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;,&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My object&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My data&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;INFO&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Item:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;_id&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;ObjectId&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;5c99ffdf5ecb8221dcb3ff74&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;,&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My object&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My data&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;INFO&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;Item:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;_id&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;ObjectId&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;5c99ffe05ecb8221dcb3ff75&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;,&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My object&amp;#39;&lt;/span&gt;:&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;My data&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;This is everything that is required - once a connection is created it can be used immediately in Zato services.&lt;/p&gt;
&lt;p&gt;Because each connection is actually an instance of the official MongoDB Python client, there are no limits to what can be done with them - building MongoDB-based applications with Zato is now a fully supported possibility.&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Tue, 26 Mar 2019 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/mongodb.html</guid></item><item><title>HTTP Method and Accept headers</title><link>https://zato.io/en/blog/http-accept-method-headers.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/http-accept-method-headers.html&quot;&gt;HTTP Method and Accept headers&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2019-03-18, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;Zato 3.1 includes new means to manage access to REST services based on input Method and Accept headers in HTTP requests - here is how they can be employed in practice.&lt;/p&gt;
&lt;h2 id=&quot;a-bit-of-background&quot;&gt;A bit of background&lt;/h2&gt;
&lt;p&gt;Prior to Zato 3.1, one could always build a REST API reacting to individual HTTP verbs by implementing &lt;a href=&quot;https://zato.io/en/docs/4.1/dev/index.html&quot;&gt;handle_VERB&lt;/a&gt; methods in services, such as:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;MyService&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle_GET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-4&quot; name=&quot;line-0-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Reacts to GET requests&lt;/span&gt;
&lt;a id=&quot;line-0-5&quot; name=&quot;line-0-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;a id=&quot;line-0-6&quot; name=&quot;line-0-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-7&quot; name=&quot;line-0-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;handle_POST&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-0-8&quot; name=&quot;line-0-8&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-8&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 8 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;c1&quot;&gt;# Reacts to POST requests&lt;/span&gt;
&lt;a id=&quot;line-0-9&quot; name=&quot;line-0-9&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-9&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot; 9 &quot;&gt;&lt;/span&gt;&lt;/a&gt;        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;a id=&quot;line-0-10&quot; name=&quot;line-0-10&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-10&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;10 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-0-11&quot; name=&quot;line-0-11&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-11&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;11 &quot;&gt;&lt;/span&gt;&lt;/a&gt;    &lt;span class=&quot;c1&quot;&gt;# Any other handle_VERB method will be used accordingly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This works and will continue to work as expected in all future Zato versions.&lt;/p&gt;
&lt;p&gt;However, one aspect of it is that, if one uses &lt;a href=&quot;https://zato.io/en/docs/4.1/dev/index.html&quot;&gt;SimpleIO&lt;/a&gt;, keeping all handler methods in the same service means that all of them share the same SIO definition which is not always desirable - for instance, input to POST may be unrelated to input that DELETE receives.&lt;/p&gt;
&lt;h2 id=&quot;rest-channel-url-paths&quot;&gt;REST channel URL paths&lt;/h2&gt;
&lt;p&gt;In Zato 3.1 and newer, it is possible to create REST channels that have the same URL path but different services mounted on each channel, separately for each HTTP verb requires.&lt;/p&gt;
&lt;p&gt;That is, whereas previously it was a single service with multiple handle_VERB methods, now it can be a set of services, each reacting to a different HTTP verb and all of them mounted on the same URL path.&lt;/p&gt;
&lt;p&gt;In a way, this was supported previously but, if handle_VERB methods were not used, URL paths had to be distinct, e.g.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;GET /api/user
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;DELETE /api/user/delete
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;POST /api/user/create
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In 3.1+, this can be simplified to:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;GET /api/user
&lt;a id=&quot;line-2-2&quot; name=&quot;line-2-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;DELETE /api/user
&lt;a id=&quot;line-2-3&quot; name=&quot;line-2-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;POST /api/user
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, each of the combination of verb + path may be unique for a REST channel while previously each channel needed to have its own URL path.&lt;/p&gt;
&lt;p&gt;Moreover, because each channel may have its own separate service, it also means that each service may have its own SimpleIO definition and that the service becomes less tied to REST.&lt;/p&gt;
&lt;h2 id=&quot;http-accept-headers&quot;&gt;HTTP Accept headers&lt;/h2&gt;
&lt;p&gt;This is a completely new feature in 3.1 which lets one have distinct REST channels depending on the requests&#x27;s Accept headers.&lt;/p&gt;
&lt;p&gt;For instance, let&#x27;s say that we would like to process incoming invoices under &lt;strong&gt;POST /api/invoice&lt;/strong&gt; but we would like to have two services reacting to the same endpoint, one for JSON and now for PDF invoices.&lt;/p&gt;
&lt;p&gt;This can be achieved by configuring HTTP Accept headers in their channels, as below - note that the method and URL path are the same in both cases yet HTTP Accept and services are different because each service reacts to a different value of HTTP Accept:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.1-rest-headers/json.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.1-rest-headers/pdf.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;http-accept-header-patterns&quot;&gt;HTTP Accept header patterns&lt;/h2&gt;
&lt;p&gt;We can go one better and take advantage of Accept header patterns - with an asterisk meaning any character - this will configure the channel to process requests matching any value that fits in with the pattern, e.g. text/&lt;em&gt; will mean text/csv, text/xml or anything that starts with &lt;/em&gt;&lt;em&gt;text/&lt;/em&gt;*.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/3.1-rest-headers/text.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;However, seeing as it can be a number of input MIME types, at this point we may need to know what the actual value was - this can be extracted from the WSGI environment via &lt;strong&gt;self.wsgi_environ&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;Zato 3.1 saw improvements and backward-compatible changes to how REST channels can be built.&lt;/p&gt;
&lt;p&gt;It will now support more use-cases, such as single URL path channels with different HTTP verbs and independent SimpleIO definitions or HTTP Accept headers different for each channel.&lt;/p&gt;
&lt;p&gt;In turn, this lets one build REST APIs that are more flexible and elastic in their design to react to different input criteria.&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 18 Mar 2019 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/http-accept-method-headers.html</guid></item><item><title>Two-factor authentication in Zato Dashboard</title><link>https://zato.io/en/blog/web-admin-totp.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/web-admin-totp.html&quot;&gt;Two-factor authentication in Zato Dashboard&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2019-02-25, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;This post provides steps needed to enable and make use of
&lt;a href=&quot;https://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm&quot;&gt;TOTP&lt;/a&gt;
two-factor authentication in the Zato Dashboard - the method is compatible with the most popular apps such as
&lt;a href=&quot;https://en.wikipedia.org/wiki/Google_Authenticator&quot;&gt;Google Authenticator&lt;/a&gt;,
&lt;a href=&quot;https://authy.com/&quot;&gt;Authy&lt;/a&gt;
or
&lt;a href=&quot;https://en.wikipedia.org/wiki/FreeOTP&quot;&gt;FreeOTP&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The functionality is slated for release in Zato 3.1 and, currently, it is available via Zato &lt;a href=&quot;https://zato.io/en/docs/4.1/admin/guide/install/index.html&quot;&gt;source installation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;modifying-web-adminconf&quot;&gt;Modifying web-admin.conf&lt;/h2&gt;
&lt;p&gt;We start by letting web-admin know that it is to require TOTP security codes from users. This is a global flag for all users.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://zato.io/en/docs/4.1&quot;&gt;Stop&lt;/a&gt; web-admin&lt;/li&gt;
&lt;li&gt;Open web-admin.conf file&lt;/li&gt;
&lt;li&gt;Set &lt;strong&gt;&quot;is_totp_enabled&quot;&lt;/strong&gt; to &lt;strong&gt;true&lt;/strong&gt; (note that it is lower-case, without quotes)&lt;/li&gt;
&lt;li&gt;Save the file&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://zato.io/en/docs/4.1&quot;&gt;Start&lt;/a&gt; web-admin back&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;generating-the-initial-totp-key&quot;&gt;Generating the initial TOTP key&lt;/h2&gt;
&lt;p&gt;Now that the two-factor authentication with TOTP is enabled, we need the initial TOTP key for each user, otherwise they will not be able to log in at all.&lt;/p&gt;
&lt;p&gt;Command line can be used to reset such keys for any user - in this case the process of resetting a key will amount to setting the initial one, as in the sample below that resets the key for a web-admin user called admin:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;zato&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;reset-totp-key&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;/path/to/web-admin&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;admin
&lt;a id=&quot;line-0-2&quot; name=&quot;line-0-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;IDNSLY27ESRPWUI5
&lt;a id=&quot;line-0-3&quot; name=&quot;line-0-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;$
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Such a key can now be transferred to an app of choice to generate time-based security codes that web-admin will require.&lt;/p&gt;
&lt;h2 id=&quot;logging-in&quot;&gt;Logging in&lt;/h2&gt;
&lt;p&gt;The app that the key was saved to will now present security codes needed for logging in.&lt;/p&gt;
&lt;p&gt;Each such key is valid for at most 30 seconds - in this way a potential attacker will have to take two factors into account, one is your password and the other is getting access to your app and the associated TOTP secret key. Replay attacks are not particularly feasible against such codes because they will change frequently.&lt;/p&gt;
&lt;p&gt;As always, even without TOTP, you should also make sure you rate-limit login attempts to web-admin by configuring your frontend load-balancer, or proxy, accordingly. With TOTP, since the codes are relatively short, it would be possible for an attacker to check them all very quickly so this kind of rate-limiting is of double importance.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/web-admin-totp/login.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;changing-your-totp-key-in-web-admin&quot;&gt;Changing your TOTP key in web-admin&lt;/h2&gt;
&lt;p&gt;Having logged in, it is possible to generate secret keys directly in web-admin too. This option will also output QR codes to transfer the code to mobile devices simply by scanning the resulting QR code.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/web-admin-totp/settings.png&quot;/&gt;&lt;/p&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;That is all - everything is set up and two-factor authentication will be enforced each time anyone logs in. TOTP is easy to configure and use so it is recommended to enable it as an additional security layer.&lt;/p&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 25 Feb 2019 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/web-admin-totp.html</guid></item><item><title>Zato: A successful Python 3 migration story</title><link>https://zato.io/en/blog/python-3-migration-success-story.html</link><description>
&lt;h1 class=&quot;insights-header&quot;&gt;
  &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/python-3-migration-success-story.html&quot;&gt;Zato: A successful Python 3 migration story&lt;/a&gt;
&lt;/h1&gt;
&lt;div class=&quot;article-meta&quot;&gt;
  2019-02-11, by Dariusz Suchojad
&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/authors/dsuch.webp&quot;
    alt=&quot;&quot; width=&quot;35&quot;
    class=&quot;insights-author&quot;/&gt;
&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://upcdn.io/kW15bqq/raw/root/static/blog/images/python3/python-logo.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Now that Python 3 support is available as a preview for developers,
this post summarizes the effort that went into making sure that Zato works smoothly using both Python 2.7 and 3.x.&lt;/p&gt;
&lt;p&gt;In fact,  the works required were remarkably straightforward and trouble-free and the article discusses the thought process behind it,
some of the techniques applied or tools used.&lt;/p&gt;
&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;
&lt;p&gt;Zato is [an enterprise API integration platform and backend application server]/en/docs/4.1/intro/esb-soa.html).
We support a couple dozen of protocols, data formats, several sorts of IPC and other means to exchange messages across applications.&lt;/p&gt;
&lt;p&gt;In other words, on the lowest level, passing bytes around,
transforming, extracting, changing, collecting, manipulating, converting, encoding, decoding and comparing them, including
support for all kinds of natural languages from around the world, is what Zato is about at its core
when it is considered from the perspective of the programming language it is implemented in.&lt;/p&gt;
&lt;p&gt;The codebase is around 130,000 lines of code, out of which Python and Cython are 60,000 lines. This is not everything, though, because we also have 170+
external dependencies that need to work with Python 2.7 and 3.x.&lt;/p&gt;
&lt;p&gt;The works took two people a total of 80 hours. They were spread over a longer calendar time, except for the final sprint that required
more attention for several days in a row.&lt;/p&gt;
&lt;h2 id=&quot;preparations&quot;&gt;Preparations&lt;/h2&gt;
&lt;p&gt;Since the very beginning, it was clear that Python 3 will have to be supported at one day so the number one thing that each and every Python module
has always had is this preamble:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-0-1&quot; name=&quot;line-0-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-0-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nn&quot;&gt;__future__&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;absolute_import&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;division&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;print_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unicode_literals&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is what every Python file contains and it easily saved 90% of any potential work required to support Python 3 because, among
other less demanding things, it enforced a separation, though still not as strict as in Python 3, between byte and Unicode objects.
The separation is a good thing and the more one works with Python 3 the clearer it becomes.&lt;/p&gt;
&lt;p&gt;In Python 2, it was sometimes possible to mix the two. Imagine that there is a Python-derived language where JSON dicts and Python dicts
can be sometimes used interchangeably.&lt;/p&gt;
&lt;p&gt;For instance, this is a JSON object: {&quot;key1&quot;: &quot;value1&quot;} and it so happens that it is also a valid Python dict so in this hypothetical
language, this would work:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-1-1&quot; name=&quot;line-1-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;json&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;{&amp;quot;key1&amp;quot;: &amp;quot;value1&amp;quot;}&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-1-2&quot; name=&quot;line-1-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;python&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;key2&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;value2&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;a id=&quot;line-1-3&quot; name=&quot;line-1-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;a id=&quot;line-1-4&quot; name=&quot;line-1-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-1-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;json&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;python&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now the result is this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-2-1&quot; name=&quot;line-2-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-2-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;key1&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;value1&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;key2&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;value2&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or wait, perhaps it should be this?&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-3-1&quot; name=&quot;line-3-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-3-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;{&amp;quot;key1&amp;quot;: &amp;quot;value1&amp;quot;, &amp;quot;key2&amp;quot;: &amp;quot;value2&amp;quot;}&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is the central thing - they are distinct types and they should not be mixed merely because they may be related or seem similar.&lt;/p&gt;
&lt;p&gt;Conceptually, just like upon receiving a JSON request from the network a Python application will decode it into a canonical representation,
such as a dict, list or another Python object, the same should happen to other bytes, including ones that happen to represent text or similar information. In this case, the canonical format is called Unicode, and that is the whole point of employing it in one&#x27;s application.&lt;/p&gt;
&lt;p&gt;All of this was clear from the outset and the &lt;code&gt;from __future__&lt;/code&gt; statements helped in its execution, even if theoretically one could have been still able to mix bytes and Unicode - it was simply a matter of using the correct canonical format in a given context, i.e. a case of making sure the architecture was clean.&lt;/p&gt;
&lt;p&gt;This particular &lt;code&gt;__future__&lt;/code&gt; statement was &lt;a href=&quot;https://docs.python.org/release/2.6/whatsnew/2.6.html#pep-3112-byte-literals&quot;&gt;first announced&lt;/a&gt; in 2008 so there was plenty of time to prepare to it.&lt;/p&gt;
&lt;p&gt;As part of the preparations, it is good to read a book about Unicode. Not just a &#x27;Unicode for overburdened developers&#x27; kind of an article but an actual book that will let one truly appreciate the standard&#x27;s breadth and scope. While reading it, do not resist the temptation to learn at least basics of two or more natural languages that you never knew about before. It will only help you develop into a better person and this is not a joke.&lt;/p&gt;
&lt;p&gt;While programming with bytes and Unicode, it is convenient simply to forget about whether it is a &#x27;str&#x27;, &#x27;bytes&#x27; or &#x27;unicode&#x27; object - it is easier simply to think about bytes and text. There are bytes that can mean anything and there is text whose native, canonical form is Unicode. This is not always 100% accurate
because Unicode can represent marvelous gems such as &lt;a href=&quot;https://en.wikipedia.org/wiki/Byzantine_Musical_Symbols&quot;&gt;Byzantine musical&lt;/a&gt; &lt;a href=&quot;https://orthodoxwiki.org/Byzantine_Notation&quot;&gt;notation&lt;/a&gt; and more but if a given application&#x27;s scope is mostly constrained to text then this will work - there are bytes and there is text.&lt;/p&gt;
&lt;p&gt;This is all fine with our own code but there are still the external libraries that Zato uses and some of them will want bytes, not text, or the other way around, in seemingly similar situations. There can be even cases like a library expecting for protocol header keys to be text and protocol header values to be bytes for rather unclear reasons. Simply accept it as a fact of life and move on with your works, there is no need to pause even for a moment to think about it.&lt;/p&gt;
&lt;h2 id=&quot;side-projects&quot;&gt;Side projects&lt;/h2&gt;
&lt;p&gt;It was good to try out Python 3 first in a few new, smaller side-projects, GUI or command-line tools that are not part of the core yet they are important in the overall picture. The most important part of it was that creating a Python 3 application from scratch was in no way different than in Python 2, this served as a gentle introduction
to Python 3-specific constructs and this knowledge was easily transferred later on to the main porting job.&lt;/p&gt;
&lt;h2 id=&quot;dependencies&quot;&gt;Dependencies&lt;/h2&gt;
&lt;p&gt;Out of a total of 170+ dependencies, around 10 were not Python 3-compatible. All of them had not been updated in eight, twelve or more years. At this point,
it is safe to assume that if there is a dependency that was last updated in 2009 and it has no Python 3 support then it never will.&lt;/p&gt;
&lt;p&gt;What to do next depended on a particular case, each of them was some kind of a convenience library - sometimes they had to be dropped and sometimes forked. Most complex changes required in a fork were on the level of updating &#x27;print&#x27; to &#x27;print()&#x27; or doing away with complex installation setups that predated contemporary pip-based configuration options.&lt;/p&gt;
&lt;p&gt;Other than that, there were no issues with dependencies, all of them were ready for Python 3.&lt;/p&gt;
&lt;h2 id=&quot;idioms-and-imports&quot;&gt;Idioms and imports&lt;/h2&gt;
&lt;p&gt;Most of the reference information needed to make use of Python 2 and 3 was available via the &lt;a href=&quot;https://python-future.org/compatible_idioms.html&quot;&gt;python-future&lt;/a&gt; project which itself is a great assistance. Installing this library, along with its dependencies, sufficed for 99% of cases. There were some lesser requirements that were incorporated into a Zato-specific submodule directly, e.g. sys.maxint is at times useful as a loop terminator but ints in Python 3 have no limits so an equivalent had to be added to our own code.&lt;/p&gt;
&lt;p&gt;Note that the page above does not show all the idioms and some changes were not always immediately obvious, like modifications to &lt;code&gt;__slots__&lt;/code&gt;, or the way metaclasses can be declared, but there were no really impossible cases, just different things to use, either built in to Python 3 or available via &lt;a href=&quot;https://python-future.org/&quot;&gt;future&lt;/a&gt; or &lt;a href=&quot;https://pypi.org/project/six/&quot;&gt;six&lt;/a&gt; libraries.&lt;/p&gt;
&lt;p&gt;A nice thing is that one is not required to immediately change all the imports in one go - they can be changed in smaller increments, e.g. &#x27;basestring&#x27; is still available in the form of &#x27;from past.builtins import basestring&#x27;.&lt;/p&gt;
&lt;h2 id=&quot;testing&quot;&gt;Testing&lt;/h2&gt;
&lt;p&gt;A really important aspect during the migration was the ability to test sub-components of an application in isolation. This does not only include unittests, which may be too low-level, but also things such as starting only selected parts of Zato without a requirement to boot up whole servers which in turn meant each change could be tested within one second rather than ten. To a degree, this was an unexpected but really useful test of how modular our design was.&lt;/p&gt;
&lt;p&gt;Intellectually, this was certainly the most challenging part because it required maintaining and traversing several trains of thought at once, sometimes for several days on end. This, in turn, means that it really is not a job for late afternoons only and it cannot be an afterthought, things can simply get complex very quickly.&lt;/p&gt;
&lt;h2 id=&quot;string-formatting&quot;&gt;String formatting&lt;/h2&gt;
&lt;p&gt;There is one thing that was not expected - the way str.format works with bytes and text.&lt;/p&gt;
&lt;p&gt;For instance, this will fail in Python 3:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-4-1&quot; name=&quot;line-4-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;aaa&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;bbb&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-4-2&quot; name=&quot;line-4-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;Traceback&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;most&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recent&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;call&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-4-3&quot; name=&quot;line-4-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;  &lt;span class=&quot;n&quot;&gt;File&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;stdin&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;a id=&quot;line-4-4&quot; name=&quot;line-4-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;ne&quot;&gt;TypeError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Can&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;t convert &amp;#39;&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;bytes&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39; object to str implicitly&lt;/span&gt;
&lt;a id=&quot;line-4-5&quot; name=&quot;line-4-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-4-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Just for reference, in Python 2 it does not fail:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-5-1&quot; name=&quot;line-5-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;aaa&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;bbb&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-5-2&quot; name=&quot;line-5-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;aaabbb&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-5-3&quot; name=&quot;line-5-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-5-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Still under Python 2, let&#x27;s use string formatting:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-6-1&quot; name=&quot;line-6-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-6-2&quot; name=&quot;line-6-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;aaa&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;bbb&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-6-3&quot; name=&quot;line-6-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;aaa.bbb&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-6-4&quot; name=&quot;line-6-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-6-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In Python 3, this is the result:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-7-1&quot; name=&quot;line-7-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-7-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-7-2&quot; name=&quot;line-7-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-7-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;aaa&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;bbb&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-7-3&quot; name=&quot;line-7-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-7-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;aaa.b&amp;#39;bbb&amp;#39;&amp;quot;&lt;/span&gt;
&lt;a id=&quot;line-7-4&quot; name=&quot;line-7-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-7-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the context of a Python 3 migration, it would have been probably more in line with other changes to the language if this had been special-cased to reject such constructs altogether.&lt;/p&gt;
&lt;p&gt;Otherwise, it initially led to rather inexplicable error messages because the code that produces such string constants may be completely unaware of where they are used further on. But witnessed once or twice, it was apparent later on what the root cause was and this could be easily dealt with.&lt;/p&gt;
&lt;h2 id=&quot;things-that-are-missed&quot;&gt;Things that are missed&lt;/h2&gt;
&lt;p&gt;One small, yet convenient, feature of Python 2 was the availability of some of the common codecs directly in string objects, e.g.:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-8-1&quot; name=&quot;line-8-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;abc&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;hex&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-8-2&quot; name=&quot;line-8-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;616263&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-8-3&quot; name=&quot;line-8-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;abc&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;base64&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-8-4&quot; name=&quot;line-8-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;YWJj&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-8-5&quot; name=&quot;line-8-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;ελληνική&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;idna&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-8-6&quot; name=&quot;line-8-6&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-6&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;6 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;xn--jxangifdar&amp;#39;&lt;/span&gt;
&lt;a id=&quot;line-8-7&quot; name=&quot;line-8-7&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-8-7&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;7 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will not work as-is in Python 3:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;a id=&quot;line-9-1&quot; name=&quot;line-9-1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-9-1&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;1 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;sa&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;abc&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;hex&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;a id=&quot;line-9-2&quot; name=&quot;line-9-2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-9-2&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;2 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;n&quot;&gt;Traceback&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;most&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recent&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;call&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
&lt;a id=&quot;line-9-3&quot; name=&quot;line-9-3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-9-3&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;3 &quot;&gt;&lt;/span&gt;&lt;/a&gt;  &lt;span class=&quot;n&quot;&gt;File&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;stdin&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;a id=&quot;line-9-4&quot; name=&quot;line-9-4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-9-4&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;4 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;ne&quot;&gt;LookupError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;hex&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;encoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;codecs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;handle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arbitrary&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;codecs&lt;/span&gt;
&lt;a id=&quot;line-9-5&quot; name=&quot;line-9-5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;#line-9-5&quot;&gt;&lt;span class=&quot;linenos&quot; data-linenos=&quot;5 &quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Naturally, the functionality as such is still available in Python 3, just not via the same means.&lt;/p&gt;
&lt;h2 id=&quot;python-27&quot;&gt;Python 2.7&lt;/h2&gt;
&lt;p&gt;On the server side, Python 2.7 will be around for many years. After all, this is a great language that let thousands and millions of people complete amazing projects and most of enterprise applications do not get rewritten solely because one of the technical components (here, Python) changes in a way that is partly incompatible with previous versions.&lt;/p&gt;
&lt;p&gt;Both RHEL and Ubuntu ship with Python 2.7 and both of them have long-term support well into the 2020s so the language as such will not go away. Yet, piece by piece, all the applications will be changed, modified, modularized or rewritten and gradually Python 2.7&#x27;s usage will diminish.&lt;/p&gt;
&lt;p&gt;In Zato, Python 2.7 will be supported for as long as it is feasible and one of the current migration&#x27;s explicit goals was to make sure that existing user Zato environments based on Python 2.7 will continue to work out-of-the-box with Python 3 so there is no difference which Python version one chooses - both are supported and can be used.&lt;/p&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;An extraordinary aspect of the migration is that it was so unextraordinary. There were no really hard-won battles, no true gotchas and no unlooked-for hurdles. This can be likely attributed to the facts that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Core Python developers offered information what to expect during such a job&lt;/li&gt;
&lt;li&gt;Unicode was not treated as an afterthought&lt;/li&gt;
&lt;li&gt;Zato reuses common libraries that are all ported to Python 3 already&lt;/li&gt;
&lt;li&gt;Internet offers guides, hints and other pieces of information about what to do&lt;/li&gt;
&lt;li&gt;It was easy to test Zato components in isolation&lt;/li&gt;
&lt;li&gt;Time was explicitly put aside for the most difficult parts without having to share it with other tasks&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;nav-title footer&quot;&gt;
    &lt;a class=&quot;rounded nav-title&quot; href=&quot;https://zato.io/en/blog/&quot;&gt;More blog posts&lt;/a&gt;&lt;span class=&quot;arrow-footer&quot;&gt;➤&lt;/span&gt;
&lt;/div&gt;
</description><pubDate>Mon, 11 Feb 2019 03:00:00 +0000</pubDate><guid>https://zato.io/en/blog/python-3-migration-success-story.html</guid></item></channel></rss>