InvokeExecute()

Invokes the Execute method on a Marketing Cloud Engagement API Object and returns the API status code.

Availability

<table> <tr> <td>Marketing Cloud Engagement</td> <td>✅ Yes</td> </tr> <tr> <td>Marketing Cloud Next</td> <td>❌ No</td> </tr> </table>

Syntax

InvokeExecute(apiObject,
              statusMessage,
              requestId)

The InvokeExecute() function has three parameters:

  • apiObject (API Object): Required. The API Object to delete.
  • statusMessage (AMPscript variable): An AMPscript variable that stores the API status message.
  • requestId (AMPscript variable): An AMPscript variable that stores the request ID.

Usage

This example sets up and executes a LogUnsubEvent. The function succeeds if the operation completes, or when the specified error codes indicate the subscriber was already unsubscribed.


Set @lue = CreateObject('ExecuteRequest')
SetObjectProperty(@lue,'Name','LogUnsubEvent')

Set @lue_prop = CreateObject('APIProperty')
SetObjectProperty(@lue_prop, 'Name', 'SubscriberKey')
SetObjectProperty(@lue_prop, 'Value', @SubscriberID)
AddObjectArrayItem(@lue, 'Parameters', @lue_prop)

Set @lue_prop = CreateObject('APIProperty')
SetObjectProperty(@lue_prop, 'Name', 'JobID')
SetObjectProperty(@lue_prop, 'Value', @JobID)
AddObjectArrayItem(@lue, 'Parameters', @lue_prop)

Set @lue_prop = CreateObject('APIProperty')
SetObjectProperty(@lue_prop, 'Name', 'ListID')
SetObjectProperty(@lue_prop, 'Value', @ListID)
AddObjectArrayItem(@lue, 'Parameters', @lue_prop)

Set @lue_prop = CreateObject('APIProperty')
SetObjectProperty(@lue_prop, 'Name', 'BatchID')
SetObjectProperty(@lue_prop, 'Value', @BatchID)
AddObjectArrayItem(@lue, 'Parameters', @lue_prop)

Set @lue_prop = CreateObject('APIProperty')
SetObjectProperty(@lue_prop, 'Name', 'Reason')
SetObjectProperty(@lue_prop, 'Value', 'Custom Unsubscribe Page')
AddObjectArrayItem(@lue, 'Parameters', @lue_prop)

Set @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)
Set @Response = Row(@lue_statusCode, 1)
Set @Status = Field(@Response,'StatusMessage')
Set @Error = Field(@Response,'ErrorCode')

If (@Error == '12012') OR (@Error == '401') OR (@Status == 'Event posted') then
/_ Succeeded _/
Else
/_ Failed _/
EndIf