system
October 9, 2018, 5:48pm
1
Hi!
Got an internal error response when trying to post to Contacts API with user vid.
{“status”=>“error”, “message”=>“internal error”, “correlationId”=>“882e4799-b484-453b-b066-5ceb12979f62”, “requestId”=>“7ce9fe5842ea340f2d6f38a26b074795”}
Can someone help me, and what other information can I provide on here to solve the issue?
Thanks,
Victor
Hi @victorclee ,
Happy to help. To troubleshoot effectively, though, I’ll need the following information:
Your Hub ID.
The full request URL you used, including the method. (Don’t include your API key.)
The raw request body, including the headers.
The status code you received from HubSpot.
system
October 10, 2018, 7:32pm
3
@Isaac_Takushi
4592187
post https://api.hubapi.com/contacts/v1/contact/email/# { @user.email }/profile?hapikey=#{Rails.application.secrets.hubspot_api_key}
headers:{ “Accept” => “application/json” },
parameters:{
“properties”: [
{
“property”: “causes”,
“value”: “#{ @user.active_causes }”
},
{
“property”: “charities_helped”,
“value”: “#{ charities_count }”
},
{
“property”: “dollars_donated”,
“value”: “#{ total_giving }”
},
{
“property”: “percents”,
“value”: “#{ percent_pledged }”
},
{
“property”: “referral_code”,
“value”: “#{ set_share_link }”
},
{
“property”: “referrees”,
“value”: “#{ @user.referrees.count }”
},
{
“property”: “billable”,
“value”: “#{ @user.billable ? }”
},
{
“property”: “firstname”,
“value”: “Avocado”
}
]
}
code: 500
{“status”=>“error”, “message”=>“internal error”, “correlationId”=>“5c172128-03c4-4329-987a-dc41b8e6cc27”, “requestId”=>“1fe81a449aaac48704d95b2837dacd68”}
Hey @victorclee ,
I thought you were trying to update a contact by its vid ? That endpoint is via email .
Would you share a link to a contact you are attempting to update via the vid endpoint?
system
October 10, 2018, 8:11pm
5
@Isaac_Takushi
Sorry, posted the wrong url. I’ve tried updating both via email and vid, but I always get the 500 response.
“https://api.hubapi.com/contacts/v1/contact/vid/# { @user.hubspot_vid }/profile?hapikey=#{ Rails.application.secrets.hubspot_api_key }”
I was trying to update myself as a test
system
October 10, 2018, 8:16pm
6
I’m integrating the Contacts API with our Rails app, and I’m using a gem called Unirest to make the call
http://unirest.io/ruby.html
I can make changes to myself through the API when using Postman, but always get 500 response through our Rails app
system
October 11, 2018, 6:07pm
7
Any updates would be appreciated, @Isaac_Takushi
Hey @victorclee ,
I was able to update your contact’s Would you like to see some puppies? property , so the HubSpot endpoint and your API key are working properly.
I unfortunately won’t be of much help in troubleshooting Rails, but in this case, the 500 error suggests some formatting issue to me.
Are you able to get an example of the actual call made (not with the variables but the actual vid injected?
system
October 12, 2018, 6:02pm
9
@Isaac_Takushi
Here’s an code example of an attempt to update my own HubSpot contact through the API
require 'unirest'
require 'json'
contact = Unirest.post "https://api.hubapi.com/contacts/v1/contact/vid/2367/profile?hapikey=KEY",
headers: { "Accept" => "application/json" },
parameters: {"properties": [{"property": "firstname", "value": "Avocado"}]}.to_json
puts contact.code
contact.code shows me 500, and there’s no update to my profile.
system
October 15, 2018, 7:29pm
10
Happy Monday, @Isaac_Takushi ! Does the code example above help give you any insights on where the formatting issue is?
Hi @dadams , I was reading up on some other forum posts regarding developers getting 500 status code and saw your name several times. Please excuse me for roping you in in the middle, but thought the more set of eyes and brains on an issue the better. I provided most of the info I can in earlier posts. Please let me know what other info I can provide to give you a better picture of the issue. Thanks!
Hi @victorclee ,
Unirest seems to want a Hash for parameters and you’re currently calling .to_json on a JSON object.
Can you try:
{:properties=>[{:property=>"firstname", :value=>"Avacado"}]}
Failing that, try:
{:properties=>[{:property=>"firstname", :value=>"Avacado"}]}.to_json
P.S. I’ve removed your API key since this is a public forum.
system
October 15, 2018, 8:48pm
12
@Isaac_Takushi , thanks for responding! Still got 500 status back on both attempts. And yes, thank you very much for catching that for me
What are some other solutions we can try?
@victorclee ,
I’m frankly not familiar with Ruby, so you know more than I do on that front. Is there any way you can get me the actual JSON request body sent to the endpoint? (Not the Hash or the code you’re entering in the app.)
I’m heading out for the day, but I’ll see what I can do tomorrrow.
system
October 16, 2018, 2:00am
14
@Isaac_Takushi sure thing. Here’s the actual data that’s in the payload.
{:properties=>[{:property=>"causes", :value=>"Animals & Environment, Youth & Education"}, {:property=>"charities_helped", :value=>"8"}, {:property=>"dollars_donated", :value=>"75.0"}, {:property=>"percents", :value=>"1.0"}, {:property=>"referral_code", :value=>"https://www.percentpledge.org/invite?ref=Um1HUQ"}, {:property=>"referrees", :value=>"1"}, {:property=>"billable", :value=>"true"}]}
system
October 16, 2018, 1:17pm
15
@Isaac_Takushi Could it be something in the header?
system
October 16, 2018, 4:55pm
16
@Isaac_Takushi
The issue was solved by not using Unirest to make the HTTP call.
I ended up using URI and Net::HTTP.
I also added a .to_json at the end of my request body request.body = data.to_json
Finally got a 204!
Thanks for your help!
I’m glad to hear it, @victorclee !
I was thinking the issue was with the body data’s format, since the payload you pasted above is in Hash rather than JSON. I guess the .to_json method didn’t work in Unirest?
system
October 16, 2018, 5:09pm
18
@Isaac_Takushi
I think Unirest understands the to_json method, since it’s documented in their readme.
http://unirest.io/ruby.html
Under the “Custom Entity Body” section
At this point, I’m not able to pinpoint what the issue was with Unirest. The success came from an effort to duplicate what is working from using Postman, and the libraries it used were URI and Net::HTTP
[
Screen Shot 2018-10-16 at 12.08.54 PM.png719x580 35.2 KB
](https://community.hubspot.com/legacyfs/online/uploads/default/original/2X/1/1446233159bc24577e958a45718bd237af399e04.png )