1st argument: not an iodata term Error For multilingual text

I am trying to send a string of text as a body like this:

HTTPoison.post(
      "https://api.letter.net",
      '{"text": "{πŸ‡ΊπŸ‡Έ : Hello #{message} welcome here #{number} \n πŸ‡―πŸ‡΅ : #{number} γ‚ˆγ†γ“γγ„γ‚‰γ£γ—γ‚ƒγ„γΎγ—γŸ #{message} ハローウェルカム\n πŸ‡°πŸ‡· : #{message} μ•ˆλ…• #{number} μ—¬κΈ° μ˜€μ‹  것을 ν™˜μ˜ν•©λ‹ˆλ‹€}"}',
      [{"Content-Type", "application/json"}]
    )

But I am getting this error

[error] GenServer #PID<0.780.0> terminating
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not an iodata term

    :erlang.iolist_to_binary([123, 34, 116, 101, 120, 116, 34, 58, 32, 34, 127482, 127480, 32, 58, 32, 65, 32, 110, 101, 119, 32, 114, 101, 108, 101, 97, 115, 101, 32, 110, 111, 116, 101, 115, 32, 102, 111, 114, 32, 118, 51, 46, 49, 50, 46, 48, 32, 114, 101, 108, ...])

I know that this is because of the Japanese and Korean text but I am I did not find resources on how to send something like this…

Single quotes cannot be used interchangably with double quotes in elixir. Single quotes are a used for charlists and double quotes are use for binaries, which are different datatypes.

There are a few ways to go about double quotes within binaries.

# Escape inner quotes
"{\"text\": …"

# Use sigil_s to have different delimiters for a binary
~s({"text": …)

# Don't deal with json manually and use a json library like jason to do the encoding
Jason.encode!(%{text: """
{πŸ‡ΊπŸ‡Έ : Hello #{message} welcome here #{number} 
 πŸ‡―πŸ‡΅ : #{number} γ‚ˆγ†γ“γγ„γ‚‰γ£γ—γ‚ƒγ„γΎγ—γŸ #{message} ハローウェルカム
 πŸ‡°πŸ‡· : #{message} μ•ˆλ…• #{number} μ—¬κΈ° μ˜€μ‹  것을 ν™˜μ˜ν•©λ‹ˆλ‹€}
"""})
3 Likes

Thank you for explaining, You are right!