1// create & initialize a curl session
2$curl = curl_init();
3
4// set our url with curl_setopt()
5curl_setopt($curl, CURLOPT_URL, "api.example.com");
6
7// return the transfer as a string, also with setopt()
8curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
9
10// curl_exec() executes the started curl session
11// $output contains the output string
12$output = curl_exec($curl);
13
14// close curl resource to free up system resources
15// (deletes the variable made by curl_init)
16curl_close($curl);1function callAPI($method, $url, $data){
2   $curl = curl_init();
3   switch ($method){
4      case "POST":
5         curl_setopt($curl, CURLOPT_POST, 1);
6         if ($data)
7            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
8         break;
9      case "PUT":
10         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
11         if ($data)
12            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);			 					
13         break;
14      default:
15         if ($data)
16            $url = sprintf("%s?%s", $url, http_build_query($data));
17   }
18   // OPTIONS:
19   curl_setopt($curl, CURLOPT_URL, $url);
20   curl_setopt($curl, CURLOPT_HTTPHEADER, array(
21      'APIKEY: 111111111111111111111',
22      'Content-Type: application/json',
23   ));
24   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
25   curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
26   // EXECUTE:
27   $result = curl_exec($curl);
28   if(!$result){die("Connection Failure");}
29   curl_close($curl);
30   return $result;
31}1$data_array =  array(
2      "customer"        => $user['User']['customer_id'],
3      "payment"         => array(
4            "number"         => $this->request->data['account'],
5            "routing"        => $this->request->data['routing'],
6            "method"         => $this->request->data['method']
7      ),
8);
9$make_call = callAPI('POST', 'https://api.example.com/post_url/', json_encode($data_array));
10$response = json_decode($make_call, true);
11$errors   = $response['response']['errors'];
12$data     = $response['response']['data'][0];1$data_array =  array(
2   "amount" => (string)($lease['amount'] / $tenant_count)
3);
4$update_plan = callAPI('PUT', 'https://api.example.com/put_url/'.$lease['plan_id'], json_encode($data_array));
5$response = json_decode($update_plan, true);
6$errors = $response['response']['errors'];
7$data = $response['response']['data'][0];1$get_data = callAPI('GET', 'https://api.example.com/get_url/'.$user['User']['customer_id'], false);
2$response = json_decode($get_data, true);
3$errors = $response['response']['errors'];
4$data = $response['response']['data'][0];