Rest API - Sales Kits

Hello all.

We currently use rest api to add sales orders from our website into E10 but we are having some issues with Sales Kits. If a sales kit part is added via the website using API the other lines don’t seem to understand how to jump to the next line number automatically.

Anybody else have this? I have the same problem with Postman, I need to change the line from 1 to around 8 as the Sales Kit took 7 lines but are not showing up on the Sales Ordery Entry screen.

Thanks
Aaron.

In the REST API when you call the GetNewOrderDtl it should come in with the next available LineNum pre-assigned and then you make changes to everything besides the defaults and Update, no?

For SalesKit I think you need to use GetNewSalesKit

I’m posting this off

Erp.Bo.SalesOrderSvc/OrderDtls

How would I call those from that?

You can access the Custom Methods in swagger

https://YOURSERVER/Epicor10Prod/api/help/v1/methods/Erp.BO.SalesOrderSvc/index#!/Custom_methods/GetNewSalesKit


I’ve not used REST, but thought it processed similar to DMT (by using the underlying BO and Methods). So shouldn’t added lines use 0 (zero) for the OrderLine?

Hi Haso,

Do you understand php?

function loadOrderItems($dbconnection, $currentCust) 
	{
		$ret = array();
		for($i = 0; isset($_POST["partNum_".$i]); $i++) {
			$qty = $_POST["qty_".$i];
			if($qty > 0) {
				$item = false;
				if($_POST["custom_".$i]) {
					$item = new DealerOrderItem();
					$item->custom = 1;
					$item->partNum = $_POST["partNum_".$i];
					$item->customDescription = $_POST["customDescription_".$i];
					$item->description = "[".$item->partNum."] ".$item->customDescription;
				} else {
					if(is_object($part = PartMasterFeedDB::getSingleFromClause($dbconnection, "WHERE partNum = '".mysql_real_escape_string($_POST["partNum_".$i])."'"))) {					
						$item = new DealerOrderItem();
						$item->partNum = $part->partNum;
						$item->part = $part;
						$item->description = "[".$part->partNum."] ".$part->partDescription;
						$item->price = $part->getCustPrice($currentCust);
					}
				}
				if(is_object($item)) {
					$item->qty = max(0, ceil($qty));
					$item->comment = $_POST["comment_".$i];
					$ret[] = $item;
				}
			}
		}
		return $ret;

This is my Order Lines section.

I’m currently using as stated above. I’m not confident enough to use the custom methods. :confused: Any other suggestions/?

2 Likes

They’re added in a array e.g 1,2,3,4,5 for each line added to the form on the site.

How are you adding them to OrderDtl table, using the API Right or SQL?

They’re pushed using the API but the data for the part numbers and descriptions is dragged out of a SQL database well phpMyAdmin.

// Create the sales items
					$i = 1;
					foreach($orderItems as $orderItem) {
						$itm = [];
						if($orderItem->custom == 0) {
							$itm = [
								'Company' => "TEAGLE",
								'OrderNum' => $orderNum,
								'CustNum'   => $currentCust->custNum,
								'OrderLine'   => $i,
								'LineType'   => "PART",
								'PartNum'   => $orderItem->partNum,
								'OrderComment'   => $orderItem->comment,
								'SellingQuantity'  => strval($orderItem->qty)
							];
						} else {
							$itm = [
								'Company' => "TEAGLE",
								'OrderNum' => $orderNum,
								'CustNum'   => $currentCust->custNum,
								'LineType'   => "PART",
								'OrderLine'   => $i,
								'PartNum'   => $orderItem->partNum,
								'LineDesc'   => $orderItem->customDescription,
								'OrderComment'   => $orderItem->comment,
								'SellingQuantity'  => strval($orderItem->qty)
							];							
						}
						$status = 0;
						$result = set_data("Erp.BO.SalesOrderSvc/OrderDtls", $itm, $status);
						
						if(intval($status) != 201) {
							die("Failed to create the order details in ERP.\r\n" . json_encode($result));
						}

						$i++;

You will save yourself alot of headaches by using the Custom Method’s – there is alot of logic it handles for you. Such as looking if Backflush is enabled, setting the SellingQty properly etc…

I would recommend you go to POSTMAN and step through making a new order line on an order. It should take you few minutes.

The same concept will be in code then.

  • GetByID(orderNum)
  • GetNewOrderDtl
  • Update

In your php code basically each call should return the dataset you will keep passing like a ball to the next API Call

  1. GetByID(orderNum) : returns All Tables for that Order (OrderHed, OrderDtl, OrderRel…)
  2. GetNewOrderDtl : creates a new OrderDtl with defaults figured out and RowMod = “A”, you make changes
  3. Update
2 Likes

Yeah I’ve noticed the datasets in the methods that’s where it got ugly for me. I’m not the biggest of coders and this was a challenge in the first instance.

Thank you for the head ups. I will look into this and make some improvements as I go along… It’s been working flawlessly but the Sales Kits are just causing a little bit of a problem.

Thanks for your help haso. :wink:

Maybe @josecgomez or @jgiese.wci have a php starter boilerplate. I love php used it for years, but I dont have a quick example code to share. Maybe they have a helper function or class that makes it easier.

@aarong - was the line
$ret[] = $item; supposed to be $ret[i] = $item; ??

or possibly

array_push($ret, $item)

And if you search for PHP REST clients examples, you should find lots of help - even libraries like this: GitHub - tcdent/php-restclient: A generic REST API client for PHP

I have a php “library” i built to interact with Epicor REST v1. I believe it is posted somewhere on the site or I can dig it up later.

1 Like

image

1 Like

Php rest api - #6 by hkeric.wci this guy here

Sorry to bring this one up but I wanted to message as I’m in a similar spot. I use PHP to access the REST API and create sales orders. It’s been working without issue for a long time.

But in a recent post I made, we are seeing an issue with sales kits. It appears it’s not back flushing. Parts show up on the order and everything fires right in that way. It just doesn’t pull the parts from inventory for some reason.

I’m wondering if @aarong you ran into this problem and possibly solved it. If not, oh well.

Are you creating the lines yourself? If so then stop! Let epicor generate the lines for you.

If you arent generating the lines then look up the part for the part type being Kit and make sure in the foreach loop. Its added last as when kits are added they create several lines and it screws with the api foreach.

My solution was dropping the line creation.

1 Like

I just add the sales kit as a part to the SO. Let epicor do all the work.

I hate to say it but it looks like it’s working on my end.

I took the other coworkers word that it wasn’t working and I didn’t pull a time phase to see what was going on. I instead went looking at the API and checking everything was being entered properly on the sales order side. Everything was working so then I thought, check time phase. Sure enough it’s working as it should.

I think the issue here is they are saying inventory is off. Not because of Epicor but because of people in the warehouse not doing counts properly.

1 Like