This document contains conceptual, procedural, and scenario information about HTTP AMPscript functions.

Why Use the HTTP AMPscript Functions

You can use these functions to include and manipulate web content within email messages and landing pages.

How To Use the HTTP AMPscript Functions

Create your AMPscript using the functions below and place them in the content areas of landing pages and email messages. For example, you can use the URLEncode() function to encode spaces or non-alphanumeric characters contained in a URL for use by your subscribers.

HTTPGet(S1,B1,N1,S2)

Returns the content from a specified URL. This function only works with HTTP on port 80 and HTTPS on port 443. Non-standard port assignments cause this function to fail. ExactTarget honors any character set returned in the HTTP headers via Content-Type. For example, you can use a UTF-8 encoded HTML file with Content-Type: text/html; charset=utf-8 included in the header. If the encoding is not specified in the header, the application assumes all returned data will be in the character set WindowsCodePage 1252. You can change this default by contacting Global Support.

Arguments

  • S1    The URL from which to return content
  • B1    (Optional) Defines whether the process continues on error. Defaults to false. A value of true ignores errors in process.
  • N1   (Optional) Defines whether the function allows empty content. This function defaults to 0.
    • A value of 0 allows for empty content
    • A value of 1 returns an error
    • A value of 2 skips the subscriber. 
  • S2   (Optional) Output of function status.
    • A value of 0 indicates status is OK
    • A value of -1 indicates a missing URL
    • A value of -2 indicates an HTTP request error
    • A value of -3 indicates empty content; the function completed successfully, but no content was returned

Example

HTTPGet("http://www.example.com")

System returns the content of http://www.example.com.

HTTPGet("http://www.example.com",false,0,@CallStatus)

System returns the content of http://www.example.com. The function stops if it encounters an error, and it allows empty content. The status of the function is returned to the declared variable @CallStatus.

HTTPRequestHeader(S1)

Retrieves the specified header from an HTTP request. Use only in landing pages.

Arguments

  • S1    The header to be retrieved from an HTTP request

Example

%%=HTTPRequestHeader("Referer")=%%

System returns value of the Referer header from the HTTP request.

IsCHTMLBrowser(S1)

Indicates if the passed-in user agent value represents a CHTML browser. CHTML browsers (such as those found on feature phones) use a modified version of HTML to display information on smaller screens with less resources than smartphones). This function returns a value of true or false indicating whether the browser uses CHTML. You can use this value to determine whether or not to display CHTML content.

Arguments

  • S1   The brower user-agent value

Examples

REPLACE IsCHTMLBrowser("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36")

System returns false because the provided user-agent value represents a Chrome browser on Windows.

IsCHTMLBrowser("DoCoMo/2.0 MST_v_SH2101V(c100)")

System returns true because the provided user-agent value represents a known CHTML browser on a feature phone.

IsCHTMLBrowser(HTTPRequestHeader("user-agent"))

This example uses the HTTPRequestHeader AMPscript funciton to return the browser user-agent value from the current browser. System returns the appropriate value for the provided user-agent value.

RedirectTo(S1)

Allows a client to specify the target of a link be a complete URL stored in an attribute, DE (data extension) field, or variable. This function may be used only in HTML emails within the href attribute of an <A> tag. In text emails, it must be prefixed with"http://" and there can be no spaces within the parentheses. In order to retain tracking information for clicked links, you must include the anchor tags (<a></a>) within the email itself and not the link retrieved via the AMPscript.

Arguments

  • S1    Function or substitution string to which to redirect

Examples

Given the data extension Vacation_Deals:

Customer_ID     Type         Link
123                    Flight        http://example.com/flights/
123                    Car            http://example.com/cars/
456                    Hotel        http://example.com/hotels/

%%[
Var @rows, @link, @cntr, @type
Set @rows=LookupRows("Vacation_Deals","CustomerID","123")
For @cntr=1 to Rowcount(@rows) do
        set @type=Field(Row(@rows, @cntr),"type")
        set @link=Field(Row(@rows, @cntr),"link")
]%%
<a href="%%=RedirectTo(@link)=%%">%%=v(@type)=%%</a>

%%[
Next @cntr
]%%

System returns:

Flight Deals

Car Deals

Where Flight Deals links to http://example.com/flights/ and Car Deals links to http://example.com/cars/.

You can also use this function to include data extension values at the end of a hyperlink within an email message, as shown in the example below:

%%[Set @email = 'aruiz@example.com' 
Set @firstName = 'Angel' 
Set @url = Concat('https://www.example.com?email=',@email,'&name=',@firstName)]%% 

<a href = "%%=RedirectTo(@url)=%%">Click Here</a>

System returns:

https://www.example.com?email=aruiz@...com&name=Angel

URLEncode(S1,B1,B2)

Returns the specified URL with spaces replaced with %20 or fully encodes all non-alphanumeric characters.

Arguments

  • S1    String containing the URL and attribute value
  • B1    (optional) Boolean value indicating how the function handles illegal URL characters. If you do not specify this value or set the value to 0, the function replaces spaces in the URL with %20. If you set this value to 1, the function encodes any character illegal for use in a URL (such as spaces and accented letters) in the query string of the given URL.
  • B2    (optional) Boolean value indicating how the function encodes passed string values. If you do not specify this value or set the value to 0, the function encodes only the portion of the passed string following the ? character. If you set this value to 1, the function encodes the full passed string.

Example

URLEncode("http://example.com?p=first name")

System returns:

http://example.com?p=first%20name

WrapLongURL(S1)

Returns a wrapped URL for the long URL provided in the string parameter of the function. Only URLs longer than 975 characters can be modified, and this function does not replace the standard link wrapping functionality implemented in the ExactTarget application. It is intended to mitigate a known limitation with long URLs in Microsoft Outlook 2007 and applies to URLs such as those included in an image source tag.

Arguments

  • S1    The long URL to be wrapped

Example

In the case where an image source URL exceeds 975 characters, use the function as shown below:

WrapLongURL("http://example.com/exceedinglylongimageurl.jpg")

This function returns a wrapped URL that can be used in your send to ensure compatibility with Outlook 2007. If this function is used on a URL with less than 975 characters, the URL will pass unchanged and the call will not break the send. Links wrapped with WrapLongURL remain incompatible with Always On Clicks. If your Member DB is down, a WrapLongURL will not work.

Was This Page Helpful?
Last updated by ryan.williams at 11:23, 27 Jun 2014