Wrong URI for PushEvent causes 404
Was just debugging why I receive the error non-ok code received (404) from the API when using PushEvent.
The response body is the 404 page with HTML such as <div class="mt-4 text-xl dark:text-gray-100">Oops! There's nothing here</div> and the request URI is https://plausible.io/api/v1/api/event.
@andrerfcsantos So it seams like the path is wrong...
Version: v0.4.0
It seems to be an issue with https://plausible.io/api/v1/api/event vs Plausible's documented https://plausible.io/api/event
I solved it via the following, and will leave it here for others, @JohannesKaufmann I assumed you did this as well:
// create plausible client for events api
pl := plausible.NewClientWithBaseURL(config.PLAUSIBLE_API_KEY, "https://plausible.io")
Seems like this detail escaped code review, sorry for this.
This is a tricky one, the whole idea of allowing to provide a base URL was to allow:
- To point to self-hosted instances
- To allow to specify the API version by including it in the base URL
Specifically, this second point assumed the base URL would always include the version of the endpoints. But this event endpoint is not versioned, which introduces a bit of an edge case here.
I was tempted to just make https://plausible.io the default base URL the library would use and update all the endpoint calls to then append the /api/v1/ bit, except for the events endpoint where it would just append /api, However, this would be a breaking change so I didn't make it. But it's something that will be considered for the next major bump of the library.
Instead, I released v0.5.0 which strips the version from the base URL just for the event request
@JohannesKaufmann @jackspirou Can you upgrade to 0.5.0 and let me know if this fixes your issue? With this version, the workaround of setting the base URL to "https://plausible.io" is no longer needed. I've made it so the workaround will still work for the events requests after the upgrade, but I strongly encourage you to revert the workaround, as it makes the client created not work for other requests other than the events one. With this new version, all requests should work without the need to set a base URL, and the only reasons one should change the base URL are the two specified previously.