Buckets:
title: Custom Object Function - Sage Intacct SDK for PHP | Sage Intacct Developer
url: https://developer.intacct.com/tools/sdk-php/custom-object-function/
Custom Object Function - Sage Intacct SDK for PHP | Sage Intacct Developer
Overview
Getting Started
List AR Invoices
List Vendors (Legacy)
CRUD Customer
Custom Object Function
Troubleshooting
- Prerequisites
- Set up
- Run the example
- Extra credit
- Get the record by ID
- Delete the record
- What’s next?
The example shows you how to:
- Create a class that extends
AbstractFunctionand implementsFunctionInterface. - Implement the
writeXmlfunction to generate XML for the API function for the request. - Call execute on a client and pass in the API function instance to send the request to the gateway.
Prerequisites
- You have downloaded or cloned the Sage Intacct SDK for PHP examples.
- You successfully ran the getting started example—in particular, you set up the
.credentials.inifile required bybootstrap.php. - The company you are using has Platform Services enabled and an object definition for your custom object (the example uses
test_object). - The user you are using has add, edit, delete, list, and view permissions for the custom object.
Set up
In the
composer.jsonfile, note that thesrc/Exampledirectory is mapped to the\Intacct\Example\namespace in the autoloader:"autoload": { "psr-4": { "Intacct\\Example\\": "src/Example/" } }Open
src/Example/AbstractTestObject.phpand note how it extendsIntacct\Functions\AbstractFunction.AbstractFunctionis a helper class provided mainly to generate random control IDs.AbstractFunctionimplementsIntacct\Functions\FunctionInterface, and any class whose instances will be executed by a client must implementFunctionInterface. If usingexecuteBatch, the parameter must be aFunctionInterface[]array.Open
src/Example/TestObjectCreate.phpand note how it extendsAbstractTestObject.The
FunctionInterfacerequires that the class implement thewriteXml(XMLWriter &$xml)function. This implementation is where you provide the XML that will be processed at the gateway endpoint.Back in
src/Example/AbstractTestObject.php, replacetest_objectwith the integration name for your custom object.const INTEGRATION_NAME = 'test_object';
Run the example
Run the
custom-object-function.phpfile:php custom-object-function.phpObserve the terminal output, which should look similar to this:
Created record ID 10153 Process finished with exit code 0Note the record ID, which will be used to delete the object later.
Open the generated
logs/intacct.htmlfile in your browser and review the entries.The file provides info and debug entries. The SDK provides a debug entry for each HTTP request/response (with the Sage Intacct endpoint).
Note that the log file was created by the logger set in the client config.
Extra credit
Get the record by ID
Update
custom-object-function.phpto execute aReadfunction using the record ID returned byTestObjectCreateas the key.$read = new \Intacct\Functions\Common\Read(); $read->setObjectName(\Intacct\Example\TestObjectCreate::INTEGRATION_NAME); $read->setKeys([ $recordNo ]); $response = $client->execute($read);
Delete the record
Create a
TestObjectDeleteclass and execute an instance of it that uses the same record ID returned in theTestObjectCreateresult.If you need help, see the example class.
<?php namespace Intacct\Example; use Intacct\Xml\XMLWriter; class TestObjectDelete extends AbstractTestObject { public function __construct($recordId) { $this->setId($recordId); } public function writeXml(XMLWriter &$xml) { $xml->startElement('function'); $xml->writeAttribute('controlid', $this->getControlId()); $xml->startElement('delete'); $xml->writeElement('object', self::INTEGRATION_NAME); $xml->writeElement('keys', $this->getId()); $xml->endElement(); // delete $xml->endElement(); // function } }
What’s next?
For more complex examples, you can use the functions in the SDK as models. For example, AbstractBill extends AbstractFunction, then BillCreate and BillDelete extend AbstractBill and write the XML for creating or deleting bills.
Provide feedback
Xet Storage Details
- Size:
- 4.74 kB
- Xet hash:
- e19e6c86d1b42c5ac9e7d76e441a1c74fa761ccc2fc273a59d3d53611db23629
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.