pixiSendEmailForInvoice
Creates a Pixi automail of type `API_Invoice_eMail` for an invoice from the matching mail template and places it in the outbox or drafts.
Generates and queues an e-mail for one invoice using the Pixi automail module (AM) and the mail type API_Invoice_eMail.
Steps:
- An empty
InvoiceNris treated as missing. A missingSubjectorMessagebecomes an empty string. Subject,MessageandInvoiceNrare stored in a temporary table (Api_Subject,Api_Message,InvoiceNr). The mail type's SQL query can read them when it builds the mail.- The mail type
API_Invoice_eMailis looked up inAM_Type. It must be enabled. - The invoice is read from
Invoicesand joined to its billing address inAddresses. This gives the customer, shop ID, country, shipping vendor and payment type. - A mail template of this type is selected with
fPixi_AM_GetTemplate. It looks for an enabled template that matches shop, country, payment type and shipping vendor. If no template matches all four, it falls back to templates that match fewer of these criteria, and finally to a generic template. pixi_AM_CreateMailForCSDbuilds the mail: recipient, subject, body and body type.Pixi_AM_SendManualstores the mail inAM_Mailwith statusCREATED. It may also attach the invoice document.- The key of the new mail record is returned in the column
AM_TypeKey.
If a check fails, the call returns a row with ReturnCode = ERROR and an ErrorMsg and stops.
Notes
- The call does not send the mail directly. It creates an
AM_Mailrecord in folder 1 (outbox), or in folder 0 (drafts) if the settingPixiMail_ForceManualMode=1or the mail type is in manual mode. It also publishes the MQ eventMailCreated. - Test mode: if the setting
PixiMail_ForceTestMode=1or the mail type has test mode enabled, the recipient is replaced by the address in the settingPixiMail_Test_eMail. - Subject and message: the passed
Subjectis overwritten by the subject that the template generates.SubjectandMessageonly appear in the mail if the mail type's SQL query or the template usesApi_Subject/Api_Message. That query is stored inAM_Type.AM_TypeSQLprocand runs as dynamic SQL. Its exact behaviour cannot be seen from the code. - If the dynamic query fails, the error is only written to the AM log and the call returns
eMail was not created!. - If the query returns no rows, an empty placeholder mail row is created. That row may then be stored with an empty recipient.
- Mail type must also be a folder-1 type:
Pixi_AM_SendManualrequires the type withAM_TypeFolder= 1. Otherwise it raisesEmail Type is disabled. In that case the caller receives aSqlMessageand a row withAM_TypeKey= 0. - Misleading column name:
AM_TypeKeyholds the new mail key (identity ofAM_Mail), not the type key. - Invoice attachment: the invoice document is attached via
AM_MailAttachmentonly if the mail type allows attachments, the template hasAttachInvoiceDocument= 1 and an attachment path is found. AM_MailInvoiceNris stored as NULL in the mail record.UserNameis passed to avarchar(20)parameter, so longer values are truncated.- Reads use
NOLOCK. No explicit transaction is used.
Tables used
| Parameter | Type | Default | Description |
|---|---|---|---|
InvoiceNr
Required
|
varchar(20) string |
– |
Number of the invoice the mail is created for ( Example: |
Subject
Required
|
varchar(255) string |
– |
Subject text. It is provided to the mail type query as Example: |
Message
Required
|
varchar(1024) string |
– |
Free message text. It is provided to the mail type query as Example: |
UserName
Required
|
varchar(50) string |
– |
User stored as creator and last editor of the mail record. Values longer than 20 characters are truncated. Example: |
Result set 1 · On success, and also with value 0 if Pixi_AM_SendManual raised an error
Key of the newly created mail record.
| Column | Type | Description |
|---|---|---|
AM_TypeKey
Nullable |
int |
Key of the new |
Result set 2 · If a validation fails or no mail could be created
Status row describing the error.
| Column | Type | Description |
|---|---|---|
ReturnCode
|
varchar(5) string |
Always |
ErrorMsg
|
varchar(40) string |
Error text. |
Response example
<SqlRowSet1>
<row>
<AM_TypeKey>158342</AM_TypeKey>
</row>
</SqlRowSet1>
| Status | Message | Cause |
|---|---|---|
| ERROR | Please specify the InvoiceNr parameter | `InvoiceNr` is NULL or empty. Pass a valid invoice number. |
| ERROR | eMail type is not enabled! | No enabled mail type `API_Invoice_eMail` exists in `AM_Type`. Enable the mail type in the Pixi automail configuration. |
| ERROR | Specified Invoice was not found! | No invoice with this number exists, or the invoice has no linked address. |
| ERROR | Cant find correct eMail template! | No enabled template of type `API_Invoice_eMail` matches the invoice's shop, country, payment type or shipping vendor, and no generic template exists either. Create a matching or generic template. |
| ERROR | eMail was not created! | Mail generation returned no row, for example because the mail type's SQL query failed. Check the AM log and the type query. |
| RAISERROR | Email Type is disabled | Raised by `Pixi_AM_SendManual` if the type `API_Invoice_eMail` with `AM_TypeFolder` = 1 is missing or not enabled. In this case `AM_TypeKey` = 0 is returned. |
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:pixiSendEmailForInvoice>
<InvoiceNr>ZEB000003</InvoiceNr>
<Subject>Your invoice ZEB000003</Subject>
<Message>Thank you for your order. Please find your invoice attached.</Message>
<UserName>master</UserName>
</ns1:pixiSendEmailForInvoice>
</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:pixiSendEmailForInvoice>
<InvoiceNr>ZEB000003</InvoiceNr>
<Subject>Your invoice ZEB000003</Subject>
<Message>Thank you for your order. Please find your invoice attached.</Message>
<UserName>master</UserName>
</ns1:pixiSendEmailForInvoice>
</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 = [
'InvoiceNr' => 'ZEB000003',
'Subject' => 'Your invoice ZEB000003',
'Message' => 'Thank you for your order. Please find your invoice attached.',
'UserName' => 'master',
];
$soapArguments = [];
foreach ($arguments as $name => $value) {
$soapArguments[] = new SoapVar($value, XSD_STRING, '', '', $name);
}
$response = $soapClient->__soapCall('pixiSendEmailForInvoice', $soapArguments);
- SQL object:
- dbo.pipiSendEmailForInvoice