|
|
Using AMPscript with the Web Service APIFrom $1Table of contents
This document contains conceptual and procedural information about using AMPscript in conjunction with the web service API. You can make calls to the API using AMPscript functions. PrerequisitesYou must be familiar with both AMPscript and the web service API in order to use the information in this document. You must also have access to use the web service API via your ExactTarget account. Please contact your ExactTarget representative if you wish to enable your account to use the web service API. Why Use AMPscript with the Web Service APIBecause AMPscript is a server-side scripting language, you can build interactions with the web service API directly into email messages or landing pages. This allows you to tightly integrate your content and messages with the web service API. How To Use AMPscript with the Web Service APIAMPscript uses a series of functions to interact with the web service API. These functions interact with the API's methods, objects, and properties as detailed below: Object-related FunctionsCreateObject(S1)Returns a new ExactTarget web service API object. Arguments
ExampleSET @subscriber = CreateObject("Subscriber")
Creates a new Subscriber object for the web service API. NOTE: an object created with CreateObject() should only be used for one particular API call. So, if a Subscriber object is created and then updated via InvokeUpdate, it cannot be passed to a Triggered Send. SetObjectProperty(O1,S1,S2)Sets a value for an object created by the CreateObject function. Arguments
ExampleThe following example creates an API object named "Subscriber" and gives it the the "EmailAddress" property with the value of an email address. SET @subscriber=CreateObject("Subscriber")
SetObjectProperty(@subscriber,"EmailAddress","user@example.com")
The following example creates an API object named "Attribute", gives it a name of "First Name", and sets the value to John. SET @attribute=CreateObject(Attribute) SetObjectProperty(@attribute,"Name","First Name") SetObjectProperty(@attribute,"Value","John") AddObjectArrayItem(O1,S1,S2)Appends an object to an array on an API object. Arguments
ExampleGiven the example below: AddObjectArrayItem(@mySubscriber,"Attribute",@myNewAttribute) The Attributes array on the mySubscriberObject would receive the attribute myNewAttribute. Field(S1,S2)Returns the specified field in the specified row or property value from an API object. Arguments
Example%%=Field(@row, "City")=%% The system returns value of the City field in the row specified in the @row variable.
%%=Field(@subscriber, "EmailAddress")=%% The system returns the EmailAddress value from the @subscriber WSDL object. Method-related FunctionsInvokeCreate(O1,S1,N1,O2)Invokes the ExactTarget web service API Create method on an API object. Returns the API Status Code. Arguments
ExampleGiven the example below: %%[
var @emailaddr
SET @emailaddr = "help@example.com"
SET @ts = CreateObject("TriggeredSend")
SET @tsDef = CreateObject("TriggeredSendDefinition")
SET @ts_subkey = @emailaddr
SetObjectProperty(@tsDef, "CustomerKey", "VolConfirm")
SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)
SET @ts_sub = CreateObject("Subscriber")
SetObjectProperty(@ts_sub, "EmailAddress", @emailaddr)
SetObjectProperty(@ts_sub, "SubscriberKey", @ts_subkey)
AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)
IF @ts_statusCode != "OK" THEN
RaiseError(@ts_statusMsg, 0, @ts_statusCode, @errorCode)
ENDIF
]%%
The AMPscript creates the TriggeredSend and TriggeredSendDefinition objects as @ts and @tsDef. It also assigns the correct properties to the objects and passes the object into the InvokeCreate call. The InvokeCreate call returns a status code and status message by which exception handling can be built. In this example, the AMPscript returns an error to the screen. InvokeUpdate(P1,P2,P3,P4)Invokes the Update method on an API object. Arguments
InvokeDelete(O1,S1,N1,O2)Invokes the Delete method on an API object. Returns the API Status Code. Arguments
InvokeRetrieve(P1,P2,P3)Returns an array of API objects from a RetrieveRequest object. Arguments
InvokePerform(O1,S1,S2)Invokes the ExactTarget web service API Perform method on an API object. Returns the API Status Code. Arguments
InvokeRetrieve(P1,P2,P3)Returns an array of API objects from a RetrieveRequest object. Arguments
InvokeUpdate(P1,P2,P3,P4)Invokes the Update method on an API object. Arguments
RaiseError(S1,B1,S2,S3,B2)Raises the error given in S1 and stops processing of job. If optional B1 is included with a value of "true," this function stops the send for the current subscriber only. Arguments
NOTE: The B2 flag applies to data written by the following AMPscript functions: ExampleRaiseError("An Error Occurred")
System returns the error message "An Error Occurred" and stops the job. RaiseError("Do not send to subscriber", true)
System returns the error message "Do not send to subscriber" and stops the send to that subscriber only. NOTE: Please note that because the system pre-processes and builds these emails, tracking and reporting numbers include these emails despite the errors and may cause inaccuracies. Use this function to handle the errors of a small number of subscribers, rather than as a method to segment out large numbers of subscribers. Instead, use query activities and exclusion lists to handle your segmentation needs. SetObjectProperty(O1,S1,S2)Sets a value for an object created by the CreateObject function. Arguments
ExampleThe following example creates an API object named "Subscriber" and gives it the the "EmailAddress" property with the value of an email address. SET @subscriber=CreateObject("Subscriber")
SetObjectProperty(@subscriber,"EmailAddress","user@example.com")
The following example creates an API object named "Attribute", gives it a name of "First Name", and sets the value to John. SET @attribute=CreateObject(Attribute) SetObjectProperty(@attribute,"Name","First Name") SetObjectProperty(@attribute,"Value","John") Sample CodeThe pages listed below provide examples on how to create AMPscript that interacts with the web service API to accomplish common tasks.
This page was last updated by Ryan Williams on Tue, 13 Dec 2011 13:51:41 GMT. If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:
Tags: (Edit tags)
|
Powered by MindTouch 2010 |