ChipCoons

ChipCoons

My Pheonix app is set up to be a bridge between a legacy JQuery web-app and Hubspot CRM.

I have all the functionality working to capture a contact in the JQuery side, pass it to the Pheonix app, and then sent a Create_Or_Update post to Hubspot leveraging a slightly updated Hubspotex implementation.

When the HTTP POST request is fired to Hubspot, it is returning a 200 response as expected, but I’m throwing an error in my Phoenix app and I’m not sure what to do to avoid the exception. I think I’m not handling the return correctly.

The function sending to Hubspot is:

  def send_to_hubspot(%Person{} = person) do
    email = person.email
    firstname = person.firstName
    lastname = person.lastName
    registration_event = person.event
    mobilephone = person.sms_phone
    body = %{properties: [
                %{property: "firstname", value: firstname},
                %{property: "lastname", value: lastname},
                %{property: "mobilephone", value: mobilephone},
                %{property: "registration_event", value: registration_event}
              ]
            }
    req = Hubspot.Contacts.create_or_update(email, body)
    case Hubspot.request(req) do
      {:ok, %HTTPoison.Response{status_code: 200}} ->
          person
      {:ok, %HTTPoison.Response{status_code: 409}} ->
        IO.puts "Conflict error response if you are trying to update the email address of a record, and there is an existing record with the new email address."
      {:error, %HTTPoison.Error{reason: reason}} ->
        IO.puts reason
    end

  end

I am calling the function after the Ecto/Postgres database is updated in this function (which is where I think my actual problem is…

  def update_person(%Person{} = person, attrs) do
    person
    |> Person.changeset(attrs)
    |> Repo.update()
    send_to_hubspot(person)
  end

And I’m getting the following exception in the console:

[error] #PID<0.538.0> running ScandimensionWeb.Endpoint (connection #PID<0.537.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: PUT /api/people/1
** (exit) an exception was raised:

    ** (FunctionClauseError) no function clause matching in ScandimensionWeb.FallbackController.call/2
        (scandimension) lib/scandimension_web/controllers/fallback_controller.ex:10: 
            ScandimensionWeb.FallbackController.call(%Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, 
                assigns: %{}, 
                before_send: [#Function<0.58261320/1 in Plug.Session.before_send/2>, #Function<1.112466771/1 in Plug.Logger.call/2>, #Function<0.33752287/1 in Phoenix.LiveReloader.before_send_inject_reloader/2>], 
                body_params: %{"person" => %{"email" => "test@test.com", "event" => "AustinMakerFaire", "firstName" => "Tom", "id" => 1, "lastName" => "Tester", "slot_score" => 5, "sms_phone" => "8015551212"}}, 
                cookies: %{"_scandimension_key" => "SFMyNTY.g3QAAAABbQAAAA9jdXJyZW50X3VzZXJfaWRhAQ.n-kVxZ-a6yhdrUfPzwxSbxhtBjqizNzaQF5XPYsXi1g"}, 
                halted: false, host: "localhost", method: "PUT", owner: #PID<0.538.0>, 
                params: %{"id" => "1", "person" => %{"email" => "test@test.com", "event" => "AustinMakerFaire", "firstName" => "Tom", "id" => 1, "lastName" => "Tester", "slot_score" => 5, "sms_phone" => "8015551212"}}, 
                path_info: ["api", "people", "1"], 
                path_params: %{"id" => "1"}, port: 4000, private: %{ScandimensionWeb.Router => {[], %{}}, 
                :phoenix_action => :update, 
                :phoenix_controller => ScandimensionWeb.PersonController, 
                :phoenix_endpoint => ScandimensionWeb.Endpoint, 
                :phoenix_format => "json", 
                :phoenix_layout => {ScandimensionWeb.LayoutView, :app}, 
                :phoenix_pipelines => [:api], 
                :phoenix_router => ScandimensionWeb.Router, 
                :phoenix_view => ScandimensionWeb.PersonView, 
                :plug_session => %{"current_user_id" => 1}, :plug_session_fetch => :done}, 
                query_params: %{}, query_string: "", 
                remote_ip: {127, 0, 0, 1}, r
                eq_cookies: %{"_scandimension_key" => "SFMyNTY.g3QAAAABbQAAAA9jdXJyZW50X3VzZXJfaWRhAQ.n-kVxZ-a6yhdrUfPzwxSbxhtBjqizNzaQF5XPYsXi1g"}, 
                req_headers: [{"accept", "*/*"}, 
                    {"accept-encoding", "gzip, deflate"}, 
                    {"cache-control", "no-cache"}, 
                    {"connection", "keep-alive"}, 
                    {"content-length", "148"}, 
                    {"content-type", "application/json"}, 
                    {"cookie", "_scandimension_key=SFMyNTY.g3QAAAABbQAAAA9jdXJyZW50X3VzZXJfaWRhAQ.n-kVxZ-a6yhdrUfPzwxSbxhtBjqizNzaQF5XPYsXi1g"}, 
                    {"host", "localhost:4000"}, 
                    {"postman-token", "72fffb40-c564-4aa1-91bf-f3c6960ed369"}, 
                    {"user-agent", "PostmanRuntime/7.11.0"}], 
                request_path: "/api/people/1", 
                resp_body: nil, 
                resp_cookies: %{}, 
                resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "FZkgGTd0_LBHp24AAAGC"}], 
                    scheme: :http, 
                    script_name: [], 
                    secret_key_base: :..., 
                    state: :unset, 
                    status: nil}, 
                    %Scandimension.Prospects.Person{__meta__: #Ecto.Schema.Metadata<:loaded, "people">, email: "test@test.com", event: nil, firstName: "Tom", id: 1, inserted_at: ~N[2019-04-25 16:08:38], is_synched: false, lastName: "Tester", slot_score: 5, sms_phone: "8015551212", updated_at: ~N[2019-04-26 20:20:05]})
        (scandimension) lib/scandimension_web/controllers/person_controller.ex:1: ScandimensionWeb.PersonController.action/2
        (scandimension) lib/scandimension_web/controllers/person_controller.ex:1: ScandimensionWeb.PersonController.phoenix_controller_pipeline/2
        (scandimension) lib/scandimension_web/endpoint.ex:1: ScandimensionWeb.Endpoint.instrument/4
        (phoenix) lib/phoenix/router.ex:275: Phoenix.Router.__call__/1
        (scandimension) lib/scandimension_web/endpoint.ex:1: ScandimensionWeb.Endpoint.plug_builder_call/2
        (scandimension) lib/plug/debugger.ex:122: ScandimensionWeb.Endpoint."call (overridable 3)"/2
        (scandimension) lib/scandimension_web/endpoint.ex:1: ScandimensionWeb.Endpoint.call/2
        (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:33: Phoenix.Endpoint.Cowboy2Handler.init/2
        (cowboy) /Users/chipcoons/Dev/Phoenix/scandimension/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
        (cowboy) /Users/chipcoons/Dev/Phoenix/scandimension/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3
        (cowboy) /Users/chipcoons/Dev/Phoenix/scandimension/deps/cowboy/src/cowboy_stream_h.erl:274: :cowboy_stream_h.request_process/3
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

First Post!

axelson

axelson

Scenic Core Team

Can you show your fallback controller and PersonController?

Last Post!

axelson

axelson

Scenic Core Team

I’m glad that you got it to work!

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews