base_url = $base_url; $this->sub_key = $sub_key; $this->token = $token; } public function generateToken() { // NOTE: no need for now, since we use the pre-generated token } public function getInventory($branch_codes = [], $skus = []) { $body = [ 'BranchCodes' => $branch_codes, 'Skus' => $skus ]; $body_text = json_encode($body); $res = $this->curlPost('InventoryService', $body_text); return json_decode($res, true); } protected function curlPost($url, $body) { $curl = curl_init(); $options = [ CURLOPT_URL => $this->base_url . '/' . $url, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $body, CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Ocp-Apim-Subscription-Key: ' . $this->sub_key, 'Authorization: Bearer ' . $this->token, ], ]; curl_setopt_array($curl, $options); $res = curl_exec($curl); curl_close($curl); error_log('MOTIV API connector'); error_log(print_r($options, true)); error_log($res); return $res; } }