InvokeExecute()

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

Availability 

Marketing Cloud Engagement ✅ Yes
Marketing Cloud Next ❌ No

Syntax 

1InvokeExecute(apiObject,
2              statusMessage,
3              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.

1Set @lue = CreateObject('ExecuteRequest')
2SetObjectProperty(@lue,'Name','LogUnsubEvent')
3
4Set @lue_prop = CreateObject('APIProperty')
5SetObjectProperty(@lue_prop, 'Name', 'SubscriberKey')
6SetObjectProperty(@lue_prop, 'Value', @SubscriberID)
7AddObjectArrayItem(@lue, 'Parameters', @lue_prop)
8
9Set @lue_prop = CreateObject('APIProperty')
10SetObjectProperty(@lue_prop, 'Name', 'JobID')
11SetObjectProperty(@lue_prop, 'Value', @JobID)
12AddObjectArrayItem(@lue, 'Parameters', @lue_prop)
13
14Set @lue_prop = CreateObject('APIProperty')
15SetObjectProperty(@lue_prop, 'Name', 'ListID')
16SetObjectProperty(@lue_prop, 'Value', @ListID)
17AddObjectArrayItem(@lue, 'Parameters', @lue_prop)
18
19Set @lue_prop = CreateObject('APIProperty')
20SetObjectProperty(@lue_prop, 'Name', 'BatchID')
21SetObjectProperty(@lue_prop, 'Value', @BatchID)
22AddObjectArrayItem(@lue, 'Parameters', @lue_prop)
23
24Set @lue_prop = CreateObject('APIProperty')
25SetObjectProperty(@lue_prop, 'Name', 'Reason')
26SetObjectProperty(@lue_prop, 'Value', 'Custom Unsubscribe Page')
27AddObjectArrayItem(@lue, 'Parameters', @lue_prop)
28
29Set @lue_statusCode = InvokeExecute(@lue, @overallStatus, @requestId)
30Set @Response = Row(@lue_statusCode, 1)
31Set @Status = Field(@Response,'StatusMessage')
32Set @Error = Field(@Response,'ErrorCode')
33
34If (@Error == '12012') OR (@Error == '401') OR (@Status == 'Event posted') then
35/_ Succeeded _/
36Else
37/_ Failed _/
38EndIf