pentacent / keila

Open Source Newsletter Tool.
https://keila.io
GNU Affero General Public License v3.0
1.44k stars 81 forks source link

How to PATCH / PUT campaign via API? #276

Open dompie opened 8 months ago

dompie commented 8 months ago

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?

wmnnd commented 8 months ago

Could you share the logs from your Keila instance?

dompie commented 8 months ago

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

wmnnd commented 8 months ago

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

dompie commented 8 months ago

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

wmnnd commented 8 months ago

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.

dompie commented 8 months ago

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