How to export an invoice or current instruction using the Acumatica SOAP API via PHP?
I can generate PHP SOAP stub classes using https://www.wsdltophp.com/
Most of the examples I found use .Net
The WSDL my client provided me with is: http://erp.triode.co.nz/pmsdb/Soap/INEXPORT.asmx?WSDL
From what I see, it seems that Acumatica has several WSDLs for different procedures. If someone could give me a point in the right direction, that would be great. I can authenticate with the Acumatica endpoint, I just get stuck on where to start this use case.
*** UPDATE ****
OK. I am now using Acumatica PHP helper files, which are very useful, but unfortunately got stuck again trying to export a list of invoices for a single client:
<?php ini_set('memory_limit','512M'); ini_set('display_errors',true); error_reporting(-1); require_once('AcumaticaGate.php'); //$wsdl = "http://erp.triode.co.nz/pmsdb/Soap/AR402000.asmx?WSDL"; // $client = new AcumaticaGate('<user_login>', '<user_password>', '<folder_name>','http://<computer>/<website>'); //Can't provide credentials for security reasons unfortunately $un = "" $pw = ""; $client = new AcumaticaGate($un, $pw, 'AR402000','http://erp.triode.co.nz/pmsdb'); $customer_id = "DAR"; $doctype = "Invoice"; $selection = $client->Schema->GetSchemaResult->Selection; $customer = $selection->Customer = $customer_id; $all_docs = $selection->ShowAllDocuments = true; $unreleased = $selection->IncludeUnreleasedDocuments = true; $type_doc = $client->Schema->GetSchemaResult->Documents->TypeDisplayDocType; // FILTERS $filters = array(); array_push($filters, $client->PrepareSimpleFilter(clone $type_doc, FilterCondition::Equals, $doctype)); $export_param = new Export(); $export_param->commands = array($customer, $all_docs, $unreleased); $export_param->filters = $filters; $export_param->breakOnError = true $export_param->includeHeaders = false; $export_param->topCount = 0; $export = $client->Client->Export($export_param); echo "<pre>"; print_r($export); echo "</pre>"; // echo $client->Client->__getLastRequest(); ?>
Getting error:
Fatal error: SoapFault exception: [soap: Server] System.Web.Services.Protocols.SoapException: the server could not process the request. ---> System.NullReferenceException: the reference to the object is not installed in the instance of the object. in PX.Api.SyImportContext.ParseCommand (SyCommand cmd) in PX.Api.SyExportContext.a (SYMappingField A_0) in System.Linq.Enumerable.WhereSelectArrayIterator 2.MoveNext() at System.Collections.Generic.List 1..ctor IEnumerable 1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable 1 source) in PX. Api.SyExportContext..ctor (matching SYMapping, IEnumerable 1 fields, String[] providerFields, Dictionary 2 viewFilters, Boolean breakOnError, Int32 start, Int32 count, LinkedSelectorViews selectorViews, String rowFilterField) in PX.Api.ScreenUtils.ExportInternal ( Commands line 549
This is the .Net method I'm trying to reverse engineer:
Example 4.3.4: Obtaining a list of customer invoices This example, which is provided for reference only, shows how to obtain a list of invoices for a customer (by customer ID) in the form of customer information (AR402000; Finance> Accounts Receivable> Work Area> Explore).
class CustomerDetail {
UPDATE
The script has been updated and now receives an empty response from the API endpoint, at least it is not an error, but still remains unfortunately, therefore accepts, but returns nothing:
NEW CODE
<?php ini_set('memory_limit','512M'); ini_set('display_errors',true); error_reporting(-1); require_once('AcumaticaGate.php'); //$wsdl = "http://erp.triode.co.nz/pmsdb/Soap/INEXPORT.asmx?WSDL"; // $client = new AcumaticaGate('<user_login>', '<user_password>', '<folder_name>','http://<computer>/<website>'); $un = ""; $pw = ""; $client = new AcumaticaGate($un, $pw, 'AR402000','http://erp.triode.co.nz/pmsdb'); $customer_id = "3678"; $doctype = "Invoice"; $selection = $client->Schema->GetSchemaResult->Selection; $customer = $selection->Customer; $all_docs = $selection->ShowAllDocuments; $unreleased = $selection->IncludeUnreleasedDocuments; $type_doc = $client->Schema->GetSchemaResult->Documents->TypeDisplayDocType; $command = array(); array_push($command, $client->PrepareValue($customer_id, $customer)); array_push($command, $client->PrepareValue('true', $all_docs)); array_push($command, $client->PrepareValue('true', $unreleased)); // FILTERS $filters = array(); array_push($filters, $client->PrepareSimpleFilter(clone $type_doc, FilterCondition::Equals, $doctype)); array_push($filters, $client->PrepareSimpleFilter(clone $customer, FilterCondition::Equals, $customer_id)); $export_param = new Export(); $export_param->commands = $command; $export_param->filters = $filters; $export_param->breakOnError = true; $export_param->includeHeaders = false; $export_param->topCount = 0; $export = $client->Client->Export($export_param); // echo "<pre>"; // print_r($export); // echo "</pre>"; echo $client->Client->__getLastRequest(); ?>
SOAP XML REQUEST
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP- ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.acumatica.com/typed/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <ns1:Export> <ns1:commands> <ns1:Command xsi:type="ns1:Value"> <ns1:Value>3678</ns1:Value> <ns1:LinkedCommand xsi:type="ns1:Field"> <ns1:FieldName>CustomerID</ns1:FieldName> <ns1:ObjectName>Filter</ns1:ObjectName> <ns1:Value>Customer</ns1:Value> <ns1:Commit>true</ns1:Commit> </ns1:LinkedCommand> </ns1:Command> <ns1:Command xsi:type="ns1:Value"> <ns1:Value>true</ns1:Value> <ns1:LinkedCommand xsi:type="ns1:Field"> <ns1:FieldName>ShowAllDocs</ns1:FieldName> <ns1:ObjectName>Filter</ns1:ObjectName> <ns1:Value>ShowAllDocuments</ns1:Value> <ns1:Commit>true</ns1:Commit> </ns1:LinkedCommand> </ns1:Command> <ns1:Command xsi:type="ns1:Value"> <ns1:Value>true</ns1:Value> <ns1:LinkedCommand xsi:type="ns1:Field"> <ns1:FieldName>IncludeUnreleased</ns1:FieldName> <ns1:ObjectName>Filter</ns1:ObjectName> <ns1:Value>IncludeUnreleasedDocuments</ns1:Value> <ns1:Commit>true</ns1:Commit> </ns1:LinkedCommand> </ns1:Command> </ns1:commands> <ns1:filters> <ns1:Filter> <ns1:Field> <ns1:FieldName>DisplayDocType</ns1:FieldName> <ns1:ObjectName>Documents</ns1:ObjectName> <ns1:Value>TypeDisplayDocType</ns1:Value> </ns1:Field> <ns1:Condition>Equals</ns1:Condition> <ns1:Value xsi:type="xsd:string">Invoice</ns1:Value> <ns1:OpenBrackets>0</ns1:OpenBrackets> <ns1:CloseBrackets>0</ns1:CloseBrackets> <ns1:Operator>And</ns1:Operator> </ns1:Filter> <ns1:Filter> <ns1:Field> <ns1:FieldName>CustomerID</ns1:FieldName> <ns1:ObjectName>Filter</ns1:ObjectName> <ns1:Value>Customer</ns1:Value> <ns1:Commit>true</ns1:Commit> </ns1:Field> <ns1:Condition>Equals</ns1:Condition> <ns1:Value xsi:type="xsd:string">3678</ns1:Value> <ns1:OpenBrackets>0</ns1:OpenBrackets> <ns1:CloseBrackets>0</ns1:CloseBrackets> <ns1:Operator>And</ns1:Operator> </ns1:Filter> </ns1:filters> <ns1:topCount>0</ns1:topCount> <ns1:includeHeaders>false</ns1:includeHeaders> <ns1:breakOnError>true</ns1:breakOnError> </ns1:Export> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
END POINT RATING
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <ExportResponse xmlns="http://www.acumatica.com/typed/"> <ExportResult /> </ExportResponse> </soap:Body> </soap:Envelope>