---
schema_version: "1"
id: 409c3a495295d9de58ce7e6a70d20d1b936fd0eb35b933489d39d4c52226b1d1
title: InvokeExecute()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/references/api/mc-ampscript-reference-api-invoke-execute.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-api/mc-ampscript-reference-api-invoke-execute.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 62068944bd47d9174802c4337c38148d1db5ce46470c787b172b761898facc34
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# 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

```

```

```
