mirror of
https://github.com/Corsinvest/cv4pve-api-php.git
synced 2026-04-25 04:25:48 +03:00
[GH-ISSUE #33] JSON vs. x-www-form-urlencoded for PUT/POST #26
Labels
No labels
enhancement
needs investigation
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/cv4pve-api-php#26
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @lukasbruha on GitHub (May 15, 2024).
Original GitHub issue: https://github.com/Corsinvest/cv4pve-api-php/issues/33
Hi,
thx for you lib. But I was wondering if json_encode($parameters) for PUT/POST methods is correct behavior since API doc, see https://pve.proxmox.com/wiki/Proxmox_VE_API#API_URL, specifies following:
Parameters can be passed using standard HTTP techniques:
As far as I can see, there is no JSON support for PUT/POST parameters. Currently, I am getting 501 Not Implemented when I want to call eg. POST /api2/json/nodes/NODE-01/qemu/103/status/stop via this library. But once I replace $data = json_encode($parameters) to eg. $data = http_build_query($parameters) in executeAction() and remove array_push for headers' Content-Type and Content-Length on lines that follows, server accepts it with 200 OK.
I am sure this library is using by several devs, so maybe it is about my Proxmox configuration. But since there is no official support of JSON mentioned in Proxmox documentation, I would kindly ask you for any response to this issue.
Thx.
@franklupo commented on GitHub (May 15, 2024):
Hi,
what parameters do you pass?
can you attach an example?
best reagrds
@lukasbruha commented on GitHub (May 15, 2024):
Hi, no parameters. The issue is in Content-Type and json_encode (although it is empty). Seems Proxmox API rejects it in general because of these both. FYI I am using Proxmox VE 8.1.4.
In code, see https://github.com/Corsinvest/cv4pve-api-php/blob/master/src/PveClientBase.php#L380, there is no decision to not pass empty data if not defined. It passes and sets Content-Type everytime. So I cannot avoid that.
@franklupo commented on GitHub (May 15, 2024):
is the solution not to pass parameters if they aren't there?
@lukasbruha commented on GitHub (May 15, 2024):
I am not sure since JSON as input is not officially supported according to documentation. If method was protected instead of private, I would overwrite it myself to avoid JSON for PUT/POST completely and pass query instead although I think JSON is more pretty and would be suitable when Proxmox responses are in JSON as well.
Question: when you developed this lib, JSON was working with Proxmox POST call as mentioned above? I was wondering why I am the only one having these issues. Can you test it yourself in your dev env with Proxmox?
@franklupo commented on GitHub (May 15, 2024):
check the problem and I'll update you
@lukasbruha commented on GitHub (May 16, 2024):
Hi, I have (possibly) find a solution (you have mentioned it above): when there are no parameters, you should avoid empty JSON and CURLOPT_POSTFIELDS should be set to empty string (as defined on https://curl.se/libcurl/c/CURLOPT_POSTFIELDS.html). When there are any parameter, JSON can be sent although Proxmox API doc does not mention it explicitly on https://pve.proxmox.com/wiki/Proxmox_VE_API#API_URL
So the fix in https://github.com/Corsinvest/cv4pve-api-php/blob/master/src/PveClientBase.php#L378 should be:
Analogically for PUT switch-case branch in https://github.com/Corsinvest/cv4pve-api-php/blob/master/src/PveClientBase.php#L369.
Does it make sense to you?
@franklupo commented on GitHub (May 16, 2024):
Yes, if you want create a pull request
@lukasbruha commented on GitHub (May 17, 2024):
Done, see https://github.com/Corsinvest/cv4pve-api-php/pull/34. Please merge it once you have time.