# Creating and Publishing Quotes via API

**URL:** <https://community.hubspot.com/t/creating-and-publishing-quotes-via-api/97375>\
**Category:** APIs & Integrations\
**Tags:** developer-tools\
**Created:** [January 8, 2024, 11:55pm UTC](https://community.hubspot.com/t/creating-and-publishing-quotes-via-api/97375 "2024-01-08T23:55:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JFenchel](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@JFenchel](https://community.hubspot.com/u/JFenchel)\
**Post date:** [January 8, 2024, 11:55pm UTC](https://community.hubspot.com/t/creating-and-publishing-quotes-via-api/97375/1 "2024-01-08T23:55:47Z")

</div>

I’m using Zapier to create and publish quotes automatically via api calls. It’s all working pretty well, except that all of our quotes are defaulting to the wrong domain. When I create a new quote template it defaults to our [blog.company.com](http://blog.company.com) domain, and I always change it to our [invoice.company.com](http://invoice.company.com) domain.

When I manually create or edit quotes they use the [invoice.company.com](http://invoice.company.com) domain but if I create and publish a quote strictly through api, it uses [blog.company.com](http://blog.company.com), until I go in and manually unpublish and republish it. Does anyone know why this happens or can anyone help me?

Here’s a boiled down version of the code I’m using. I added an extra step of changing the quote template in hopes that would help but it didn’t. I have also tried unpublishing and republishing the quote via api and that doesn’t help.

```lia-code-sample
async function doStuff(){
theDate=Date.parse('10/20/2024')
console.log(theDate)

var url = 'https://api.hubapi.com/crm/v3/objects/quotes';

var data = {
 properties: {
 hs_title: 'Subscription Quote: test',
 hs_expiration_date: theDate,
 hs_status: "DRAFT",
 hs_language: "en",
 hs_sender_email: 'jeff@breatheforchange.com',
 },
 associations: [
 {
 to: {
 id: 287996186925 // This should be replaced with the actual ID you want to associate with
 },
 types: [
 {
 associationCategory: "HUBSPOT_DEFINED",
 associationTypeId: 286
 }
 ]
 }
 ]

};

var options = {
 method: 'POST',
 headers: {
 'Authorization': `Bearer ${hapi-key}}`,
 'Content-Type': 'application/json'
 },
 body: JSON.stringify(data)
};
var response=await fetch(url, options)
var responseData=await response.json()
var quoteId=responseData.properties.hs_object_id
console.log(responseData);
url=`https://api.hubapi.com/crm/v4/objects/quotes/${quoteId}/associations/default/quote_template/285843884972`
options = {
 method: 'PUT',
 headers: {
 'Authorization': `Bearer ${hapi-key}}`,
 'Content-Type': 'application/json'
 },
};
response=await fetch(url,options)
responseData=await response.json()
url=`https://api.hubapi.com/crm/v4/objects/quotes/${quoteId}/associations/default/deals/16807831318`
response=await fetch(url,options)
responseData=await response.json()
url=`https://api.hubapi.com/crm/v4/objects/quotes/${quoteId}/associations/default/line_items/7922834188`
response=await fetch(url,options)
responseData=await response.json()
url=`https://api.hubapi.com/crm/v4/objects/quotes/${quoteId}/associations/default/contacts/4114597`
response=await fetch(url,options)
responseData=await response.json()

response = await fetch(
 `https://api.hubapi.com/crm/v3/objects/quotes/${quoteId}`,
 {
 method: 'PATCH',
 headers: {
 'Authorization': `Bearer ${hapi-key}}`,
 'Content-Type': 'application/json',
 },
 body: JSON.stringify({
 properties: {
 hs_status: "APPROVAL_NOT_NEEDED", 
 }
 })
 }
);

console.log('Response status:', response.status);

const text = await response.text();
console.log('Update expiration date response text:', text);

console.log(responseData);
url=`https://api.hubapi.com/crm/v3/objects/quotes/${quoteId}`
options = {
 method: 'GET',
 headers: {
 'Authorization': `Bearer ${hapi-key}}`,
 'Content-Type': 'application/json'
 },
};
response=await fetch(url,options)
responseData=await response.json()
console.log(responseData);

}
doStuff();

```

---

<div class="post-metadata">

**Author:** ![Syeda\_Fatima](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/syeda_fatima/32/36951_2.png) [@Syeda\_Fatima](https://community.hubspot.com/u/Syeda_Fatima)\
**Post date:** [January 9, 2024, 11:01am UTC](https://community.hubspot.com/t/creating-and-publishing-quotes-via-api/97375/2 "2024-01-09T11:01:14Z")

</div>

Hey @JFenchel

I think you’re encountering an issue where quotes created through the API default to the wrong domain. I have some suggestions to troubleshoot and resolve the problem:

Ensure that the quote template association is set correctly in your API call. Double-check the quote template ID and make sure it is associated with the correct domain.

Then check whether the quote template is set as the default in your HubSpot settings. If the wrong default template is selected, it may override your API call.

Check the details of the quote template associated with your quotes. Ensure that the correct domain is specified within the template settings. Manually review and update the domain within the HubSpot quote template.

### 

Explicitly include the domain information in your API request. Add a property to your quote creation data that specifies the desired domain.

`var data = { properties: { hs_title: 'Subscription Quote: test', hs_expiration_date: theDate, hs_status: "DRAFT", hs_language: "en", hs_sender_email: 'jeff@breatheforchange.com', custom_domain: 'invoice.company.com', // Add this line }, // ... (rest of your code) };`

Ensure that default settings within HubSpot are configured correctly. Check configurations related to domains, quotes, and any relevant settings that might impact the behavior you’re experiencing.

---

<div class="post-metadata">

**Author:** ![JFenchel](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@JFenchel](https://community.hubspot.com/u/JFenchel)\
**Post date:** [January 9, 2024, 2:43pm UTC](https://community.hubspot.com/t/creating-and-publishing-quotes-via-api/97375/3 "2024-01-09T14:43:14Z")

</div>

Thanks for the suggestions! I had tried most of those things, but I was using the wrong domain property. The proper domain property to set is hs\_domain and I was trying to set hs\_proposal\_domain which is read only.
