Note: This article applies to the PHP Toolkit before version 2012.2.
User wishes to perform a delete or deleteList Web Services operation using the PHPToolkit. This article illustrates sample code that makes this possible.
- This article requires existing knowledge of Web Services and PHP.
Delete sample code:
...
require_once '../PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;
# DELETE A CUSTOMER
# ===============
// create array of customerRef fields
$customerFields = array (
'internalId' => 123,
'type' => 'customer'
);
// create recordRef
$customer = new nsComplexObject('RecordRef');
// set fields
$customer->setFields($customerFields);
// perform delete operation
$deleteResponse = $myNSclient->delete($customer);
// handle response
if (!$deleteResponse->isSuccess) {
echo "<font color='red'><b>" . $deleteResponse->statusDetail[0]->message . "</b></font>";
} else {
echo "<font color='green'><b>SUCCESS!!!</b></font>";
}
...
require_once '../PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;
# DELETE A CUSTOMER
# ===============
// create array of customerRef fields
$customerFields = array (
'internalId' => 123,
'type' => 'customer'
);
// create recordRef
$customer = new nsComplexObject('RecordRef');
// set fields
$customer->setFields($customerFields);
// perform delete operation
$deleteResponse = $myNSclient->delete($customer);
// handle response
if (!$deleteResponse->isSuccess) {
echo "<font color='red'><b>" . $deleteResponse->statusDetail[0]->message . "</b></font>";
} else {
echo "<font color='green'><b>SUCCESS!!!</b></font>";
}
...
The above code would generate the following SOAP request for the delete request:
<Body>
<delete>
<baseRef internalId="123" type="customer" xsitype="RecordRef" />
</delete>
</Body>
<delete>
<baseRef internalId="123" type="customer" xsitype="RecordRef" />
</delete>
</Body>
DeleteList sample code:
...
require_once '../PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;
# DELETE MULTIPLE CUSTOMERS
# ===============
// create array of customerRef fields
$customerFields1 = array (
'internalId' => 123,
'type' => 'customer'
);
// create 2nd array of customerRef fields
$customerFields2 = array (
'internalId' => 124,
'type' => 'customer'
);
// create recordRef
$customer1 = new nsComplexObject('RecordRef');
$customer1->setFields($customerFields1);
// create 2nd recordRef
$customer2 = new nsComplexObject('RecordRef');
$customer2->setFields($customerFields2);
// perform deleteList operation
$deleteListResponse = $myNSclient->deleteList(array($customer1, $customer2));
// handle response
if (!$deleteListResponse->isSuccess) {
echo "<font color='red'><b>" . $deleteListResponse->statusDetail[0]->message . "</b></font>";
} else {
echo "<font color='green'><b>SUCCESS!!!</b></font>";
}
require_once '../PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;
# DELETE MULTIPLE CUSTOMERS
# ===============
// create array of customerRef fields
$customerFields1 = array (
'internalId' => 123,
'type' => 'customer'
);
// create 2nd array of customerRef fields
$customerFields2 = array (
'internalId' => 124,
'type' => 'customer'
);
// create recordRef
$customer1 = new nsComplexObject('RecordRef');
$customer1->setFields($customerFields1);
// create 2nd recordRef
$customer2 = new nsComplexObject('RecordRef');
$customer2->setFields($customerFields2);
// perform deleteList operation
$deleteListResponse = $myNSclient->deleteList(array($customer1, $customer2));
// handle response
if (!$deleteListResponse->isSuccess) {
echo "<font color='red'><b>" . $deleteListResponse->statusDetail[0]->message . "</b></font>";
} else {
echo "<font color='green'><b>SUCCESS!!!</b></font>";
}
The above code would generate the following SOAP request for the deleteList request:
<Body>
<deleteList>
<baseRef internalId="123" type="customer" xsitype="RecordRef" />
<baseRef internalId="124" type="customer" xsitype="RecordRef" />
</deleteList>
</Body>
<deleteList>
<baseRef internalId="123" type="customer" xsitype="RecordRef" />
<baseRef internalId="124" type="customer" xsitype="RecordRef" />
</deleteList>
</Body>
No comments:
Post a Comment