HTTPPost2

Similar to the HTTPPost function, this posts content to a defined, publicly accessible URL, but it also provides exception handling if an error is returned from the request.

NOTE: The function only works with HTTP content on TCP/IP port 80 and HTTPS on port 443. Basic access authentication in URLs is not supported (for example, https://username:[email protected]://domain.com).

Arguments

HTTPPost2(1,2,3,4,5,6,7,8,[9a,9b]...)

Ordinal Type Required Description
1 String True URL endpoint used to post content
2 String True Content-Type header value
3 String True Content to include in POST request
4 String False Whether the process continues on an error. A value of true returns an exception.
5 String False Variable used to return status response string
6 String False Variable used to return response row set (see note)
7 String False Name of additional header to include in POST request
8 String False Value of additional header to include in POST request
9a String False Name of additional header to include in POST request (see note)
9b String False Value of additional header to include in POST request (see note)

NOTE: Ordinal 6 returns a row set (the number of rows varies depending on the URL). This is an internal row set and the fields are not available for use. Arguments 9a and 9b allow additional header name and value pairs to be appended as arguments — repeat these pairs as required.

TIP: If the HTTPPost function is set as a variable, the HTTP status code from the request will be set as the variable value.

Example

The following example makes an HTTP POST request with a JSON payload to an external endpoint.

%%[

var @payload, @postRequest, @response, @responseRows

set @payload = '{
   "Order Number":10110113,
   "First Name":"Curt",
   "Last Name":"Harris",
   "Amount":{
      "Order Subtotal":120,
      "VAT":20,
      "Shipping":0,
      "Order Total":120
   }
}'

set @postrequest = HTTPPost2("https://httpbin.org/post","application/json", @payload, true, @response, @responseRows)

]%%
status code: %%=v(@postrequest)=%%
<br><br>response: %%=v(@response)=%%
<br><br>responseRows: %%=v(@responseRows)=%%
<br><br>responseRowCount: %%=RowCount(@responseRows)=%%

Output

The request returns the status code, response payload and row set. The following response has been abbreviated for display purposes.

status code: 200

response: {"args":{}, "data":"{...}", "files":{}, "form":{  }, "headers":{...}, "json":{"Amount":{"Order Subtotal":120, "Order Total":120, "Shipping":0, "VAT":20 }, "First Name":"Curt", "Last Name":"Harris", "Order Number":10110113 } }

responseRows: System.Data.DataRow[]

responseRowCount: 10