APIs & Integrations

YLoesdau
Participant

adding products to a deal

SOLVE

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)
0 Upvotes
1 Accepted solution
Jaycee_Lewis
Solution
Community Manager
Community Manager

adding products to a deal

SOLVE

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
 

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

View solution in original post

0 Upvotes
1 Reply 1
Jaycee_Lewis
Solution
Community Manager
Community Manager

adding products to a deal

SOLVE

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
 

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes