<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Authenticating programmatically when using curl]]></title><description><![CDATA[<p dir="auto">I'm trying to connect to the API programmatically using curl calls from our server. I'm sending a call to /rest/v1/login/[username] to log in, followed by a call to /rest/v1/realtime/by-xid/[xid] to get the data value.</p>
<p dir="auto">The login call works;  it returns a response code of 200 and good data about the account.  The second call, however, fails with 401 response (unauthorized).</p>
<p dir="auto">I also tried setting the USERPWD curl option on the second call, which lets you send user name and password as part of the call, but got the same result (401, unauthorized).</p>
<p dir="auto">How do you log in when making API calls using curl?</p>
<p dir="auto">Many thanks!</p>
]]></description><link>https://forum.mango-os.com/topic/2431/authenticating-programmatically-when-using-curl</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 15:31:09 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/2431.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 Aug 2016 18:19:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Authenticating programmatically when using curl on Wed, 19 Jan 2022 08:33:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sasa" aria-label="Profile: sasa">@<bdi>sasa</bdi></a></p>
<p dir="auto">The link mentioned is not valid anymore</p>
]]></description><link>https://forum.mango-os.com/post/27277</link><guid isPermaLink="true">https://forum.mango-os.com/post/27277</guid><dc:creator><![CDATA[NinoK]]></dc:creator><pubDate>Wed, 19 Jan 2022 08:33:29 GMT</pubDate></item><item><title><![CDATA[Reply to Authenticating programmatically when using curl on Thu, 03 Nov 2016 16:47:57 GMT]]></title><description><![CDATA[<p dir="auto">Hi guys,</p>
<p dir="auto">I will get in hear instead of creating a new topic.</p>
<p dir="auto">A third party system get´s some datapoints over RESTful API (swagger). They got the Java-Client-Example from here <a href="http://help.infiniteautomation.com/support/solutions/articles/14000023292-mango-rest-api-authentication" rel="nofollow ugc">http://help.infiniteautomation.com/support/solutions/articles/14000023292-mango-rest-api-authentication</a><br />
but had no success to develop something good. The theory of authentication and the cookie-handling are clear.</p>
<p dir="auto">The problem is to realize the Java-Client without more informations about libraries,..... Are their some librarieres that we missed?</p>
<p dir="auto">Regards<br />
Sasa</p>
]]></description><link>https://forum.mango-os.com/post/13125</link><guid isPermaLink="true">https://forum.mango-os.com/post/13125</guid><dc:creator><![CDATA[sasa]]></dc:creator><pubDate>Thu, 03 Nov 2016 16:47:57 GMT</pubDate></item><item><title><![CDATA[Reply to Authenticating programmatically when using curl on Wed, 31 Aug 2016 22:38:42 GMT]]></title><description><![CDATA[<p dir="auto">Glad to hear it. Yeah, I realized I was mistaken when I posted that (hence the edits, always good to get the information here than from the notifying emails). I had glanced at a test I have doing some API calls over nc and seen it wrong. I will try to get that document updated tomorrow. Sorry for the confusion.</p>
]]></description><link>https://forum.mango-os.com/post/12529</link><guid isPermaLink="true">https://forum.mango-os.com/post/12529</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Wed, 31 Aug 2016 22:38:42 GMT</pubDate></item><item><title><![CDATA[Reply to Authenticating programmatically when using curl on Wed, 31 Aug 2016 22:23:47 GMT]]></title><description><![CDATA[<p dir="auto">Thanks, Phil!</p>
<p dir="auto">The first option (2 headers) didn't work for me, but the second worked like a charm.</p>
<p dir="auto">The single header format that worked:</p>
<p dir="auto">Cookie: XSRF-TOKEN=[value];MANGO[port]=[value]</p>
<p dir="auto">The two headers format that didn't:</p>
<p dir="auto">X-XSRF-TOKEN: [value]<br />
MANGO[port]: [value]</p>
<p dir="auto">If my syntax in the latter option is wrong, let me know ... but the single cookie option works quite nicely.</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.mango-os.com/post/12528</link><guid isPermaLink="true">https://forum.mango-os.com/post/12528</guid><dc:creator><![CDATA[jono]]></dc:creator><pubDate>Wed, 31 Aug 2016 22:23:47 GMT</pubDate></item><item><title><![CDATA[Reply to Authenticating programmatically when using curl on Wed, 31 Aug 2016 15:36:59 GMT]]></title><description><![CDATA[<p dir="auto">Hi Jono,</p>
<p dir="auto">It looks like the help document may be incomplete! My mistake, I will update that document.</p>
<p dir="auto">You should send the X-XSRF-TOKEN and session cookie in the Cookie header as:<br />
Cookie: XSRF-TOKEN=[value]; MANGO[port]=[value]</p>
<p dir="auto">Sorry for the mix-up</p>
]]></description><link>https://forum.mango-os.com/post/12522</link><guid isPermaLink="true">https://forum.mango-os.com/post/12522</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Wed, 31 Aug 2016 15:36:59 GMT</pubDate></item><item><title><![CDATA[Reply to Authenticating programmatically when using curl on Tue, 30 Aug 2016 21:08:21 GMT]]></title><description><![CDATA[<p dir="auto">Hi, Phil,</p>
<p dir="auto">Many thanks!  I'm getting the token, but I'm now getting a 403 return from /rest/v1/realtime/by-xid/[xid] call.  I'm setting headers as follows (this is in PHP):</p>
<pre><code>           // Initialize curl options
	$this-&gt;_curl_options = array(
		CURLOPT_RETURNTRANSFER =&gt; TRUE,
		CURLOPT_HEADER =&gt; TRUE,
		CURLOPT_VERBOSE =&gt; TRUE,
		CURLOPT_TIMEOUT =&gt; $this-&gt;_curl_timeout,
	);

	$headers = array(
		'Accept: application/json',
		'Accept-Encoding: gzip',
		'Accept-Language: en-US,en;q=0.5',
		'Connection: keep-alive',
		'Cache-Control: no-cache',
		"X-XSRF-TOKEN: {$this-&gt;_token}",
	);		
	$this-&gt;_curl_options[CURLOPT_HTTPHEADER] = $headers;
	$this-&gt;_curl_options[CURLOPT_USERAGENT] = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0";
	$this-&gt;_call_api();
