1+ # @generated
2+ # File generated from our OpenAPI spec
3+
14from typing import Any , Dict , Optional , Awaitable
25import asyncio
36import inspect
47import copy
58import httpx
69import time
710import json
11+ from .services .ad_publishing .ad_publishing import AdPublishing
12+ from .services .affiliate_manager .affiliate_manager import AffiliateManager
13+ from .services .agent_studio .agent_studio import AgentStudio
814from .services .associations .associations import Associations
915from .services .blogs .blogs import Blogs
16+ from .services .brand_boards .brand_boards import BrandBoards
1017from .services .businesses .businesses import Businesses
1118from .services .calendars .calendars import Calendars
1219from .services .campaigns .campaigns import Campaigns
20+ from .services .chat_widget .chat_widget import ChatWidget
1321from .services .companies .companies import Companies
1422from .services .contacts .contacts import Contacts
23+ from .services .conversation_ai .conversation_ai import ConversationAi
1524from .services .conversations .conversations import Conversations
1625from .services .courses .courses import Courses
1726from .services .custom_fields .custom_fields import CustomFields
2130from .services .forms .forms import Forms
2231from .services .funnels .funnels import Funnels
2332from .services .invoices .invoices import Invoices
33+ from .services .knowledge_base .knowledge_base import KnowledgeBase
2434from .services .links .links import Links
2535from .services .locations .locations import Locations
2636from .services .marketplace .marketplace import Marketplace
3242from .services .phone_system .phone_system import PhoneSystem
3343from .services .products .products import Products
3444from .services .proposals .proposals import Proposals
35- from .services .saas_api . saas_api import SaasApi
45+ from .services .saas . saas import Saas
3646from .services .snapshots .snapshots import Snapshots
37- from .services .social_media_posting . social_media_posting import SocialMediaPosting
47+ from .services .social_planner . social_planner import SocialPlanner
3848from .services .store .store import Store
3949from .services .surveys .surveys import Surveys
4050from .services .users .users import Users
4555from .logging import Logger
4656from .webhook import WebhookManager
4757from .constants import UserType
58+ from importlib .metadata import version as _pkg_version , PackageNotFoundError
59+
60+ # SDK version, read from the installed package metadata and sent in each request
61+ try :
62+ SDK_VERSION = _pkg_version ("gohighlevel-api-client" )
63+ except PackageNotFoundError :
64+ SDK_VERSION = "unknown"
4865
4966
5067class HighLevel :
5168 """HighLevel SDK Client"""
5269
5370 BASE_URL = "https://services.leadconnectorhq.com"
71+ API_VERSION = "v3"
5472
5573 def __init__ (
5674 self ,
@@ -60,8 +78,7 @@ def __init__(
6078 agency_access_token : Optional [str ] = None ,
6179 location_access_token : Optional [str ] = None ,
6280 session_storage : Optional [SessionStorage ] = None ,
63- log_level : Optional [str ] = None ,
64- api_version : Optional [str ] = None
81+ log_level : Optional [str ] = None
6582 ):
6683 # Validate configuration
6784 if not private_integration_token and (not client_id or not client_secret ):
@@ -74,7 +91,6 @@ def __init__(
7491
7592 # Set default configuration
7693 self .config = {
77- "api_version" : api_version or "2021-07-28" ,
7894 "private_integration_token" : private_integration_token ,
7995 "agency_access_token" : agency_access_token ,
8096 "location_access_token" : location_access_token ,
@@ -114,7 +130,8 @@ def _get_default_headers(self) -> Dict[str, str]:
114130 """Generate default headers for HTTP requests"""
115131 headers = {
116132 "Content-Type" : "application/json" ,
117- "Version" : self .config ["api_version" ]
133+ "Version" : self .API_VERSION ,
134+ "GHL-SDK-Version" : f"python/{ SDK_VERSION } " ,
118135 }
119136
120137 # Priority 1: private_integration_token
@@ -214,7 +231,7 @@ async def _refresh_token_if_needed(self, resource_id: str, session_data: ISessio
214231 })
215232
216233 self .logger .info (f"Token refreshed successfully for { resource_id } " )
217- return f"Bearer { new_token_data [ 'access_token' ] } "
234+ return f"Bearer { new_token_data . get ( 'access_token' ) or new_token_data . get ( 'accessToken' ) } "
218235
219236 except Exception as error :
220237 self .logger .error (f"Failed to refresh token for { resource_id } : { error } " )
@@ -276,7 +293,7 @@ async def _handle_location_token_fallback(self, location_id: str, location_sessi
276293 })
277294
278295 self .logger .info (f"Location token fetched successfully using company token fallback for location_id: { location_id } " )
279- return f"Bearer { new_location_token_data [ 'access_token' ] } "
296+ return f"Bearer { new_location_token_data . get ( 'access_token' ) or new_location_token_data . get ( 'accessToken' ) } "
280297
281298 except Exception as error :
282299 self .logger .error (f"Failed to handle location token fallback for location_id: { location_id } : { error } " )
@@ -388,13 +405,19 @@ def extract_resource_id(
388405
389406 def _initialize_services (self ) -> None :
390407 """Initialize all service instances with the HighLevel instance"""
408+ self .ad_publishing = AdPublishing (self )
409+ self .affiliate_manager = AffiliateManager (self )
410+ self .agent_studio = AgentStudio (self )
391411 self .associations = Associations (self )
392412 self .blogs = Blogs (self )
413+ self .brand_boards = BrandBoards (self )
393414 self .businesses = Businesses (self )
394415 self .calendars = Calendars (self )
395416 self .campaigns = Campaigns (self )
417+ self .chat_widget = ChatWidget (self )
396418 self .companies = Companies (self )
397419 self .contacts = Contacts (self )
420+ self .conversation_ai = ConversationAi (self )
398421 self .conversations = Conversations (self )
399422 self .courses = Courses (self )
400423 self .custom_fields = CustomFields (self )
@@ -404,6 +427,7 @@ def _initialize_services(self) -> None:
404427 self .forms = Forms (self )
405428 self .funnels = Funnels (self )
406429 self .invoices = Invoices (self )
430+ self .knowledge_base = KnowledgeBase (self )
407431 self .links = Links (self )
408432 self .locations = Locations (self )
409433 self .marketplace = Marketplace (self )
@@ -415,9 +439,9 @@ def _initialize_services(self) -> None:
415439 self .phone_system = PhoneSystem (self )
416440 self .products = Products (self )
417441 self .proposals = Proposals (self )
418- self .saas_api = SaasApi (self )
442+ self .saas = Saas (self )
419443 self .snapshots = Snapshots (self )
420- self .social_media_posting = SocialMediaPosting (self )
444+ self .social_planner = SocialPlanner (self )
421445 self .store = Store (self )
422446 self .surveys = Surveys (self )
423447 self .users = Users (self )
@@ -551,10 +575,6 @@ def get_client_secret(self) -> Optional[str]:
551575 """Get current client secret"""
552576 return self .config .get ("client_secret" )
553577
554- def set_api_version (self , version : str ) -> None :
555- """Set API version"""
556- self .update_config ({"api_version" : version })
557-
558578 def get_config (self ) -> Dict [str , Any ]:
559579 """Get current configuration"""
560580 return {** self .config }
0 commit comments