Closed henrytso closed 5 years ago
Hi - have you implemented the other method (Approve and optionally AutoApprove) as well? By default, Ponzu will not accept outside data from requests and make it public through the content API. See the other methods at the bottom of the file here:
https://github.com/ponzu-cms/ponzu/blob/master/examples/createable/content/song.go
Also, all create requests must be POST requests encoded as multipart/form-data, not URL parameters as it appears in your comment.
Thank you for your response! I now sent the POST request as multipart/form-data (with Postman).
[Create] error calling BeforeCreate: Auth failed for request
I see that since BeforeAPICreate returns an error, the request is cancelled and the Create method is not reached. I believe Admin Users are identified by email and password. How can I send this POST request and have the server recognize that I am an admin user? Is there another form field I missed?
@henrytso -
Since BeforeAPICreate
calls auth.IsValid(req)
in this example, seen here:
https://github.com/ponzu-cms/ponzu/blob/master/examples/createable/content/song.go#L112-L115
auth.IsValid is implemented here: https://github.com/ponzu-cms/ponzu/blob/master/system/admin/user/auth.go#L64-L74
where it checks for a token in a cookie. You can authenticate similarly from Postman by adding the same cookie that your browser has stored for the Ponzu API domain. As this package is part of the admin
package, it is specifically suited to check if requests are made by a CMS admin.
Let me know if this helps!
Closing this issue. It appears to be answered/resolved. Please reopen if not the case.
I saw the example Song.go files which implement api.Createable, api.Updateable, and api.Deleteable. However, it seems that the body of the Create method only checks whether the POST request is valid (has parameters: "title", "artist", "rating","opinion","spotify_url").
However, if there is no valid, it simply returns nil but does not seem to create a new Song. Is additional code editing required to create the instance? I made the following POST request (through Postman) and received a "200 OK" response status:
Similarly, I am unsure whether the Update and Delete methods make changes successfully, as they also return nil after validation.
I would greatly appreciate any tips and tricks for this issue of mine. Thanks in advance!