HTTPPostWithRetry()

Posts content to the specified URL. This function only works with HTTP on port 80 and HTTPS on port 443. Nonstandard port assignments cause this function to fail. This function is similar to HTTPPost2(), but this function includes the ability to retry the request if it fails on the first attempt. You can specify the number of times the function attempts to retry the POST request

The function honors any character set returned in the content-type HTTP header. For example, you can use a UTF-8 encoded HTML file if you specify Content-Type: text/html; charset=utf-8 in the header. If the header doesn’t specify encoding, the application assumes all returned data uses the character set WindowsCodePage 1252. To change this default setting, contact Salesforce support.

You can include as many name-value pairs as you need.

You can’t set the host and content-length headers of POST requests that are sent using this function. The value of host is always set to the domain of the URL that the request was sent to. The value of content-length is always set to the length of the content in the request.

The HTTPPostWithRetry() function has six parameters:

  • urlEndpoint (string): Required. The URL to send the content to.
  • contentTypeHeader (string): Required. The content-type header to use in the POST request.
  • content (string): Required. The content to send to the specified URL in the POST request.
  • numRetries (number): The number of times the request can be retried. The first retry occurs immediately after the request fails. Subsequent retries occur 1–4 seconds after the previous failure. The default value is 3.
  • boolReschedule (boolean): Determines whether the request is rescheduled if it can’t be completed after the specified number of retries. If the value is true and the send can’t be completed after the specified number of retry attempts, the send is paused and the system attempts to complete the send again after 15 minutes. If the value is false, the system doesn’t attempt to retry the delivery later. The default value is false.
  • boolReturnExceptionOnError (boolean): If true, the function produces an exception if it encounters an error. If false, the function continues after it encounters an error.
  • responseStatus (variable): A variable that is used to store the status of the POST request.
  • responseContentRowset (variable): A variable that is used to store the response content as a rowset.
  • headerName1 (string): The name of an additional header to include in the request.
  • headerValue1 (string): The value of an additional header to include in the request.

You can pass multiple name-value pairs for parameters by appending them to the end of the function (headerName2, headerValue2, and so on).

To call the function, pass it the required parameters. This example posts a simple JSON object to a specified URL. The function call uses the application/json content-type header, and stores the status of the request in a variable called @callStatus.

The function stores the HTTP status code and a rowset that contains the results of the request in the specified variables.