You are here

protected function AcquiaLiftAPI::makePostRequest in Acquia Lift Connector 7.2

Makes an Acquia Authenticated POST request to an API endpoint.

Parameters

string $url: The fully-qualified URL to make the request to.

array $headers: Any headers that need to be added.

array $body: The request body.

string $success_msg: The error message to provide if the request fails.

string $fail_msg: The error message to provide if the request fails.

Throws

\AcquiaLiftException

3 calls to AcquiaLiftAPI::makePostRequest()
AcquiaLiftAPI::saveCampaign in includes/AcquiaLiftAPI.inc
Saves a campaign to Lift.
AcquiaLiftAPI::saveDecisionSet in includes/AcquiaLiftAPI.inc
Saves a decision set to Lift.
AcquiaLiftAPI::saveGoal in includes/AcquiaLiftAPI.inc
Saves a goal to Lift.

File

includes/AcquiaLiftAPI.inc, line 872

Class

AcquiaLiftAPI

Code

protected function makePostRequest($url, $headers = array(), $body = NULL, $success_msg = '', $fail_msg = '', $vars = array()) {
  $payload = $this
    ->encodeBody($body);
  $nonce = self::nonce();
  $timestamp = time();
  $this
    ->prepareRequest('POST', $url, $headers, $payload, $nonce, $timestamp);
  $response = $this
    ->httpClient()
    ->post($url, $headers, $payload);
  if ($response->code == 200) {
    $this
      ->logger()
      ->log(PersonalizeLogLevel::INFO, $success_msg, $vars);
  }
  else {
    $this
      ->handleBadResponse($response->code, $fail_msg, $vars);
  }
  $this
    ->authenticateResponse($nonce, $timestamp, $response);
  return json_decode($response->data, TRUE);
}