Morning!
We are currently scoping out the possibility of automating quote generation for some of our accounts.
I have code that
1. creates a new quote in draft state and adds in - the title, status, expiration date, language, esign enabled, some sender info, comments and terms.
2. associates the quote to a deal
3. associates the quote to a signing contact
4. associates the quote with a quote template (custom one)
5. creates a line item and associates that to the new quote and to the deal
However when we try to publish the quote it fails with a 400 error message.
We’ve checked the scopes on the private API which all seem present and accounted for but it is still erroring.
We’ve tested and manually clicking through the quote to the final page (just before published stage) and then running the code and it works! What am I missing that is in a manual click through (no changes made what soever on this click through) that is is not picking up in the code to publish?
Any help greatly appreciated. 
Hey @EWood-Malloy-- thanks for the details and doing some preliminary troubleshooting.
@zach_threadint has some suggestions in this thread that could be useful!
Could you also share the full 400 error? Does it give us any additional context?
Maybe some of our other Community members have some tips for troubleshooting. Hey @mangelet, @Gonzalo, @ChristinaKay anything you can add here?
Best,
Kennedy
Hi @kennedyp
Thank you for coming back to me and the link to the other thread.
The error mesage isn’t very helpful. It just says
Request failed with status code 400
I’ve tried the ‘hs_currency’ and this doesn’t seem to be the probelm either. We are default USD and the deal is USD i’m still getting the same error message as above.
I’ve added in a delay before publishing incase associating the line item wasn’t happening as quickly as I’d hoped. I also went through to the other thread linked in the thread you mentioned and can’t see anything there that would be causing the error either. We are doing it as a patch request and not a post request and all associations are being made before the quote needs to be published.
Each of the steps is a separate block of code in my workflow. Would that be casuing any issues? On checking the quote it does create it is all fine and seems to be setting things correctly to the same quote so it should have everything it needs to be published.
I am setting a signing contact. Do I need to also set them as the main ‘non signing’ contact in the code too? From looking at the quote it seems to infer that if they are the signer they are also a contact as well however.
I’m running out of ideas 
Hi @EWood-Malloy , does it help to make sure that there’s an hs_domain and hs_slug added when you try to publish?
You can look up code snippets for generating a random slug if needed.
It does help!!! Thank you very much @SAlexander43!!!
Looks like the domain isn’t set as default after i associate the quote template. Adding that in and the random slug has sorted it!
Hi! I’ve the same issue: However when we try to publish the quote it fails with a 400 error message.
How did you solved it?
Hi @Matgyron
My issue was solved by making sure the hs_domain and hs_slug were both being set by the code and then changing the hs_status to APPROVAL_NOT_NEEDED.
We did find that publishing via code was troublesome because you have to make sure everything is correct before you can do it.
So for us that was all the required properties that you usallly need when you process manaully.
The slug was probaby the most annoying part as it should be unique so my colleague used a function as below to set a random slug -
function generateRandomSlug(length = 20) {return crypto.randomBytes(Math.ceil(length / 2)).toString('hex') // Convert to hexadecimal format.slice(0, length) // Trim to the desired length.toLowerCase(); // Optional: make it lowercase for a cleaner slug}
hi @EWood-Malloy!
Thanks for your reply!
I’m using this custom code in attachemnt.
Basically it’s generating quote in draft with line items and contact association form deal. It’s missing quote custom template association and pubblish the quote. Can you help me to make it work?
1172568_1_quote custom code.txt (3.37 KB)
Hi @Matgyron
So I tend to use Python instead of Node so i’m not sure how it would work in terms of Node coding but similarly to where you have it associting to the line item you need to get it to also associate to a quote templete.
All the quote templates havea record id like all objects in HubSpot. We have a fixed template that we us all the time so for me it was just about associating to the same record Id each time.
Object type is “quote_template”
Association Type is “HUBSPOT_DEFINED”
Association Type ID is 286
Then the final thing would be to set the hs_status to APPROVAL_NOT_NEEDED
I hope that helps.
Hopefully that helps.