My Products
Help
kashyap
PARTNER

Anyway to create product, category, barcode(scancd) and pricematrix in one request

by kashyap

We are trying to create new product with new category.

Product have multiple barcodes and multiple prices like regular price and special price.

 

Can we create everything in one request?

1 REPLY 1
Accepted solution
omelhus
PARTNER

by omelhus

How dynamic can you build the query? By using the @export directive you can force the queries to run sequentially. I'm not sure where to stick the extra eanItemNos though.

 

mutation CreateProductWithGroup($cid: Int!, $cat: Int, $productNo: String) {
  useCompany(no: $cid) {
    productCategory_create(
      values: [{description: "demodemo"}]
      suggest: {productCategoryNo: true}
    ) {
      items {
        productCategoryNo @export(as: "cat")
      }
    }
    product_create(
      values: [{productNo: "1234-tes2t", description: "product description", productCategoryNo1: $cat, eanItemNo: "9999999999999"}]
    ) {
      items {
        productNo @export(as: "productNo")
      }
    }
    priceAndDiscountMatrix_create(
      values: [{productNo: $productNo, salesPrice1InCurrency: 123}, {productNo: $productNo, salesPrice1InCurrency: 99, customerPriceGroup1: 2}]
    ) {
      affectedRows
      items {
        productNo
        salesPrice1InCurrency
        customerPriceGroup1
      }
    }
  }
}