Creating a quote via API missing quote template

Hi there!!!

I’m exercising Hubspot API to create a quote. I was able of creating a quote, including most of the fields within the quote. But I am unable of selecting a template for the quote, so it can not be finished.

I’m programming in javascript and when creating the quote I fetch to the URL ‘https://api.hubapi.com/crm/v4/objects/quotes’ for creating the quote. It works.

In the payload I include next properties:

properties: {

hs_title: `Title`,

hs_expiration_date: date_selected,

hs_comments: comments_selected,

hs_status: “DRAFT”,

hs_template_type: “QUOTE”,

hs_language: “es”,

hs_sender_firstname: ‘Romeo’,

hs_sender_lastname: ‘Santos’,

hs_sender_jobtitle: ‘Account Manager’,

hs_sender_company_name: ‘Company’,

hs_sender_email: ‘roma@paris.com’,

hs_sender_company_address: “Street 1223”,

hs_sender_company_city: “City”,

hs_sender_company_zip: “12345”,

hs_sender_company_country: “XXX”,

hs_currency : ‘EUR’

}

All the fields are correctly placed in the quote and quote is created as draft, but no template is selected.

I have tried both:

hs_template_type: “CUSTOMIZABLE_QUOTE_TEMPLATE”

hs_template_type: “QUOTE”

But none is working. When checking the created quote in the Hubspot web, it appears linked to the deal, but the template appears empty, pending to be selected.

How can I select a template to be added to the quote? What should I update or change for this purpose?

Hello!

Based on your message, I would suggest that try and do it with the association attribute:

Here is how I would do it. I would first get your Template ID via api, and then create the quote with the template association:

Step 1: Get Available Quote Templates

const axios = require(‘axios’);

async function getQuoteTemplates() {

const response = await axios.get(‘https://api.hubapi.com/crm/v3/objects/quote_templates’, {

headers: {

Authorization: `Bearer ${HUBSPOT_API_KEY}` } });

const templates = response.data.results;

console.log(“Available templates:”);

templates.forEach(template => { console.log(`Template ID: ${template.id}, Name: ${template.properties.name}`); });

// Return first template ID for demo purposes

return templates[0].id; }

Step 2: Create the quote with the Association to the template

async function createQuote(templateId) {

const quoteData = {

properties: {

hs_title: “ClientX - Website Redesign Project”,

hs_expiration_date: “2025-12-31”,

hs_status: “DRAFT”,

hs_currency: “USD”,

hs_language: “en” },

associations: [ { to: { id: templateId },

types: [ {

associationCategory: “HUBSPOT_DEFINED”,

associationTypeId: 286 // quote → quote template

} ] },

{ to: { id: 987654321 }, // replace with Deal ID types: [ { associationCategory: “HUBSPOT_DEFINED”, associationTypeId: 64 // quote → deal

} ] },

{ to: { id: 1111111 }, // replace with Line Item ID 1

types: [ { associationCategory: “HUBSPOT_DEFINED”,

associationTypeId: 67 // quote → line item } ] },

{ to: { id: 2222222 }, // replace with Line Item ID #2

types: [ { associationCategory: “HUBSPOT_DEFINED”, associationTypeId: 67 } ] },

{ to: { id: 3333333 }, // replace with Contact ID

types: [ { associationCategory: “HUBSPOT_DEFINED”, associationTypeId: 3 // quote → contact } ] } ] };

const response = await axios.post(‘https://api.hubapi.com/crm/v3/objects/quotes’,

quoteData, { headers: { Authorization: `Bearer ${HUBSPOT_API_KEY}`, ‘Content-Type’: ‘application/json’ } });

console.log(“Quote created with ID:”, response.data.id); }

Let me know if this helps or if you are still running into issues! Hope you have a great day!

Thank you very much BrandonWoodruff.

I could manage it reviewing the associations part as suggested by you.

I used for this purpose, to associate template to quote:

associateTemplateUrl = …/crm/v3/objects/quotes/${quoteId}/associations/quote_template/${templateId}/quote_to_quote_template;

and it worked.

Thank you very much