defmodule SimpleshopWeb.DebugLive do use SimpleshopWeb, :live_view require Logger @impl true def mount(_params, _session, socket) do send(self(), :fetch_shops) {:ok, socket |> assign(:loading, true) |> assign(:shops, []) |> assign(:error, nil) |> assign(:response_details, nil)} end @impl true def handle_info(:fetch_shops, socket) do config = Application.get_env(:simpleshop, :printify) token = Keyword.get(config, :access_token) if token && token != "your_personal_access_token_here" do url = "https://api.printify.com/v1/shops.json" # Try without the Content-Type header - some APIs don't like it for GET requests headers = [ {"Authorization", "Bearer #{token}"}, {"User-Agent", "SimpleshopMVP"} ] Logger.info("Making request to: #{url}") Logger.info("Token (first 20 chars): #{String.slice(token, 0, 20)}...") case Req.get(url, headers: headers) do {:ok, %{status: 200, body: shops}} -> Logger.info("Successfully fetched #{length(shops)} shops") {:noreply, socket |> assign(:loading, false) |> assign(:shops, shops) |> assign(:error, nil) |> assign(:response_details, nil)} {:ok, %{status: status, body: body, headers: resp_headers}} -> Logger.error("Failed to fetch shops: #{status}") Logger.error("Response body: #{inspect(body)}") Logger.error("Response headers: #{inspect(resp_headers)}") error_msg = case body do %{"errors" => errors} -> "API Error: #{inspect(errors)}" %{"message" => message} -> "API Error: #{message}" _ -> inspect(body) end {:noreply, socket |> assign(:loading, false) |> assign(:error, "HTTP #{status}: Authentication failed") |> assign(:response_details, %{ status: status, body: body, error_msg: error_msg })} {:error, error} -> Logger.error("HTTP error fetching shops: #{inspect(error)}") {:noreply, socket |> assign(:loading, false) |> assign(:error, "Network error: #{inspect(error)}") |> assign(:response_details, nil)} end else {:noreply, socket |> assign(:loading, false) |> assign(:error, "Access token not configured. Please add it to config/dev.exs") |> assign(:response_details, nil)} end end @impl true def render(assigns) do ~H"""

Printify Shop Information

<%= if @loading do %>

Fetching your shop information...

<% else %> <%= if @error do %>

Error

<%= @error %>

<%= if @response_details do %>

Debug Information:

Status Code: <%= @response_details.status %>

Error Message: <%= @response_details.error_msg %>

Full Response Body
<%= Jason.encode!(@response_details.body, pretty: true) %>

Troubleshooting Tips:

  • Make sure you copied the FULL token (it's very long)
  • Check that there are no extra spaces before or after the token
  • The token should start with "eyJ"
  • Make sure the token hasn't expired
  • Try creating a new Personal Access Token in Printify
<% end %>
<% else %> <%= if @shops == [] do %>

No shops found for this account.

<% else %>
<%= for shop <- @shops do %>

<%= shop["title"] %>

Shop ID (Use this!)

<%= shop["id"] %>

Sales Channel

<%= shop["sales_channel"] || "N/A" %>

Next step: Copy the Shop ID above and paste it into config/dev.exs

shop_id: "<%= shop["id"] %>",
View full shop details (JSON)
<%= Jason.encode!(shop, pretty: true) %>
<% end %>
<% end %> <% end %>
<.link navigate={~p"/"} class="inline-block bg-gray-600 text-white px-6 py-2 rounded-lg hover:bg-gray-700" > ← Back to Home <.link navigate={~p"/products"} class="inline-block bg-blue-600 text-white px-6 py-2 rounded-lg hover:bg-blue-700" > View Products →
<% end %>
""" end end