Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listings API #379

Closed
matija-tree opened this issue Jan 30, 2025 · 2 comments
Closed

Listings API #379

matija-tree opened this issue Jan 30, 2025 · 2 comments

Comments

@matija-tree
Copy link

Hello, recently Listings has been added as a new Hubspot object. I notice it isn't in the API library. Are there plans to add it anytime soon e.g. most of the API seems to be auto-generated and would you be able regenerate the SDK to include Listings? If not, can one open a PR to add this as we do need this quite quickly.

@itsbrex
Copy link

itsbrex commented Feb 10, 2025

Any word on this?

@matija-tree
Copy link
Author

matija-tree commented Feb 11, 2025

@itsbrex
I managed to find that Listings has an internal hubspot ID e.g. 0-420 so can be accessed as:

`

endpoint = "https://api.hubapi.com/crm/v3/objects/0-420"
# Set up the headers with the access token
hubspot_access_token = os.getenv("hubspot_access_token")
headers = {
    "Authorization": f"Bearer {hubspot_access_token}",
    "Content-Type": "application/json",
}
all_results = []
after = None  # Start without an after cursor
custom_properties = ["hs_object_id", "hs_createdate", "hs_lastmodifieddate"]
params = {
    "limit": 100,  # Adjust limit as needed
    "properties": ",".join(custom_properties),  # Request specific properties
}

while True:
    # Construct the request URL with pagination if needed
    if after:
        params["after"] = after

    # Make the request
    response = requests.get(endpoint, headers=headers, params=params)
    data = response.json()

    # Collect results
    all_results.extend(data.get("results", []))

    # Check if there's a next page
    paging = data.get("paging", {})
    after = paging.get("next", {}).get("after")

    # Break the loop if there's no more data
    if not after:
        break

`

This is for fetching, e.g. use the same approach for updating or creating listings.

Creating a new listings object:

`

endpoint = "https://api.hubapi.com/crm/v3/objects/0-420"
# Set up the headers with the access token
hubspot_access_token = os.getenv("hubspot_access_token")
headers = {
    "Authorization": f"Bearer {hubspot_access_token}",
    "Content-Type": "application/json",
}
payload = {
    "properties": {
        "hs_name": name,
        "project_country": country,
        "project_files": project_files,
    }
}
response = requests.post(
    endpoint,
    headers=headers,
    data=json.dumps(payload),
)
new_listing = response.json()`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants