OpenAI access to HubSpot API

I am trying to create a natural language way of interacting with your Hubspot account by connecting the Hubspot API to OpenAI/Langchain. The script I am using is as follows:


HubSpotDocs =  """

The below is Hubspot API documentation showing how to create a contact. 

The endpoint is: 

"https://api.hubapi.com/crm/v3/properties/contacts". 

///Example request body to create a new contact
{
  "properties": {
    "email": "example@hubspot.com",
    "firstname": "Jane",
    "lastname": "Doe",
    "phone": "(555) 555-5555",
    "company": "HubSpot",
    "website": "hubspot.com",
    "lifecyclestage": "marketingqualifiedlead"
  }
}

Use the below authorisation:

curl -X GET https://api.hubapi.com/crm/v3/properties/contacts -H "Authorization: Bearer X"


"""


llm = ChatOpenAI(temperature=0, model= 'gpt-3.5-turbo-1106', openai_api_key="Y")

Test = APIChain.from_llm_and_api_docs(llm, HubSpotDocs,limit_to_domains=None, verbose=True)

Test.run("Create a new contact named Nasir.")​

The idea is that a user will be able to enter a prompt such as “Create contact X”, “Update contact Y” etc and the LLM (openAI) interprets this and then interacts with the Hubspot API to complete the action (hence why I have provided clear instructions for the LLM).

The problem I am facing is that I get the error message below as a response to my script:

“‘The API call to create a new contact named Nasir returned an error message stating that the user is unable to access the hubapi.com website. The error message indicates that the website is using a security service to protect itself from online attacks, and the action triggered a security solution. The user is advised to contact the site owner and provide the Cloudflare Ray ID for further assistance.’”

I do not face any issues creating new contacts (for instance) via the API WITHOUT using natural language.

This makes me think - is OpenAI access to Hubspot API data (even if it’s my own data) somehow restricted by Cloudflare? Or is there another reason the above error message is being generated? I am relatively new to all of this so forgive me if my thought process is completely off and sounds stupid.

Welcome to the forum.

It sounds like Hubspot API might be blocking it or not authorizing it correctly. You might need to reach out to them and explain what you’re doing - and give them the Cloudflare Ray ID…

1 Like

Thanks Paul. I will contact Cloudflare.

As a side question, generally speaking (outside of the Hubspot examples) is what I explained above possible without using LangChain? So can I just use OpenAI alone to “read” through an API doc then based on a natural language prompt make the relevant API calls and return data?