Problem with REST API calls using PUT/POST methods
-
First, thank you for the work you’ve put into this plugin; you’ve done a fantastic job.
I am having an issue with the Create License and Update License REST API calls; the API returns status 200, but in both cases no actual data is saved.
Additionally, a bug in the current implementation is causing the content body of the response for Create License POST requests to return an array of all licenses, as supposed to just the license created from that request. Typically an API response for a POST request would return only the newly-created object, and per your documentation, that is the intended behavior for this API also.
Specifics of the problem, and the env follow:
- The consumer key/secret are valid, with R/W permissions
- The API key is assigned to a user with full admin permissions on this WordPress install
- All API routes are enabled
- Permalinks have been re-saved
- Both API calls are being sent with the Accept and Content-Type headers set to application/json
- Body content is raw json string, using the snake_case format for field names, eg: { “product_id”: 123 }
- All of the other licenses API routes that take GET method are working fine (such as licenses/activate, with the activation count incrementing as it should); only the PUT and POST calls are having this issue
- Both WordPress and WooCommerce are on the latest stable version
- Using Postman for testing the API calls
For the Update License request, it’s returning http status 200, with Success: true and the license data object in the content body, but without the updated values in my request, with the actual license in the database unchanged.
For the Create License request, it’s also returning http status 200, but not actually saving the new license to the database. In addition, as mentioned earlier, the response is actually an array of all licenses (as if I had made a “List Licenses” request) – the new license the request was supposed to create, is not in that list, nor is it anywhere in the database with the other licenses.
Last question; do you accept pull requests for bug fixes such as this? And where would that be done at? The GitHub repo appears to be out of date, but I’d gladly contribute if it helps.
Thanks in advance,
SKEdit: For reference, I’ve included two actual API requests that are failing:
CREATE LICENSE:
curl --location --request POST '[BaseAddressRedacted]/wp-json/lmfwc/v2/licenses' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header 'Authorization: Basic [CredentialsRedacted]' \ --data-raw '{ "order_id": null, "product_id": 34050077, "user_id": null, "license_key": "ABC-123-XYZ", "expires_at": null, "valid_for": null, "status": 4, "times_activated": null, "times_activated_max": 1 }'
UPDATE LICENSE:
curl --location --request PUT '[BaseAddressRedacted]/wp-json/lmfwc/v2/licenses/J1M-3JN-IRW' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header 'Authorization: Basic [CredentialsRedacted]' \ --data-raw '{ "times_activated_max": 999 }'
- The topic ‘Problem with REST API calls using PUT/POST methods’ is closed to new replies.