• Help Desk reporting gives you real-time visibility into your support operation without the manual work. Ask our experts about which metrics matter most! AMA Dec 8-12.

    Ask us anything

adding products to a deal

YLoesdau
Participant

How would I add products to a deal via API integration?

Currently I am having issues with the access token. I created a private app, inserted the client ID and client secret but what is the refresh token?

My current python code is the following:

CLIENT_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
CLIENT_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxx'
REFRESH_TOKEN = 'xxxxxxxxxxxxxxxxxxxxx'
DEAL_ID = 'xxxxxxxxxxxxx'
PRODUCT_ID = 'xxxxxxxxxxxxxxxxxxxxxxx'
QUANTITY = 1  # Setze die Anzahl des Produkts hier ein

# OAuth-Endpunkt zum Abrufen eines Zugriffstokens mithilfe des Aktualisierungstokens
payload = {
    "grant_type": "refresh_token",
    "client_id": CLIENT_ID,
    "client_secret": CLIENT_SECRET,
    "refresh_token": REFRESH_TOKEN
}

# Anfrage für das Zugriffstoken
response = requests.post(token_url, data=payload)
access_token = response.json()['access_token']

# Endpoint für das Hinzufügen eines Produkts zu einem Deal
url = f"https://api.hubapi.com/crm/v3/objects/deals/{DEAL_ID}/products/{PRODUCT_ID}"

# Setze den Header für die Autorisierung
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}

# Erstelle das Anfrage-Payload mit der Anzahl des Produkts
payload = {
    "quantity": QUANTITY
}

# Sende die Anfrage, um das Produkt zum Deal hinzuzufügen
response = requests.put(url, headers=headers, json=payload)

# Überprüfe die Antwort
if response.status_code == 200:
    print("Produkt wurde erfolgreich zum Deal hinzugefügt.")
else:
    print("Fehler beim Hinzufügen des Produkts zum Deal:", response.text)
1 Accepted solution
Jaycee_Lewis
Solution
Thought Leader

Hey, @YLoesdau 👋 One question. Are you trying to add Line Items (created from a Product) or are you trying to link a Product directly to the deal? Here's the documentation on how to do this — Associate Products.

 

Talk soon! — Jaycee
 





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




View solution in original post

2 Replies 2
JohnMaret
Contributor

As a workaround, tools like LineNer let you add, remove (delete) or update line items automatically via workflows, so reps don’t need to touch the product field manually. Many HubSpot users enjoy using the app and find the automation it offers extremely helpful.  Thanks

Jaycee_Lewis
Solution
Thought Leader

Hey, @YLoesdau 👋 One question. Are you trying to add Line Items (created from a Product) or are you trying to link a Product directly to the deal? Here's the documentation on how to do this — Associate Products.

 

Talk soon! — Jaycee
 





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More