APIs & Integrations

gayathri139
Member

Webhook through accesstoken for private apps

SOLVE

Can we update the webhookurl or hit these endpoint "https://api.hubapi.com/webhooks/v3/appId/subscriptions" or "https://api.hubapi.com/webhooks/v3/appId/settings" with access token.I tried with api key it worked but i want to hit through access token to update my webhook settings ,Is it possible?If possible, How?

0 Upvotes
1 Accepted solution
Jaycee_Lewis
Solution
Community Manager
Community Manager

Webhook through accesstoken for private apps

SOLVE

Hey, @gayathri139 👋 Happy to help clarify things here. 

 

Looking at the documentation:

  • The Webhooks API can only be accessed using your Developer API key  — “Webhooks are set up for a HubSpot app, not individual accounts.”
  • You can set up and manage Webhooks via a Private App, but it must be done in-app – “You can also manage webhooks in a private app. In private apps, webhook settings can only be edited in the in-app settings for your private app, and cannot currently be edited through the API.”. Otherwise, if you try to use your Private App token using the Webhooks API, you'll get an error (as you noted) 

If you have a Public App (using OAuth) you can use the Developer API key and The Webhooks API to setup and manage your webhook subscriptions. If you are using a Private App, it must be done in-app. 

 

I hope this helps get you moving forward.

 

Best,

Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

View solution in original post

0 Upvotes
5 Replies 5
james-portant
Contributor

Webhook through accesstoken for private apps

SOLVE

Hi @gayathri139,

Yes, it is possible to update the webhook URL or hit the specified endpoints using an access token for private apps in HubSpot.
HubSpot is deprecating API keys in favor of OAuth access tokens, you should be able to perform these actions with an access token.

Here is a step-by-step guide on how to achieve this:

1. Obtain the Access Token

First, ensure you have the access token for your private app:

  1. Navigate to your HubSpot account.
  2. Go to Settings > Integrations > Private Apps.
  3. Create a new private app and ensure you have the appropriate scopes (permissions) for managing webhooks.
  4. Copy the access token provided.

2. Update Webhook Settings Using Access Token

You can use the access token to authenticate your requests to the HubSpot API. Here is an example using the curl command to update webhook settings.

Update Subscription Endpoint

To update webhook subscriptions, you can use the following curl command:

curl --request POST \ --url https://api.hubapi.com/webhooks/v3/{appId}/subscriptions \ --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ --header 'Content-Type: application/json' \ --data '{ "subscriptionDetails": { "eventType": "contact.creation", "propertyName": "email" } }'

Replace YOUR_ACCESS_TOKEN with your actual access token and {appId} with your app ID. Modify the subscriptionDetails as per your requirements.

Update Webhook URL Endpoint

To update the webhook URL settings, you can use the following curl command:

curl --request PUT \ --url https://api.hubapi.com/webhooks/v3/{appId}/settings \ --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ --header 'Content-Type: application/json' \ --data '{ "webhookUrl": "https://your-new-webhook-url.com", "maxConcurrentRequests": 5 }'

Replace YOUR_ACCESS_TOKEN with your actual access token, {appId} with your app ID, and https://your-new-webhook-url.com with your new webhook URL. You can also adjust maxConcurrentRequests as needed.

Example Using a Programming Language

If you prefer using a programming language like Python, here is an example using the requests library:

import requests # Replace with your actual values access_token = 'YOUR_ACCESS_TOKEN' app_id = 'YOUR_APP_ID' webhook_url = 'https://your-new-webhook-url.com' # Update webhook settings url = f'https://api.hubapi.com/webhooks/v3/{app_id}/settings' headers = { 'Authorization': f'Bearer {access_token}', 'Content-Type': 'application/json' } data = { "webhookUrl": webhook_url, "maxConcurrentRequests": 5 } response = requests.put(url, headers=headers, json=data) if response.status_code == 200: print("Webhook URL updated successfully.") else: print(f"Failed to update webhook URL: {response.status_code} - {response.text}")

 

Make sure your private app has the necessary scopes to manage webhooks. Using the Authorization: Bearer YOUR_ACCESS_TOKEN header in your requests will authenticate them correctly.

If you encounter any issues, double-check your access token and permissions, and ensure your requests are correctly formatted. 

Good luck and please give me a shout if I can help with anything.

Cheers,
James - CEO @ Portant

Portant App for HubSpot: https://ecosystem.hubspot.com/marketplace/apps/sales/sales-enablement/portant-hubspot-google-docs-in...

0 Upvotes
gayathri139
Member

Webhook through accesstoken for private apps

SOLVE

i tried hitting the curls you provided and i got this as response, and could you please share the scopes that are required to hit these.

{
    "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": "30d4e060-e524-4211-8715-5e7f724eba11",
    "links": {
        "support": "https://help.hubspot.com/",
    },
    "category": "MISSING_SCOPES"
}
0 Upvotes
james-portant
Contributor

Webhook through accesstoken for private apps

SOLVE

Sorry @gayathri139 , maybe I copied it wrong:
curl --request PUT \
--url 'https://api.hubapi.com/webhooks/v3//settings?hapikey=YOUR_HUBSPOT_DEVELOPER_API_KEY' \
--header 'content-type: application/json' \
--data '{
"throttling": {
"period": "SECONDLY",
"maxConcurrentRequests": 5
},
"targetUrl": "https://www.example.com/hubspot/target"
}'

Found here: https://developers.hubspot.com/docs/api/webhooks

For scopes:

  • Go to Settings > Integrations > Private Apps.
  • Select your private app.
  • Ensure that the following scopes are enabled:
    • webhooks
    • Any other specific scopes required for your API operations (e.g., contacts if you are dealing with contact creation).

I hope that works this time.


Cheers,

 

James

 

0 Upvotes
gayathri139
Member

Webhook through accesstoken for private apps

SOLVE

Hii James, Thanks for the time and assistance.
You provided the curl to hit it with api key, but i need it to hit through ACCESS TOKEN,Thats my actual requirement. You again provided the curl which i have already tried and got the response using api key. 

0 Upvotes
Jaycee_Lewis
Solution
Community Manager
Community Manager

Webhook through accesstoken for private apps

SOLVE

Hey, @gayathri139 👋 Happy to help clarify things here. 

 

Looking at the documentation:

  • The Webhooks API can only be accessed using your Developer API key  — “Webhooks are set up for a HubSpot app, not individual accounts.”
  • You can set up and manage Webhooks via a Private App, but it must be done in-app – “You can also manage webhooks in a private app. In private apps, webhook settings can only be edited in the in-app settings for your private app, and cannot currently be edited through the API.”. Otherwise, if you try to use your Private App token using the Webhooks API, you'll get an error (as you noted) 

If you have a Public App (using OAuth) you can use the Developer API key and The Webhooks API to setup and manage your webhook subscriptions. If you are using a Private App, it must be done in-app. 

 

I hope this helps get you moving forward.

 

Best,

Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes