APIs & Integrations

MicoleDev
Membre

Custom Object Schema Creation

Hi,

 

I am testing Hubspot CRM for future integration into our platform.

 

After I try to create a custom object schema I get this exception error:

Authentication credentials not found. This API supports both API Key and OAuth 2.0 authenti (truncated...)

I dont understand the reason of not having access to it. When I go to the private app configuration I can see "crm.schemas.custom.write" in there.

 

MicoleDev_1-1664132341241.png


is this because I am using a demo account?


I can get access to every other endpoint.

I find weird in the documentation schema creation only has API login as an authentication method

MicoleDev_0-1664132795118.png

 

While every other endpoint allow us to use Oauth

MicoleDev_1-1664132852259.png

 

I feel schema objects very interesting for the integration, and would be great to be tested before we start to implement Hubspot in our company.

All the best

16 Réponses
FHaard
Membre

Custom Object Schema Creation

I had this issue, and it was resolved by creating a new private app and token after enterprise was activated on the account, the private app that was created before the enterprise trial was activated does not work.
YMMV but it WorkedForMe TM

0 Votes
LeeBartelme
HubSpot Employee
HubSpot Employee

Custom Object Schema Creation

I have no problem creating a custom object using my private app token. Are you sure you have at least one enterprise hub (custom objects are limited to enterprise tiers) and you are using the private app token correctly (as a header)?

 

That being said the beta should be accessible in your portal to create custom objects from the UI. Navigate to the "Product Updates" link in the dropdown in the top right of your potal. If you click on "Betas" you should see one labeled "Manage and Visualize Your Data Model". If you join that beta, you should be able to create custom objects from the portal settings.

 

LeeBartelme_1-1664285994331.png

 



LeeBartelme_0-1664285956933.png

 

0 Votes
FHaard
Membre

Custom Object Schema Creation

Hi,
is there a reason that this would not work on trial enterprise accounts? It's hard to evaluate if enterprise is worth it if a USP does not work in the trial, and it seems no schema interaction works using private apps on a trial enterprise account?

 

0 Votes
LeeBartelme
HubSpot Employee
HubSpot Employee

Custom Object Schema Creation

Can you share your code (with your Access Token removed) so we can see exactly what you are doing? I was able to create using the API and Access token using a trial enterprise hub.

0 Votes
FHaard
Membre

Custom Object Schema Creation

This is the request

from hubspot import HubSpot
import hubspot
from pprint import pprint
from hubspot.crm.schemas import ObjectSchemaEgg, ApiException

api_client = hubspot.Client.create(access_token=TOKEN)
labels = {
    "singular": "Test CO",
    "plural": "Test CO"
}
object_schema_egg = ObjectSchemaEgg(
    labels=labels,
    required_properties=["application_id", "status", "affiliate"],
    searchable_properties=["status"],
    primary_display_property="status",
    secondary_display_properties=[],
    properties=[{
        "name":"application_id",
        "label":"Application ID",
        "isPrimaryDisplayLabel": False},
                {
        "name":"status",
        "label":"Status",
                    "isPrimaryDisplayLabel": True},
                {
        "name":"affiliate",
        "label":"Affiliate",
                    "isPrimaryDisplayLabel": False}],
    associated_objects=["CONTACT"],
    name="testcustomschema")
try:
    api_response = api_client.crm.schemas.core_api.create(object_schema_egg=object_schema_egg)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling core_api->create: %s\n" % e)


and the response is

Exception when calling core_api->create: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Date': 'Fri, 07 Oct 2022 16:36:21 GMT', 'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '316', 'Connection': 'keep-alive', 'CF-Ray': '75680e1f483b9903-ARN', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Vary': 'origin, Accept-Encoding', 'CF-Cache-Status': 'DYNAMIC', 'Access-Control-Allow-Credentials': 'false', 'X-HubSpot-Auth-Failure': '401 Unauthorized', 'X-HubSpot-Correlation-Id': '4775757c-77a8-4b7c-934e-00e2310e68a4', 'Report-To': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=wXo1FpFtLOsOueMqu3zT2yVhdcW5StSUmVyUCRW16oRpyO4wCTSMVELyfdCQ8xy%2BjqIISf7kBKz4CcKsFIjpqvb7eIYZRk4nWYkrgxVT%2Bv7aUZpJvm6qWz4IExp3JMAT"}],"group":"cf-nel","max_age":604800}', 'NEL': '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}', 'Server': 'cloudflare', 'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400'})
HTTP response body: {"status":"error","message":"Authentication credentials not found. This API supports both API Key and OAuth 2.0 authentication and you can find more details at https://developers.hubspot.com/docs/methods/auth/oauth-overview","correlationId":"4775757c-77a8-4b7c-934e-00e2310e68a4","category":"INVALID_AUTHENTICATION"}

The same api client and token works for e.g. fetching custom objects if they're created using the beta UI

 

0 Votes
LeeBartelme
HubSpot Employee
HubSpot Employee

