AMPscript
AddObjectArrayItem
CreateObject
InvokeConfigure
InvokeCreate
InvokeDelete
InvokeExecute
InvokeExtract
InvokePerform
InvokeRetrieve
InvokeSchedule
InvokeUpdate
SetObjectProperty
Validate Your Server-Side JavaScript using WSProxy
Invokes the Retrieve method on an API object.
InvokeRetrieve(1, 2)
| Ordinal | Type | Description |
|---|---|---|
1 | String | Required. The name of the object to perform the Retrieve method on. |
2 | Array | Required. An array that holds the status and request ID of the API call. |
This code example uses the Platform.Function.InvokeRetrieve function to perform an API call. The example includes a filter that’s configured so that the request retrieves all emails that are associated with a specific account ID.
1<script runat="server">
2
3 // Create an API RetrieveRequest.
4 var RetrieveRequest = Platform.Function.CreateObject("RetrieveRequest");
5
6 // Create a variable to store the result of the RetrieveRequest.
7 var StatusAndRequestID = [0,0];
8
9 // Specify the object type for the retrieve request.
10 Platform.Function.SetObjectProperty(RetrieveRequest, "ObjectType", "Email");
11
12 // Specify the columns to retrieve for the specified object type.
13 Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "Email.Name");
14 Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "Email.ID");
15
16 // Create a SimpleFilterPart to apply to the API request.
17 var RetrieveFilter = Platform.Function.CreateObject("SimpleFilterPart");
18
19 // Filter objects based on account ID.
20 Platform.Function.SetObjectProperty(RetrieveFilter, "Property", "Client.ID");
21 Platform.Function.SetObjectProperty(RetrieveFilter, "SimpleOperator", "equals");
22 Platform.Function.AddObjectArrayItem(RetrieveFilter, "Value", "11223");
23
24 // Add the filter to the RetrieveRequest.
25 Platform.Function.SetObjectProperty(RetrieveRequest, "Filter", RetrieveFilter);
26
27 // Perform the request.
28 var Emails = Platform.Function.InvokeRetrieve(RetrieveRequest, StatusAndRequestID);
29
30 // Output the status and ID for the request.
31 Platform.Response.Write("Status: " + StatusAndRequestID[0] + "<br/>");
32 Platform.Response.Write("RequestID: " + StatusAndRequestID[1] + "<br/>");
33
34 // Iterate through the results. Output the ID and name of each object in the result.
35 for ( var c = 0 ; c < Emails.length ; c ++ ) {
36 Platform.Response.Write("[" + Emails[c].ID + "] ");
37 Platform.Response.Write(Emails[c].Name + "<br/>");
38 };
39</script>The response includes the status and ID of the request, as well as a list of all emails that matched the filter criteria.
1Status: OK
2RequestID: 11d254b9-f4d3-4f05-8b6e-5885ddc0901e
3[1122334] Major Release Announcement for version 2.0
4[1122335] Minor Release Announcement (version 2.0.1)
5[1122336] Minor Release Announcement (version 2.0.2)