@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file.
- New filter type: `contains`, available for `page`, `entry_page`, `exit_page`
- Add filter for custom property
- Add ability to import historical data from GA: plausible/analytics#1753
- API route `GET /api/v1/sites/:site_id`
### Fixed
- UI fix where multi-line text in pills would not be underlined properly on small screens.
@ -28,6 +28,16 @@ defmodule PlausibleWeb.Api.ExternalSitesController do
end
def get_site(conn, %{"site_id" => site_id}) do
site = Sites.get_for_user(conn.assigns[:current_user].id, site_id, [:owner, :admin])
if site do
json(conn, site)
else
H.not_found(conn, "Site could not be found")
def delete_site(conn, %{"site_id" => site_id}) do
site = Sites.get_for_user(conn.assigns[:current_user].id, site_id, [:owner])
@ -101,6 +101,7 @@ defmodule PlausibleWeb.Router do
pipe_through [:public_api, PlausibleWeb.AuthorizeSitesApiPlug]
post "/", ExternalSitesController, :create_site
get "/:site_id", ExternalSitesController, :get_site
delete "/:site_id", ExternalSitesController, :delete_site
put "/shared-links", ExternalSitesController, :find_or_create_shared_link
put "/goals", ExternalSitesController, :find_or_create_goal
@ -384,4 +384,20 @@ defmodule PlausibleWeb.Api.ExternalSitesControllerTest do
}
describe "GET /api/v1/sites/:site_id" do
setup :create_new_site
test "get a site by it's domain", %{conn: conn, site: site} do
conn = get(conn, "/api/v1/sites/" <> site.domain)
assert json_response(conn, 200) == %{"domain" => site.domain, "timezone" => site.timezone}
test "is 404 when site cannot be found", %{conn: conn} do
conn = get(conn, "/api/v1/sites/foobar.baz")
assert json_response(conn, 404) == %{"error" => "Site could not be found"}