pentacent / keila

Open Source Newsletter Tool.

Home Page:https://keila.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to PATCH / PUT campaign via API?

dompie opened this issue · comments

Hello, I try to PATCH a campaign field (e.g. subject). But it results in an "Internal server error" when using swagger API. The result is also the same for PUT method.

Screenshot 2024-03-18 at 15-32-40 Swagger UI

Any suggestions?

Could you share the logs from your Keila instance?

Where can I find the logs? I'm not into Elexir app architecture...

How are you running Keila? The logs are outputted to stdout by the application when you run it.

I'm running it in the docker container. Found the logs:

18:41:34.579 request_id=F73v-vOvJ_7jlmgAAbih [info] PATCH /api/v1/campaigns/nmc_Mvg6QDVZ
18:41:34.585 request_id=F73v-vOvJ_7jlmgAAbih [info] Sent 500 in 5ms
18:41:34.586 [error] #PID<0.14628.0> running KeilaWeb.Endpoint (connection #PID<0.14627.0>, stream id 1) terminated
Server: keila.local:4000 (http)
Request: PATCH /api/v1/campaigns/nmc_Mvg6QDVZ
** (exit) an exception was raised:
    ** (ArgumentError) could not put/update key :id on a nil value
        (elixir 1.15.7) lib/access.ex:419: Access.get_and_update/3
        (elixir 1.15.7) lib/map.ex:957: Map.get_and_update/3
        (elixir 1.15.7) lib/kernel.ex:2817: Kernel.put_in/3
        (keila 0.14.0) lib/keila_web/api/controllers/api_campaign_controller.ex:83: KeilaWeb.ApiCampaignController.update/2
        (keila 0.14.0) lib/keila_web/api/controllers/api_campaign_controller.ex:1: KeilaWeb.ApiCampaignController.action/2
        (keila 0.14.0) lib/keila_web/api/controllers/api_campaign_controller.ex:1: KeilaWeb.ApiCampaignController.phoenix_controller_pipeline/2
        (phoenix 1.6.11) lib/phoenix/router.ex:354: Phoenix.Router.__call__/2
        (keila 0.14.0) lib/keila_web/endpoint.ex:1: KeilaWeb.Endpoint.plug_builder_call/2

I have also double-checked on campaigns index the given id exists.

Best regards

Could you try providing {"settings": {}} as part of the campaign object? This might fix the issue for now until I'm able to add a proper fix.

Yes, providing "settings": {}" attribute allows saving (although settings will reset to settings: {type: text}) - but works for me now.