Using The MailGateway API

infinityM

Member
Dec 7, 2019
166
1
18
27
Hey Guys,

I am having a very hard time understanding the proxmox mail gateway's api calls...
I am 99% sure it's just me, so hopefully someone can help me?

How can I call for example the login function, and the GET /api2/json/config/domains/ function afterwards?
Also do I need to allow an IP access to the API? Or how does it work?

It feels like the basic info I need is very lacking...

PS I am using php (If that helps ;) ).

Thank you guys in advance
 

infinityM

Member
Dec 7, 2019
166
1
18
27
hi,

the pmg api is very similar to the pve api, only the paths/parameters are different, maybe this helps
https://pve.proxmox.com/wiki/Proxmox_VE_API
https://pmg.proxmox.com/pmg-docs/api-viewer/index.html
Thank you :). But I am still having a bit of a hard time understanding how to pass it along... The documentation does not make it clear to me....
Maybe it's just me, but the formatting makes no sense... Would you be able to advise me on the formatting? IS there a php simple example for how to call for example the login?

I just need to understand the basic structure then I can go on. Cause right now I kep getting a missing properties error...
 

dcsapak

Proxmox Staff Member
Staff member
Feb 1, 2016
5,638
581
133
32
Vienna
what error do you get?

in general you need to pass the credentials to the /access/ticket call and you get a ticket in response
this ticket is sent as a cookie to each subsequent api call (and the csrf in the header for put/post calls)
 

infinityM

Member
Dec 7, 2019
166
1
18
27
what error do you get?

in general you need to pass the credentials to the /access/ticket call and you get a ticket in response
this ticket is sent as a cookie to each subsequent api call (and the csrf in the header for put/post calls)

Ok so I found a class to help: https://github.com/CpuID/pve2-api-php-client/blob/master/pve2_api.class.php

The only issue I am having is I keep getting a false error, So when I dump the response I get the below output... What does it say? The ticket expired?
And if so, why would that happen?
"HTTP/1.1 401 No ticket Cache-Control: max-age=0 Connection: close Date: Tue, 03 Mar 2020 20:42:47 GMT Pragma: no-cache Server: pve-api-daemon/3.0 Expires: Tue, 03 Mar 2020 20:42:47 GMT "

Is there a log I can tail for more info?
 

infinityM

Member
Dec 7, 2019
166
1
18
27
Ok soI have been playing around, and I see the time on the response is always 2Hours behind my time, even though the server's time now matches my pc's time.

So it's as if the ticket expires even though it was just issued... Can you please advise if you know what might be causing it?
 

dcsapak

Proxmox Staff Member
Staff member
Feb 1, 2016
5,638
581
133
32
Vienna
I see the time on the response is always 2Hours behind my time
which part? the ticket?

in general this should not matter, since the server validates the ticket again (which is the source of the time in the ticket)

it looks like you do not set the cookie.
any chance on seeing the exact request to the server?
 

infinityM

Member
Dec 7, 2019
166
1
18
27
which part? the ticket?

in general this should not matter, since the server validates the ticket again (which is the source of the time in the ticket)

it looks like you do not set the cookie.
any chance on seeing the exact request to the server?
I have attached the test script in a zip folder, Just replace with your own variables for a server:).
 

Attachments

  • pveapi.zip
    4.5 KB · Views: 25

infinityM

Member
Dec 7, 2019
166
1
18
27
The issue I have, is I var dump the variables and they all seem to be there... So I am at a loss..
 

dcsapak

Proxmox Staff Member
Staff member
Feb 1, 2016
5,638
581
133
32
Vienna
ok ... after looking at this, the api client you use sets the cookie 'PVEAuthCookie' (since it is for pve) the Cookie for the mailgateway is 'PMGAuthCookie'
 

infinityM

Member
Dec 7, 2019
166
1
18
27
ok ... after looking at this, the api client you use sets the cookie 'PVEAuthCookie' (since it is for pve) the Cookie for the mailgateway is 'PMGAuthCookie'
My Man you are an absolute legend! I could not understand why the cookie was an issue...
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE and Proxmox Mail Gateway. We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get your own in 60 seconds.

Buy now!