Failing to post comments through the API


#1

We are displaying blog posts in a custom site retrieving the blog posts through the API which works fine.

However we are trying to implement the comment API for posting comments but are getting stuck at the following:

We are sending the following data to: https://api.hubapi.com/comments/v3/comments

userName=Test
userEmail=test%40example.com
userUrl=http%3A%2F%2Fexample.com
comment=Test+comment.
portalId=_REDACTED_ (taken from top right hubspot portal)
contentId=_REDACTED_ (the blog post ID taken from the API)
collectionId=_REDACTED_ (the blog post group ID taken from the API)
contentPermalink=_REDACTED_ (the blog post url)
contentAuthorName=_REDACTED_ (the blog post author name)
contentAuthorEmail=_REDACTED_ (the blog post author email)
hs_context=_REDACTED_ (taken from the hubspot cookie)

But we are getting a 400 HTTP error with the following message:

{
    "status": "error",
    "message": "Unable to deduce portalId from this request.",
    "correlationId": "c2e2f43a-64b8-485d-bfbe-___",
    "requestId": "00dd251f22bed29ad8d392___"
}

Can you guys point us in the right direction? In the documentation is no mention of the portalId parameter so we added it ourselfs to see if that would help but that doesn’t change the error.


#2

Hi @stayallive

Are you making this request using an API key or an access token? If you’re using an access token, is this an OAuth2 token (using the Authorization header) or an old token (using the access_token= query parameter?


#3

Hey @dadams,

We are using an API key (hapikey parameter) in the URL the same way we are retrieving comments.

So the full URL we are posting to is: https://api.hubapi.com/comments/v3/comments?hapikey=___&portalId=___

I just tried to fiddle arround again and now we are getting a 500 response internal error (we had the parameters in the post body for testing).

So something changed… but it’s still not working as expected :slight_smile:


#4

I'm getting exact same issue. Can anyone please identify the issue here?

I'm sending these data in API and using this api url.

URL : http://api.hubapi.com/comments/v3/comments?hapikey=api _key&portalId=_id

Data: var form = {
comment,
contentId,
collectionId,
contentAuthorEmail,
contentAuthorName,
contentPermalink, contentTitle,
userEmail,
portalId,
userName
}


#6

Hey, @Krina.

This endpoint requires a JSON-formatted payload. Additionally, no portalId parameter should be included in the request URL.

I successfully created comments on my own blog posts with the following format:

POST https://api.hubapi.com/comments/v3/comments?hapikey=my_api_key

{
"comment" : "This is a test comment.",
"contentId": "5340056079",
"collectionId": "4623992565",
"contentAuthorEmail": "SampleHubSpotUser@hubspot.com",
"contentAuthor": "Sample HubSpot User",
"contentPermalink": "https://blog.mysite.com/blog-post-slug",
"userEmail": "john.doe@hubspot.com",
"userName": "John Doe"
}

#7

@Isaac_Takushi
I'm sendind this in json format and also same data, There's still confusion in one thing here, I'm getting collectionId same as contentId in detail API and you seems to have different. Kindly guide me for this.

As well, If I send the same things, I'm getting following error:

{"status":"error","message":"Unable to deduce portalId from this request.","correlationId":"25d471cd-0881-4743-828c-38a10c92e36e","requestId":"e998b2953ed817065fefd9f2f3f3e9e4"}

Thanks,
Krina Soni


#8

Hi, @Krina.

Can you share the actual JSON you are sending so I can take a closer look?