Rest PHP multi-company Creating Order Company B Erp.BO.SalesOrderSvc/SalesOrders

Hello Epiusers!

Background:
After lurking for awhile I’ve managed to create a successful connection to my company and create and order header. Its very basic but it works! My next objective is to connect to the second company and inject an order header there instead. This is where my issue arises: CompanyB seems to require different fields for REST order creation.

Responses:
I have attempted to add to the post fields new fields based on the error messages returned. For example I received this response from the server and so I added “RateGrpCode”: “MAIN”:

BadRequest REST API Exception Site references invalid value. Rate Type Code references invalid value. Ice.Common.BusinessObjectException Site references invalid value. Rate Type Code references invalid value. Error OrderHed
Epicor.RESTApi.dll ThrowUpdateExtException 17 40

^this also caused me to add “Plant” and “ShipViaCode”.

And I continued to add more fields one at a time hoping to “complete” all the stealth “required” fields. I am stuck at this next response. I have been unable to identify the single field that could be assigned to meet the requirement:

BadRequest REST API Exception A valid Currency Rate Group is required. Ice.Common.BusinessObjectException A valid Currency Rate Group is required. Error OrderHed
Epicor.RESTApi.dll ThrowUpdateExtException 17 40

^I consider the possibility that it is referencing a table not a field… in which case I am unsure how to format the required input.

Searching:
I attempted to find the required fields in several places besides just checking the response codes and digging through fields. The ZData field looked promising in BAQ but I ended up just seeing the small list of required fields I working had for the main companies post fields. I have also searched the entire internet for an answer.

Questions:
Is there a better way for me to find the required fields for companyB?
Could this be some administrative setting I am unaware of?
Where is the Currency Rate Group located? If it is a table and not a field, how do I the data in post?

=========Additional Info==========

Rest call is to Erp.BO.SalesOrderSvc/SalesOrders

This is my working postfields for the main company:

CURLOPT_POSTFIELDS => ‘{
“CustNum”: 100,
“PONum”: “3003”,
“CurrencyCode”: “BASE”,
“TermsCode”: “30RW”}’

This is my incomplete postfields for company B:

CURLOPT_POSTFIELDS => ‘{
“Company”: “25556B”,
“CustNum”: 3,
“PONum”: “3001”,
“ShipViaCode”: “”,
“Plant”: “MfgSys”,
“RateGrpCode”: “MAIN”,
“CurrencyCode”: “BASE”,
“TermsCode”: “30RW”}’

Thank you for any guidance.

What REST version you use? v1?
Do you change CallSettings header when you connect to another company? Specifying Company field is not enough to change company.

2 Likes

I am using v1 of REST

I did not change CallSettings! I will research that now. Do you have any resources available to narrow my search?

Thank you.

If you search this forum, there’s a great write up called Rest Overview Novel that you should take a look at.
Also the Help in epicor is quite good.

Thanks @Aaron_Moreng but I’ve already looked through the Novel. I have managed to get orders to work from the shopify webhook all the way to the order being ready to ship with the main company. My issue comes when I try to create orders with the second company in our system. My issue seems more specific.

Did you try setting the custom call header?
from the swagger UI:

2 Likes

I am using basic authentication. I will try to add CallSettings to my CURLOPT_HTTPHEADER => array(). I will also add my full test code which is working with Company A. The failure happens when I try to change the Postfields to include the companyB.

My full working PHP Code (I’m sure there is some sloppyness in here I apologize):

Function ConnectPilot($order_number) {
ini_set(‘max_execution_time’, 300);
ini_set(‘memory_limit’, ‘1024M’); // or you could use 1G
$auth = base64_encode(“MYUSERNAME:MYPASSWORD”);
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options

curl_setopt_array($ch, array(

CURLOPT_URL => ‘https://cent…/api/v1/Erp.BO.SalesOrderSvc/SalesOrders’,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 300,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => ‘{
“CustNum”: 101,
“PONum”: "’ . $order_number . ‘",
“CurrencyCode”: “BASE”,
“Character01”: "Shopify_’ . $order_number . ‘",
“TermsCode”: “30RW”}’,

CURLOPT_HTTPHEADER => array(
"Authorization: Basic " . $auth,

“Accept: application/atom+xml”,
“Cache-Control: no-cache”,
“Content-Type: application/json”,
“Top: 20000”,
),
));

$response = curl_exec($ch);
$err = curl_error($ch);
$info = curl_getinfo($ch);

curl_close($ch);
}

Try something like this

Review how to setup that custom header and try to add it to every call with correct company.

@Olga @Aaron_Moreng that was the solution! Thank you.

I added this to the CURLOPT_HTTPHEADER => array( and it did the job!

‘CallSettings: {“Company”:“25558B”}’,

2 Likes