elixir-google-api icon indicating copy to clipboard operation
elixir-google-api copied to clipboard

Unsupported content with type: multipart/form-data

Open Ephemera opened this issue 5 years ago • 6 comments

This simple calendar_events_watch request does not run correctly:

GoogleApi.Calendar.V3.Connection.new(access_token)
|> GoogleApi.Calendar.V3.Api.Events.calendar_events_watch("primary", [resource: %{...}])

{:error,
  %Tesla.Env{
    ...
    body: "{\n \"error\": {\n  \"errors\": [\n   {\n    \"domain\": \"global\",\n    \"reason\": \"badContent\",\n    \"message\": \"Unsupported content with type: multipart/form-data; boundary=194fad99068751d50d113fb07433c3bf\"\n   }\n  ],\n  \"code\": 400,\n  \"message\": \"Unsupported content with type: multipart/form-data; boundary=194fad99068751d50d113fb07433c3bf\"\n }\n}\n",
  }
}

Is there something wrong?

Ephemera avatar Mar 10 '20 06:03 Ephemera

I had the same issue in GoogleApi.Admin.Directory_v1.Api.Users.directory_users_watch

I suspect google api doesn't support multipart/form-data in OAuth2 api refs: https://stackoverflow.com/a/37587304/9721470

vip30 avatar Apr 14 '20 06:04 vip30

I'm encountering the same issue with GoogleApi.Drive.V3.Api.Files.drive_files_watch. Did either of you find a solution @Ephemera @vip30 ?

BenSchZA avatar May 14 '20 10:05 BenSchZA

I'm encountering the same issue with GoogleApi.Drive.V3.Api.Files.drive_files_watch. Did either of you find a solution @Ephemera @vip30 ?

I gave up the client in directory watch and implemented it by Httpoison Would like to see if there is any others work around

vip30 avatar May 14 '20 12:05 vip30

I think I'll go ahead and do that too. Spent the last few hours fiddling. Do you have a sample of the Poison code you wrote for that request?

BenSchZA avatar May 14 '20 12:05 BenSchZA

I think I'll go ahead and do that too. Spent the last few hours fiddling. Do you have a sample of the Poison code you wrote for that request?

The code is something like that

    token = Auth.get_token("https://www.googleapis.com/auth/admin.directory.user", :admin)

    case request(
           :post,
           %{
             domain: domain,
             event: event
           },
           "https://www.googleapis.com/admin/directory/v1/users/watch",
           channel,
           token.token
         ) do
      {:ok, response} ->
        Poison.decode!(response.body, as: %GoogleChannel{})

      {:error, info} ->
        Logger.info("error in watch_user #{inspect(info)}")
        nil
    end

  defp request(method, params, url, body, token) do
    HTTPoison.request(%HTTPoison.Request{
      method: method,
      params: params,
      url: url,
      body: Poison.encode!(body),
      headers: [{"authorization", "Bearer #{token}"}, {"content-type", "application/json"}]
    })
  end

vip30 avatar May 14 '20 12:05 vip30

I solved it the same way using HTTPoison.

Ephemera avatar May 20 '20 03:05 Ephemera