# Connect Proxmox Backup Server (PBS) using API calls

**URL:** https://discourse.nodered.org/t/connect-proxmox-backup-server-pbs-using-api-calls/63758
**Category:** General
**Created:** [11 June 2022 08:19 UTC](https://discourse.nodered.org/t/connect-proxmox-backup-server-pbs-using-api-calls/63758 "2022-06-11T08:19:23Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![John245](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@John245](https://discourse.nodered.org/u/John245)
#### Post date: [11 June 2022 08:19 UTC](https://discourse.nodered.org/t/connect-proxmox-backup-server-pbs-using-api-calls/63758/1 "2022-06-11T08:19:23Z")

</div>

Trying

The first step is obtaining the ticket. In Postman I can manage using the following:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/2/223a2a95dacb7f76da28a8ddd230cf6f841eaab7.png)

Then set the cookie in the get request

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/ca2684e1b54ad4b9a45a16530abad38bd22e6580.png)

And I'm able to get the required info.

How to do this in Node-RED?

* * *

John

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [11 June 2022 09:37 UTC](https://discourse.nodered.org/t/connect-proxmox-backup-server-pbs-using-api-calls/63758/2 "2022-06-11T09:37:49Z")

</div>

Export your 2 queries as CURL and I will show you the "node-red" way using requests.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/f/9f5a887b840469d771747f2a074edfcfdf2d5091.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/515b3a5e7f77c9dfea7b2f63b686691746f52b62.png)

Feel free to sanitise any data (like username/password)

---

<div class="post-metadata">

### Author: ![John245](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@John245](https://discourse.nodered.org/u/John245)
#### Post date: [11 June 2022 10:23 UTC](https://discourse.nodered.org/t/connect-proxmox-backup-server-pbs-using-api-calls/63758/3 "2022-06-11T10:23:23Z")

</div>

It seems that I can simplify this by creating an API token. The curl command will then be:

`curl -H "Authorization: PBSAPIToken=root@pam!monitoring:xxx" https://192.168.1.150:8007/api2/json/version`

Coverting to JSON I will get:

```auto
{
    "url": "https://192.168.1.150:8007/api2/json/version",
    "raw_url": "https://192.168.1.150:8007/api2/json/version/",
    "method": "get",
    "headers": {
        "Authorization": "PBSAPIToken=root@pam!monitoring:xxx"
    }
}

```

And above is working in Postman.

Like to see how to achieve this in Node-RED.

* * *

John

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [11 June 2022 13:04 UTC](https://discourse.nodered.org/t/connect-proxmox-backup-server-pbs-using-api-calls/63758/4 "2022-06-11T13:04:41Z")

</div>

> [@John245](#):
>
> curl -H "Authorization: PBSAPIToken=root@pam!monitoring:xxx" [https://192.168.1.150:8007/api2/json/version](https://192.168.1.150:8007/api2/json/version)

Try this...

Demo flow (use `CTRL+I` to import)...

```auto
[{"id":"c82b311ec0638ce1","type":"http request","z":"4c5ad8c7caa80822","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[],"credentials":{"user":"","password":""},"x":440,"y":1160,"wires":[["92e61560bb618ec1"]]},{"id":"fe26ba8d9d76aca4","type":"function","z":"4c5ad8c7caa80822","name":"","func":"//original curl: \n//\n//curl -H \"Authorization: PBSAPIToken=root@pam!monitoring:xxx\" https://192.168.1.150:8007/api2/json/version\n\nmsg.method = \"get\";\nmsg.url = \"https://192.168.1.150:8007/api2/json/version\";\nmsg.payload = ``;\nmsg.headers = {\n \"Authorization\": \"PBSAPIToken=root@pam!monitoring:xxx\"\n};\nmsg.cookies = null;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":1160,"wires":[["c82b311ec0638ce1"]]},{"id":"92e61560bb618ec1","type":"debug","z":"4c5ad8c7caa80822","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":1160,"wires":[]},{"id":"2fde920d638097d0","type":"inject","z":"4c5ad8c7caa80822","name":"Click me","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":80,"y":1160,"wires":[["fe26ba8d9d76aca4"]]}]

```

---

<div class="post-metadata">

### Author: ![John245](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@John245](https://discourse.nodered.org/u/John245)
#### Post date: [11 June 2022 13:57 UTC](https://discourse.nodered.org/t/connect-proxmox-backup-server-pbs-using-api-calls/63758/5 "2022-06-11T13:57:04Z")

</div>

> [@Steve-Mcl](#):
>
> ```auto
> [{"id":"c82b311ec0638ce1","type":"http request","z":"4c5ad8c7caa80822","name":"","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[],"credentials":{"user":"","password":""},"x":440,"y":1160,"wires":[["92e61560bb618ec1"]]},{"id":"fe26ba8d9d76aca4","type":"function","z":"4c5ad8c7caa80822","name":"","func":"//original curl: \n//\n//curl -H \"Authorization: PBSAPIToken=root@pam!monitoring:xxx\" https://192.168.1.150:8007/api2/json/version\n\nmsg.method = \"get\";\nmsg.url = \"https://192.168.1.150:8007/api2/json/version\";\nmsg.payload = ``;\nmsg.headers = {\n \"Authorization\": \"PBSAPIToken=root@pam!monitoring:xxx\"\n};\nmsg.cookies = null;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":1160,"wires":[["c82b311ec0638ce1"]]},{"id":"92e61560bb618ec1","type":"debug","z":"4c5ad8c7caa80822","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":1160,"wires":[]},{"id":"2fde920d638097d0","type":"inject","z":"4c5ad8c7caa80822","name":"Click me","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":80,"y":1160,"wires":[["fe26ba8d9d76aca4"]]}]
> 
> ```

I will get:

"RequestError: self signed certificate : [https://192.168.1.150:8007/api2/json/version](https://192.168.1.150:8007/api2/json/version)"

* * *

John

---

<div class="post-metadata">

### Author: ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)
#### Post date: [11 June 2022 16:34 UTC](https://discourse.nodered.org/t/connect-proxmox-backup-server-pbs-using-api-calls/63758/6 "2022-06-11T16:34:01Z")

</div>

The error is quite self-explanatory... You are attempting an HTTPS request to an IP address and there is no valid certificate. So it fails.

If you look in the manual of the HTTP node:

```auto
rejectUnauthorized
If set to false, allows requests to be made to https sites that use self signed certificates.

```

In the function where msg.url and so on are set, adding a line:

```auto
msg.rejectUnauthorized = false;

```

should do the trick.

---

<div class="post-metadata">

### Author: ![John245](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@John245](https://discourse.nodered.org/u/John245)
#### Post date: [11 June 2022 17:34 UTC](https://discourse.nodered.org/t/connect-proxmox-backup-server-pbs-using-api-calls/63758/7 "2022-06-11T17:34:38Z")

</div>

Thnx, I had a look before at this but the post I found had a slightly different solution that did not do the job.

Thanks a lot for your help. It turned out that I should not use the HTTP nodes but just write a function.

* * *

John

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [25 June 2022 17:35 UTC](https://discourse.nodered.org/t/connect-proxmox-backup-server-pbs-using-api-calls/63758/8 "2022-06-25T17:35:20Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
