APIs & Integrations

josephLayden
Colaborador(a)

Blog Post API throwing ssl.SSLCertVerificationError

resolver

I am trying to automate a batch of blog posts. Currently, the posts are created in draft mode, but then I receive a 404 when I try to push the draft version live. Here are the two functions I have written. First, I create the post and receive a 200 success message and the draft version of the post shows up in my portal. However, the second function errors out, saying "All who wander are not lost"

def create_blog_post():
    """Create a new blog post
    POST /content/api/v2/blog-posts
    """
    xurl = "/content/api/v2/blog-posts"
    url = HS_API_URL + xurl + APIKEY
    headers = { "content-type" : "application/json" }
    response = requests.post(url, headers=headers, data=json.dumps(new_post))
    print(response.status_code, response.content, response)

create_blog_post()

Next I try and publish using:

def schedule_post(blog_post_id):
    """
    Publish, schedule or unpublish a blog post
    POST /content/api/v2/blog-posts/:blog_post_id/publish-action
    """
    xurl = "/content/api/v2/blog-posts/:" + str(blog_post_id) + PUBLISH
    url = HS_API_URL + xurl + APIKEY
    response = requests.post(url)
    print(response.status_code, response.content, response)

schedule_post(6612191199)

When I run the publish function. The 404 error says that the post is not found, but there is a draft version in the portal.

<!-- 404 error --><div class="page"><div class="container"><div class="content"><div class="page- header"><h1>All who wander are not lost</h1><h2>But that page is nowhere to be found.</h2></div><div id="content"><p></p></div></div></div></div><div class="status-code">404</div></body>' <Response [404]>

While I am trying to set the publish_date to an epoch time, In the portal the date scheduled always is 1970 even though I am setting an epoch time for later today.

I am working on debugging using RequestBin: https://requestbin.fullcontact.com/1iiiiyo1?inspect

0 Avaliação positiva
1 Solução aceita
josephLayden
Solução
Colaborador(a)

Blog Post API throwing ssl.SSLCertVerificationError

resolver

Yes. I was receiving 404 and 500 errors. The 404 was due to wrong Hapikey and the 500 error was due to a proxy server on the corporate network.

Exibir solução no post original

0 Avaliação positiva
5 Respostas 5
cbarley
Alunos da HubSpot
Alunos da HubSpot

Blog Post API throwing ssl.SSLCertVerificationError

resolver

Hi @joseph.layden, Just came across your post in the developer's slack API channel. Looks like you were speaking with Matt Coley about this. Were you able to resolve the issue?

0 Avaliação positiva
josephLayden
Solução
Colaborador(a)

Blog Post API throwing ssl.SSLCertVerificationError

resolver

Yes. I was receiving 404 and 500 errors. The 404 was due to wrong Hapikey and the 500 error was due to a proxy server on the corporate network.

0 Avaliação positiva
cbarley
Alunos da HubSpot
Alunos da HubSpot

Blog Post API throwing ssl.SSLCertVerificationError

resolver

Got it! Glad you were able to get some help. Just as an aside, we try to get to posts in under 2 business days in the forums. The US holiday sort of messed with that recently. One thing to consider, however, is if you post or edit your post multiple times in your thread, the thread gets bumped back to the top, so it's less likely we'll see it. We try to do our due diligence with addressing the oldest topics first, but sometimes they slip through the cracks since forums aren't the easiest method of support to use. Just wanted to make sure you knew what to expect here! Happy to help in these forums if you have other issues moving forward.

0 Avaliação positiva
josephLayden
Colaborador(a)

Blog Post API throwing ssl.SSLCertVerificationError

resolver

After posting in Slack. I have been notified to use Epoch time down to the millisecond. This successfully scheduled the correct date/time eliminating the 404 error. 404 error replaced by 500 error below:

500 b'<html>\r\n<head><title>500 Internal Server Error</title></head>\r\n<body bgcolor="white">\r\n<center><h1>500 Internal Server Error</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n' <Response [500]>

Updated function below:

#  Define JSON objects for each action
PUBLISH = {"action": "schedule-publish"}
CANCEL = {"action": "cancel-publish"}

def schedule_post(blog_post_id):
    """
    Publish, schedule or unpublish a blog post
    POST /content/api/v2/blog-posts/:blog_post_id/publish-action
   """
    xurl = "/content/api/v2/blog-posts/:" + str(blog_post_id) + "/schedule-publish?" + str(PORTAL_ID)
    url = HS_API_URL + xurl + APIKEY
    response = requests.post(url)
    headers = { "content-type" : "application/json" }
    response = requests.post(url, headers=headers, data=PUBLISH)
    print(response.status_code, response.content, response)
0 Avaliação positiva
josephLayden
Colaborador(a)

Blog Post API throwing ssl.SSLCertVerificationError

resolver

Further discussion in Slack confirms more errors. First off, .../schedule-publish is not the endpoint needed! Actually it is .../publish-action. Also, remove the : before the post ID. Additionally, any query parameters should be set up as key/value pairs, each pair separated by &. I also think HS API requires the secure HTTPS protocol. So the URL looks like:

https://api.hubapi.com/content/api/v2/blog-posts/[post_id]/publish-action?portalId=[portal_id]&hapikey=[api_key]


def publish_post(blog_post_id):
    """
    Publish, schedule or unpublish a blog post
    POST /content/api/v2/blog-posts/:blog_post_id/publish-action
    """
    xurl = "/content/api/v2/blog-posts/" + str(blog_post_id) + "publish-action?portalId=" + str(PORTAL_ID)
    url = HS_API_URL + xurl + APIKEY
    response = requests.post(url)
    headers = { "content-type" : "application/json" }
    response = requests.post(url, headers=headers, json=PUBLISH)
    print(response.status_code, response.content, response)

The result is an SSL certificate error. Does anyone have experience with fixing this issue?

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)
0 Avaliação positiva