ex_airtable icon indicating copy to clipboard operation
ex_airtable copied to clipboard

Incorrect URL when retrieving record with Service.retrieve/2

Open mvellandi opened this issue 4 years ago • 0 comments

Hi, I just noticed I was getting 404s when following the guide, doing module setup (base, api_key, name), and then retrieving a record like: MyTable.retrieve("rec12345")

My clue was the "%2F" following my table name "editions" %HTTPoison.Response{ request_url: "https://api.airtable.com/v0/{my_base_id}/editions%2FrecY33Xhr5arkWEIa" }

I looked at ExAirtable.Service, and updated retrieve/2 from: def retrieve(%Config.Table{} = table, id) when is_binary(id) do perform_request(table, url_suffix: "/" <> id) |> Airtable.Record.from_map() end to def retrieve(%Config.Table{} = table, id) when is_binary(id) do perform_request(table, url_suffix: id) |> Airtable.Record.from_map() end

and updated base_url/2 from: defp base_url(%Config.Table{} = table, suffix) when is_binary(suffix) do table.base.endpoint_url <> "/" <> encode(table.base.id) <> "/" <> encode(table.name) <> encode(suffix) end to defp base_url(%Config.Table{} = table, suffix) when is_binary(suffix) do table.base.endpoint_url <> "/" <> encode(table.base.id) <> "/" <> encode(table.name) <> "/" <> encode(suffix) end

Worked for me at least. Cheers and thanks for this cool library!

mvellandi avatar Jan 19 '21 19:01 mvellandi