Custom Object Schema Creation

Can you try doing it just from like Postman? Just trying to see maybe if it's a client library thing? Also, I'm not familiar with Python at all. Just JS.

0 Votes
FHaard
Membre

Custom Object Schema Creation

curl --request POST \
                       --url 'https://api.hubapi.com/crm/v3/schemas' \
                       --header 'content-type: application/json' \
                       --header 'authorization: Bearer $TOKEN' \
                       --data '{
                   "name": "my_object",
                   "labels": {
                     "singular": "My object",
                     "plural": "My objects"
                   },
                   "primaryDisplayProperty": "my_object_property",
                   "requiredProperties": [
                     "my_object_property"
                   ],
                   "properties": [
                     {
                       "name": "my_object_property",
                       "label": "My object property",
                       "isPrimaryDisplayLabel": true
                     }
                   ],
                   "associatedObjects": [
                     "CONTACT"
                   ],
                   "metaType": "PORTAL_SPECIFIC"
                 }'

{"status":"error","message":"The scope needed for this API call isn't available for public use. If you have questions, contact support or post in our developer forum.","correlationId":"96e40266-00fd-4597-9bff-94bc4a9bc079","links":{"support":"https://help.hubspot.com/","forum":"https://community.hubspot.com/t5/APIs-Integrations/bd-p/integrations"},"category":"MISSING_SCOPES"}⏎ 

The documentation at https://developers.hubspot.com/docs/api/crm/crm-custom-objects actually suggests HAPI key here, which are going away in a month or so.

0 Votes
LeeBartelme
HubSpot Employee
HubSpot Employee

Custom Object Schema Creation

I don't know why on the example post request for the method they only list API Key. I'm just telling you it works in my own portal and a trial portal I have. I have postman setup and I'm not using API Keys and I'm able to create new custom objects just fine. They also list clearly the migration information on that page. It is supposed to work with private apps.

So I'm trying to isolate your issue to code or something else. If it works in Postman, we know it's code related. If it doesn't work in Postman, we know is' account, configuration, token related. 

0 Votes
FHaard
Membre

Custom Object Schema Creation

I edited my reply to include curl commnad and output
0 Votes
LeeBartelme
HubSpot Employee
HubSpot Employee

Custom Object Schema Creation

So in that case I'm not sure I can help. Below is my curl generated from Postman. There must be something else going on with the private app permissions or something I don't really know. The app I used had the following permissions.

LeeBartelme_0-1665167256023.png

It was a trial with marketing ent and sales ent trial. But either should get you custom objects (obviously since you can make them in the UI).

 

 

curl --location --request POST 'https://api.hubapi.com/crm/v3/schemas' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer XXX' \
--data-raw '{
  "labels": {
    "singular": "Object",
    "plural": "Objects"
  },
  "name": "Object",
  "properties": [
    {
      "fieldType": "text",
      "label": "Prop",
      "name": "prop",
      "type": "string"
    }
  ],
  "primaryDisplayProperty": "prop"
}'

 

 

 All I'd suggest at this point is to maybe create a new private app and grant it everything and just "see" if it works. I really don't know. Based on what I can see, it should work.

But as an aside, with the UI you really don't need that API anyway. It's no longer needed with it now being in the UI.

0 Votes
FHaard
Membre

Custom Object Schema Creation

I figured it out - the private app needs to be recreated after enterprise is activated, or you get these weird permission errors for some of the custom object endpoints (but not all).
Thanks for your assistance!

0 Votes
LeeBartelme
HubSpot Employee
HubSpot Employee

Custom Object Schema Creation

Cool, in that case, I would think rotating the token might have worked as well. (Possibly not). It might be worth testing if you still have the old app running. If you do try rotating the token and it works, let me know. Rotating the token I would think, would refresh all those permissions behind the scenes.

0 Votes
FHaard
Membre

Custom Object Schema Creation

I tried rotating the key on the old app earlier, and again just now, but no
difference - I re-checked the scopes as well and they match exactly on the
new (working) app and the old one.
0 Votes
LeeBartelme
HubSpot Employee
HubSpot Employee

Custom Object Schema Creation

Thanks, that's good information to know.

0 Votes
tominal
Guide | Partenaire solutions
Guide | Partenaire solutions

Custom Object Schema Creation

I agree with you that this is weird.

 

There is a pilot that you have to request access to allowing you to use OAuth to create schemas. That is the only good solution that I can see at this moment.

API keys are being sunsetted, so I am not sure what is going to happen with schema creation...

 

Creating a schema with a private app key results in this error:

 

tominal_0-1664146460398.png

 

Does anyone else have any ideas?


Thomas Johnson
Community Champion


Kahu Software LLC
A Texan HubSpot consulting firm
https://kahusoftware.com
0 Votes
FHaard
Membre

Custom Object Schema Creation

I don't have any ideas but have the 'not available for public use'issue if using curl, and the "Authentication credentials not found" if I use the Python client library.

0 Votes