pixiSetItemTags
Synchronises the prefixed item tags of the items given in an XML document: creates missing tags, adds new tag assignments and removes prefixed assignments no longer listed.
Sets the tags of one or more items from the XML document in TagsXML. The call works as a replace per item for all tags whose name starts with TagPrefix.
Steps:
- Every
/ItemTags/Item/TagList/Tagelement becomes one row. The tag name is stored asTagPrefix+Name(an emptyNamegives no name). Empty values forItemNrInt,EANUPCandItemKey= 0 are treated as missing. - The item is resolved in three passes against
Items: first byItemKey, then byItemNrInt, then byEANUPC. A later match overwrites an earlier one, so if several identifiers are given and point to different items, the EAN match wins. Rows whose item cannot be found are silently dropped. - Tags (type 1, not a system tag) that do not exist yet by name are created in
Tag. If the same tag name appears with different descriptions, the alphabetically highest description is used; an empty description is stored as empty string. Descriptions of existing tags are not changed. - For each item contained in the XML, all existing assignments in
TagMatchto tags of type 1 whose name matchesTagPrefix%and which are not listed for that item are deleted. Tags without the prefix are not touched. An item sent only with an empty tag name therefore loses all its prefixed tags. - Listed tag assignments that do not exist yet are inserted into
TagMatch.
The result lists the newly inserted assignments with Action = ADDED. Items that were sent with an empty tag name additionally appear once with Action = DELETED and TagKey/TagName empty. The individual removed assignments are not returned.
Notes
- No explicit transaction: tag creation, deletions and inserts are separate statements; a failure in between can leave a partial state.
- Reads of
ItemsandTaguseNOLOCK. TagPrefixis used in aLIKEpattern;%or_in the prefix act as wildcards and can widen the set of tags that get removed. An empty prefix makes all type-1 tags of the listed items subject to removal. ANULLprefix yields no tag names, so nothing is added and nothing is removed.- The XML element
Nameis read asvarchar(50),Descriptionasvarchar(500),EANUPCasvarchar(13); longer values are truncated. Whether prefix + name fits intoTag.Namedepends on the table definition, which is not visible. - The XML document handle from
sp_xml_preparedocumentis never released withsp_xml_removedocument; it stays allocated until the connection ends. - No error rows are returned; unknown items are ignored silently.
Tables used
| Parameter | Type | Default | Description |
|---|---|---|---|
TagsXML
|
varchar(max) xml |
NULL |
XML document with the items and their tag list. Each Example:
|
TagPrefix
|
varchar(20) string |
API |
Prefix placed in front of every tag name from the XML. Only assignments to tags whose name starts with this prefix are synchronised (removed if not listed). Note the trailing space in the default. Example: |
Result set 1 · Always (may be empty)
Newly added tag assignments (ADDED) and, for items sent with an empty tag name, one marker row (DELETED). Duplicate rows are removed by UNION.
| Column | Type | Description |
|---|---|---|
TagKey
Nullable |
int |
ID of the tag ( |
TagName
Nullable |
string |
Full tag name including prefix; empty for |
ItemKey
|
int |
Key of the resolved item. |
Action
|
varchar(7) string |
|
Response example
<SqlRowSet1>
<row>
<TagKey>17</TagKey>
<TagName>API Sale</TagName>
<ItemKey>1234</ItemKey>
<Action>ADDED</Action>
</row>
<row>
<TagKey>18</TagKey>
<TagName>API New</TagName>
<ItemKey>1234</ItemKey>
<Action>ADDED</Action>
</row>
</SqlRowSet1>
POST https://apigateway.descartes.com/tms/pixi/
Content-Type: text/xml; charset=utf-8
Authorization: Basic BASE64(USERNAME:PASSWORD)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://apigateway.descartes.com/tms/pixi/">
<SOAP-ENV:Body>
<ns1:pixiSetItemTags>
<!-- <TagsXML><![CDATA[<ItemTags><Item><ItemKey>1234</ItemKey><ItemNrInt>A-1000</ItemNrInt><EANUPC>4012345678901</EANUPC><TagList><Tag><Name>Sale</Name><Description>Summer sale 2024</Description></Tag><Tag><Name>New</Name><Description></Description></Tag></TagList></Item></ItemTags>]]></TagsXML> -->
<!-- <TagPrefix>API</TagPrefix> -->
</ns1:pixiSetItemTags>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
curl -X POST 'https://apigateway.descartes.com/tms/pixi/' \
--user 'USERNAME:PASSWORD' \
--header 'Content-Type: text/xml; charset=utf-8' \
--data-binary @- <<'XML'
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://apigateway.descartes.com/tms/pixi/">
<SOAP-ENV:Body>
<ns1:pixiSetItemTags>
<!-- <TagsXML><![CDATA[<ItemTags><Item><ItemKey>1234</ItemKey><ItemNrInt>A-1000</ItemNrInt><EANUPC>4012345678901</EANUPC><TagList><Tag><Name>Sale</Name><Description>Summer sale 2024</Description></Tag><Tag><Name>New</Name><Description></Description></Tag></TagList></Item></ItemTags>]]></TagsXML> -->
<!-- <TagPrefix>API</TagPrefix> -->
</ns1:pixiSetItemTags>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XML
<?php
$soapClient = new SoapClient(null, [
'login' => 'USERNAME',
'password' => 'PASSWORD',
'location' => 'https://apigateway.descartes.com/tms/pixi/',
'uri' => 'https://apigateway.descartes.com/tms/pixi/',
]);
$arguments = [
// 'TagsXML' => '<ItemTags><Item><ItemKey>1234</ItemKey><ItemNrInt>A-1000</ItemNrInt><EANUPC>4012345678901</EANUPC><TagList><Tag><Name>Sale</Name><Description>Summer sale 2024</Description></Tag><Tag><Name>New</Name><Description></Description></Tag></TagList></Item></ItemTags>',
// 'TagPrefix' => 'API',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiSetItemTags', $soapArguments);
- SQL object:
- dbo.pipiSetItemTags