HTTPPostWithRetry
Posts content to a URL with automatic retry logic and returns the HTTP status code. Runtime-proven on a live Marketing Cloud Engagement CloudPage — including the responseStatus argument that holds the response body rather than the status the docs describe.
Syntax
HTTPPostWithRetry(urlEndpoint, contentTypeHeader, content[, numRetries, reschedule, returnExceptionOnError, @responseStatus, @responseContentRowset, headerName1, headerValue1, ...]) → number
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
urlEndpoint |
string | Yes | The URL to post the content to |
contentTypeHeader |
string | Yes | The Content-Type header for the request |
content |
string | Yes | The content to send in the POST body |
numRetries |
number | No | How many times the request can be retried (default 3) |
reschedule |
boolean | No | When true, retry after 15 minutes if all retries fail (default false) |
returnExceptionOnError |
boolean | No | When true, raise an exception on failure; when false, continue after an error |
responseStatus |
string | No | Output variable that receives the response body |
responseContentRowset |
rowset | No | Output variable that receives the response headers as a rowset |
headerName1 |
string | No | Name of an additional request header |
headerValue1 |
string | No | Value of an additional request header |
There is no upper bound on the argument count — additional request headers are passed as repeated name/value pairs after the rowset variable.
Example
%%[ VAR @status, @body, @headers
SET @status = HTTPPostWithRetry("https://postman-echo.com/post", "application/json", '{"marker":"amp-retry-xx7"}', 2, false, true, @body, @headers)
]%%
%%=v(@status)=%%
Renders 200; @body holds the echoed response and @headers is a rowset of the response headers.
Lower the retry count and let the function raise on a persistent failure:
%%[
VAR @status, @body, @headers
SET @status = HTTPPostWithRetry("https://postman-echo.com/post", "application/json", @payload, 2, false, true, @body, @headers)
]%%
Status %%=v(@status)=%%; header rows %%=v(RowCount(@headers))=%%
Return value
number — the HTTP status code of the response, which is 200 on a successful POST. There is no closed set of values to test for a success.
Behaviour
The responseStatus argument holds the body, and a separate rowset holds the headers. The official reference labels the argument as storing the request “status”, but at runtime it receives the response body (289 characters of echoed JSON) while responseContentRowset receives the response headers as a rowset — 11 header rows in the proof. The layout matches HTTPPost2. See the differs-from-docs note.
The retry controls are accepted at runtime. numRetries, reschedule and returnExceptionOnError were all accepted (2, false, true in the proof) and the successful call returned 200. Retry-on-failure itself is documented but cannot be observed against a healthy endpoint, so a probe confirms only that the arguments are accepted and a normal POST succeeds.
The HTTP status code is the return value. As with the other POST functions, the numeric status comes back as the function’s own return value, not through an output variable.
Show test script
%%[
VAR @b, @s3, @body3, @rr3
SET @b = RequestParameter("b")
OutputLine(Concat("CTRL=[", Uppercase("ok"), "]"))
/* 8-arg form: numRetries/reschedule/returnExceptionOnError accepted; @body3 the body, @rr3 the header rowset. fetch ?b=retry */
IF @b == "retry" THEN
SET @s3 = HTTPPostWithRetry("https://postman-echo.com/post", "application/json", '{"marker":"amp-retry-xx7"}', 2, false, true, @body3, @rr3)
OutputLine(Concat("status=[", @s3, "] bodylen=[", Length(@body3), "]"))
OutputLine(Concat("rrRows=[", RowCount(@rr3), "]"))
ENDIF
]%%
Availability
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | No |
See also
HTTPPost2— the same body/headers split without retryHTTPPost— the simplest POST- Differs from docs: the responseStatus argument holds the body
- Official reference · ampscript.guide