alcantarajosephc

alcantarajosephc

Invalid paremeter when passing an array

I have this curl.

curl -H "Content-Type: application/json" -X POST -d '{"file_server": {"method": "api/file", "parameter": [{"filepath":"tehnnhjhst", "FileBase64String":"test"}]}}' http://localhost:4000/api/some_method

But I got this JSON response:

{"errors":{"parameter":["is invalid"]}}

This is my model

schema "some_method" do
    field :method, :string
    field :parameter, :string

    timestamps()
  end

I just wanted to store the array as plain text/string to my MySql database.
Is there parse equivalent to this? or?
Any idea? Thank you.

Most Liked

wfgilman

wfgilman

You’ve defined :parameter as a :string but you’re passing an array, as you state. I would expect there to be an error.

Are you using changesets for your model? They help validate your datatypes with some nice error messages.

alcantarajosephc

alcantarajosephc

Yes im using changesets to my model.

def changeset(struct, params \\ %{}) do
    struct
    |> cast(params, [:method, :parameter])
    |> validate_required([:method, :parameter])
  end

So array in :string (varchar(255), utf8_general_ci in my MySql database) is not allowed?

wfgilman

wfgilman

I’m confused. An array is not a string. You should get an error message.

Last Post!

alcantarajosephc

alcantarajosephc

I just hook it in JSON encode.

params = Map.put(params, "parameter", Poison.encode!(params["parameter"])

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New

We're in Beta

About us Mission Statement