HTTPPost

This function posts content to a defined, publicly accessible URL.

Arguments

HTTPPost(1,2,3,4,5,6,[7a,7b]...)

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 Variable used to return response
5 String False Name of additional header to include in POST request
6 String False Value of additional header to include in POST request
7a String False Name of additional header to include in POST request (see note)
7b String False Value of additional header to include in POST request (see note)

NOTE: Additional header name and value pairs can be appended as arguments.

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).


Not a subscriber? Subscribe now.

Example 1

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

%%[

var @payload, @response

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

set @request = HTTPPost("https://httpbin.org/post","application/json", @payload, @response)

]%%
status code: %%=v(@request)=%%
<br><br>response: %%=v(@response)=%%

Output

The request returns the response body.

status code: 200

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

Example 2


Not a subscriber? Subscribe now.