</code></pre>
<p dir="auto">Then, the _call-&gt;api() method makes the call:</p>
<pre><code>	$this-&gt;_curl_options[CURLOPT_URL] = $this-&gt;call_string;
	$curl = curl_init();
	curl_setopt_array($curl, $this-&gt;_curl_options);
	
	// Make the call
	$response = curl_exec($curl);
	curl_close($curl);
</code></pre>
<p dir="auto">Is this the right way to send the authentication token on the second call?</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.mango-os.com/post/12518</link><guid isPermaLink="true">https://forum.mango-os.com/post/12518</guid><dc:creator><![CDATA[jono]]></dc:creator><pubDate>Tue, 30 Aug 2016 21:08:21 GMT</pubDate></item><item><title><![CDATA[Reply to Authenticating programmatically when using curl on Tue, 30 Aug 2016 18:40:22 GMT]]></title><description><![CDATA[<p dir="auto">Hi Jono,</p>
<p dir="auto">I bet you're looking for this information: <a href="http://help.infiniteautomation.com/support/solutions/articles/14000023292-mango-rest-api-authentication" rel="nofollow ugc">http://help.infiniteautomation.com/support/solutions/articles/14000023292-mango-rest-api-authentication</a></p>
<p dir="auto">tldr: you need to supply the token you got when authenticating in subsequent headers</p>
]]></description><link>https://forum.mango-os.com/post/12512</link><guid isPermaLink="true">https://forum.mango-os.com/post/12512</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Tue, 30 Aug 2016 18:40:22 GMT</pubDate></item></channel></rss>