# Ignition and (Docker) Portainer API. (HTTP queries)

**URL:** <https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725>\
**Category:** Ignition\
**Created:** [July 15, 2020, 1:35pm UTC](https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725 "2020-07-15T13:35:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 15, 2020, 1:35pm UTC](https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725/1 "2020-07-15T13:35:51Z")

</div>

Has anyone had any luck with Ignition and portainer API?

I have been trying to connect to the Portainer API, with no luck. I have never used HTTP bindings before(which might be my real problem here).

The procedure for the portainer API should be quite simple:  
[https://gist.github.com/deviantony/77026d402366b4b43fa5918d41bc42f8](https://gist.github.com/deviantony/77026d402366b4b43fa5918d41bc42f8)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 15, 2020, 3:21pm UTC](https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725/2 "2020-07-15T15:21:15Z")

</div>

Http bindings aren’t going to work well for this purpose - they’re not very good at authentication right now.  
I’d recommend [`system.net.httpClient()`](https://docs.inductiveautomation.com/display/DOC80/system.net.httpClient). You could wrap things in a class to make accessing the API a little friendlier:

```auto
class PortainerClient(object):
	def __init__ (self, baseUrl, username, password, **kwargs):
		self.baseUrl = baseUrl
		self.client = system.net.httpClient(**kwargs)
		response = self.client.post(baseUrl + "auth", data={"Username": username, "Password": password})
		self.token = response.json["jwt"]
		
	def call(self, endpoint, method="GET", **kwargs):
		headers = kwargs.get("headers", {})
		headers["Authorization"] = "Bearer {}".format(self.token)
	
		response = self.client.request(self.baseUrl + endpoint, method, headers=headers, **kwargs)
		return response.json
		
client = PortainerClient("https://docker.ia.local/api/", "admin", "password", bypass_cert_validation=True)

print client.call("endpoints/1/docker/containers/json")

```

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 16, 2020, 8:53pm UTC](https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725/3 "2020-07-16T20:53:50Z")

</div>

That look very neat, I cant wait to thinker with that. Thanks alot @paul-griffith !

I will post again when tested 🙂

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 18, 2020, 7:14pm UTC](https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725/4 "2020-07-18T19:14:54Z")

</div>

Works great!

How would you use this in perspective to show live status of containers(?):

I am thinking a gateway event timer script. Then write to a dataset tag. But then the script would init every time, which is unnecessary since the token is valid for 8 hours?

Parallel to the status being updated. If I make buttons in perspective to start/stop containers. Should I run this script directly, or use the already obtained token. In the latter case I must store the token somewhere; normal tag database, or session custom props?

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 19, 2020, 11:08am UTC](https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725/5 "2020-07-19T11:08:55Z")

</div>

I used a responsive view and made a (crude) interface:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/2/92a4775b9c07ba918a2eb39b5582bc8a1ac9689b.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/5/35d0c036de3a08a7c6652c30325fc30dac5caebc.png)

Would be nice to get those state into the tag database for alarming though.

Maybe I will also add an interface for creating containers, maybe based on git repos.

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 22, 2020, 7:26pm UTC](https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725/6 "2020-07-22T19:26:53Z")

</div>

@paul-griffith, do you have any idea why this wont work?

```auto
class PortainerClient(object):
	def __init__ (self, baseUrl, username, password, **kwargs):
		self.baseUrl = baseUrl
		self.client = system.net.httpClient(**kwargs)
		response = self.client.post(baseUrl + "auth", data={"Username": username, "Password": password})
		self.token = response.json["jwt"]
		
	def call(self, endpoint, method="GET", **kwargs):
		headers = kwargs.get("headers", {})
		headers["Authorization"] = "Bearer {}".format(self.token)
	
		response = self.client.request(self.baseUrl + endpoint, method, headers=headers, **kwargs)
		return response.json
		
	def post(self, endpoint, **kwargs):
		headers = kwargs.get("headers", {})
		headers["Authorization"] = "Bearer {}".format(self.token)
		response=self.client.post(self.baseUrl + endpoint, headers=headers, **kwargs)
		print response
		return response.json

client = PortainerClient("http://MYIP:9000/api/", "admin", "password", bypass_cert_validation=True)

#create an exec instance
endpoint="endpoints/1/docker/containers/ba376d6b670b8aa946d1a26f28c781349be7b15753266aaf4dd78bcd85108dc5/exec"
data={ "AttachStdin":False,
"AttachStdout":True,
"AttachStderr":True, 
"Tty":False, 
"Cmd":['/bin/date'] }
returned=client.post(endpoint, data=data)

#Start the exec instance created above
endpoint="endpoints/1/docker/exec/"+str(returned['Id'])+"/start"
data = {"Detach": False,"Tty": False}
returned=client.post(endpoint,data=data)
print returned
print "\n"

```

I am always getting this error when running the last client.post()

```auto
Caused by: java.io.IOException: protocol error: Frame type(80) length(4740180) exceeds MAX_FRAME_SIZE(16384)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 22, 2020, 7:35pm UTC](https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725/7 "2020-07-22T19:35:56Z")

</div>

Try setting a `-Djdk.httpclient.maxframesize=524288` in the JVM arguments of wherever you’re running the http client - if it’s on the gateway, it’ll be in `ignition.conf`, in the `wrapper.java.additional` parameters section.

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [July 25, 2020, 9:37pm UTC](https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725/8 "2020-07-25T21:37:01Z")

</div>

Thanks, but i get exactly the same error.

I did like below, and rebooted the gateway. Im running in docker, but I guess it should not matter…

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/f/dfdce56c34c7bc182eea47b8e7a01f851557eb34.png)

You mentioned where i run the http client, thats in the designer on a different computer. Where can I change the framesize for a client?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 27, 2020, 3:25pm UTC](https://forum.inductiveautomation.com/t/ignition-and-docker-portainer-api-http-queries/36725/9 "2020-07-27T15:25:38Z")

</div>

In the JVM arguments of the designer launcher configuration - the same argument without the `wrapper.java.additional`; the entire remainder of the line starting with `-D` should do it.
