[Crosspost] Adding Line Items To Quote Through V8 Rest API

This is a crosspost, my other post didnt get any comments on the general forum but I figure this is more of a developer question anyways.

I have been struggling with this for a few days and I have not been able to find any answers or create a workaround. My main goal is to add products to an account to show that they have been purchased. From what I understand, what I first need to do is create a quote, add a group of line items to the quote, add items to the group, and then mark that quote as closed_accepted for the items to populate on the account. This process works in the GUI just fine.

I am using the REST API V8 to accomplish this. From what I can tell, what I have needed to do is the following:

  1. Create an “AOS_Quotes”.
  2. Create an “AOS_Line_Item_Groups”.
  3. Create an “AOS_Products_Quotes”.
  4. Relate numbers 2 and 3 together.
  5. Relate numbers 1 and 2 together.

I have a few issues that I am running into though. They are the following:

  1. When trying to create an “AOS_Products_Quotes”, the information doesn’t autofill based any of the information I provide including the fields “product_id” or “part_number”. The “AOS_Products_Quotes” is created, it just simply doesnt fill in with information like it does in the GUI when selecting something.
  2. When trying to relate all three above items (quote, list item group, and product quote), I get back messages saying the products have been related but exploring them in the GUI gives no indication that they have been. None of the “AOS_Line_Item_Groups” ever show up in the “AOS_Quotes” that I create and none of the information populates.

I am happy to post my request URLs and body as I am very stuck and need as much help as I can get.

Bumping this a little but I have found a little more information. It looks like I dont need to make an “AOS_Line_Item_Groups”, just a “AOS_Products_Quotes”.

  1. Create an “AOS_Quotes”.
  2. Create an “AOS_Products_Quotes”.
  3. Relate numbers 1 and 2 together.

The issue I am running into now is that when I try and create an “AOS_Products_Quotes” based on information from “AOS_Products”, the information doesnt autofill like it does in the GUI. Then when I relate them, nothing really works right if that makes sense. I cant relate a product directly to a quote though, the API wants me to create a Product Quote first. So I somehow need to figure out how to fill it in.

I may have found a solution to the issue though it will still need some testing. Basically the following is what you would need to do:

  1. Create a quote
  2. Create a product quote
  3. Relate the product to the product quote
  4. Copy all the fields from the product into the product quote fields
  5. Relate the product quote to the quote
  6. (Optional) Update the quote with information like the running total
  7. Update the quote to Closed Accepted

This should give you enough information to create a quote and attach items. I will continue working on it and updating just in case someone from the future stumbles on this. I can save you a week or searching :wink:

1 Like

Thanks, this is useful. Your number 4 is probably over-kill, only a few fields should be necessary, I guess.

Have you checked the database schema?

–> https://schema--suitecrm-docs.netlify.app/schema/tables/aos_products_quotes

I had not seen that, thank you!

The only reason I mentioned step 4 is because upon visiting the GUI again, I had a lot of empty fields

The link that is “Butts” (sorry, I am just a man child working late at night trying to keep my self sane) actually leads to the right product. I think when creating the prodcut quote, just copy the fields you want to show up in the GUI correctly.

Thank you again for the DB schema link :slight_smile:

That subpanel will probably fetch the right stuff from the proper tables, once the relationships are well established. It’s a JOIN query.

Then suddenly, all that you have in your Butt will come out in the open. (couldn’t resist :stuck_out_tongue: )

1 Like

Just an update, did some testing and here is what should yield the best results:

  1. Create a quote and attach it to an account (I did this through the “billing_account_id” attribute). Sent to {{suitecrm.url}}/V8/module , here is an example body text:
{
  "data": {
    "type": "AOS_Quotes",
    "attributes": {
      "name": "New Quote Created",
      "billing_account_id": "ACCOUNT ID GOES HERE"
    }
  }
}
  1. Create a products quotes (AOS_Products_Quotes) with all the fields from the product that you need to. Sent to {{suitecrm.url}}/V8/module , here is an example body text:
{
  "data": {
    "type": "AOS_Products_Quotes",
    "attributes": {
      "name": "My name",
      "description": "My description.",
      "part_number": "10",
      "currency_id": "-99",
      "product_qty": "1",
      "product_list_price": "30.000000",
      "product_list_price_usdollar": "30.000000",
      "product_unit_price": "30.000000",
      "product_unit_price_usdollar": "30.000000",
      "product_total_price": "30.000000",
      "product_total_price_usdollar": "30.000000",
      "product_id": "PRODUCT ID GOES HERE",
      "parent_type": "AOS_Quotes",
      "parent_id": "QUOTE ID GOES HERE",
      "aos_quotes": "QUOTE ID GOES HERE"
    }
  }
}
  1. Relate the products quotes to the quote. Sent to {{suitecrm.url}}/V8/module/AOS_Quotes/QUOTE ID GOES HERE/relationships , here is an example body text
{
  "data": {
    "type": "AOS_Products_Quotes",
    "id": "PRODUCTS QUOTES ID"
  }
}
  1. Update the quote to Closed Accepted
{
  "data": {
    "type": "AOS_Quotes",
    "id": "QUOTE ID GOES HERE",
    "attributes": {	
      "stage": "Closed Accepted",
      "total_amount": "30.000000",
      "total_amount_usdollar": "30.000000"
    }
  }
}

This should be all you need to do for items to show up on the accounts page under the “Products and Services Purchased” section through the REST API. :slight_smile:

1 Like