500 Response when making API call to update template


#1

This has been working consistently in the past and just stopped working today.
Here is my request and response:

  Faraday.put(
      "https://api.hubapi.com/content/api/v2/templates/#{ENV["HS_BLOG_SHOW_ID"]}\?hapikey\=#{ENV["HS_API_KEY"]}",
      { "source": File.read(ENV["BLOG_SHOW_PATH"]) }.to_json
    )

#<Faraday::Response:0x007faafa881ee8
 @env=
  #<struct Faraday::Env
   method=:put,
   body="",
   url=#<URI::HTTPS https://api.hubapi.com/content/api/v2/templates/4547682099?hapikey=[reducted]>,
   request=#<struct Faraday::RequestOptions params_encoder=nil, proxy=nil, bind=nil, timeout=nil, open_timeout=nil, boundary=nil, oauth=nil>,
   request_headers={"User-Agent"=>"Faraday v0.11.0", "Content-Type"=>"application/x-www-form-urlencoded"},
   ssl=
    #<struct Faraday::SSLOptions
     verify=true,
     ca_file=nil,
     ca_path=nil,
     verify_mode=nil,
     cert_store=nil,
     client_cert=nil,
     client_key=nil,
     certificate=nil,
     private_key=nil,
     verify_depth=nil,
     version=nil>,
   parallel_manager=nil,
   params=nil,
   response=#<Faraday::Response:0x007faafa881ee8 ...>,
   response_headers=
    {"access-control-allow-credentials"=>"false",
     "x-trace"=>"1B2A084E55F29F7E746B0D442863CE913AD8B95A4F69D735924DAC8384",
     "content-length"=>"0",
     "date"=>"Fri, 24 Mar 2017 14:33:50 GMT",
     "connection"=>"close"},
   status=500,
   reason_phrase="Internal Server Error">,
 @on_complete_callbacks=[]>

What do I need to do to fix this?


#2

We are also getting 500 server errors when attempting to make calls to the Blog Post create endpoint.


#3

Hi @brennenawana

You’ll need to include the content-type: application/json header in your request. The current request has Content-Type"=>"application/x-www-form-urlencoded, which is causing that error.

We’re working on a fix for this so that you’ll get a 415 Unsupported Media Type error for this instead of the generic 500 when the content-type is incorrect.


#4

Thanks @dadams. Let me try that out right now.


#5

This does indeed look to be our problem as well, there must have been a change to make requests a bit stricter :slight_smile:

Will be great to have a better error message for this @dadams

Thanks.


#6

Yes! That was the issue. Thanks for the quick response. Two thumbs up :thumbsup: :smile: :thumbsup: