· 5 years ago · Mar 31, 2020, 07:06 AM
1<?php
2
3$username = 'apa@gmail.com';
4$password = 'apa';
5
6$curl = curl_init();
7$host = 'www.qontak.com';
8
9curl_setopt_array($curl, array(
10 CURLOPT_URL => "https://" . $host . "/oauth/token",
11 CURLOPT_RETURNTRANSFER => true,
12 CURLOPT_ENCODING => "",
13 CURLOPT_MAXREDIRS => 10,
14 CURLOPT_TIMEOUT => 30,
15 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
16 CURLOPT_CUSTOMREQUEST => "POST",
17 CURLOPT_POSTFIELDS => "grant_type=password&username=" . $username . "&password=" . $password,
18 CURLOPT_HTTPHEADER => array(
19 "User-Agent: PostmanRuntime/7.15.0",
20 "Accept: */*",
21 "Cache-Control: no-cache",
22 "Postman-Token: 6fe4ec26-9a02-4c42-9983-abf9b6068d53,c77a2e03-6b3c-467c-be02-9a8619d0dbb0",
23 "Host: $host",
24 "cookie: _qontak_session=e919412de828dfae3f3533a2fa288b3a; ",
25 "__cfduid=d30089d973d62b8085a693c94288580631563255368",
26 "content-type: application/x-www-form-urlencoded",
27 "accept-encoding: gzip, deflate",
28 "content-length: 58",
29 "Connection: keep-alive",
30 "cache-control: no-cache"
31 ),
32));
33
34# Getting the Access Token
35$response = curl_exec($curl);
36$err = curl_error($curl);
37
38curl_close($curl);
39
40if ($err) {
41 print_r("cURL Error #:" . $err);
42} else {
43 print_r($response);
44}
45
46# create a deal
47
48curl_setopt_array($curl, array(
49 CURLOPT_URL => "https://" . $host . "/api/v3.1/deals",
50 CURLOPT_RETURNTRANSFER => true,
51 CURLOPT_ENCODING => "",
52 CURLOPT_MAXREDIRS => 10,
53 CURLOPT_TIMEOUT => 30,
54 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
55 CURLOPT_CUSTOMREQUEST => "POST",
56 CURLOPT_POSTFIELDS => array(
57 "name: Test Deal Via API 3.1"
58 ),
59 CURLOPT_HTTPHEADER => array(
60 "Authorization: Bearer " . $response["access_token"],
61 "User-Agent: PostmanRuntime/7.15.0",
62 "Accept: */*",
63 "Cache-Control: no-cache",
64 "Postman-Token: 1eb7b5bb-38f7-4b8a-8fe0-9ec01b0a00f1,62346964-a7fe-4ce4-ad61-b94ed2eb60e2",
65 "Host: $host",
66 "cookie: __cfduid=d30089d973d62b8085a693c94288580631563255368",
67 "content-type: application/x-www-form-urlencoded",
68 "accept-encoding: gzip, deflate",
69 "Connection: keep-alive",
70 "cache-control: no-cache"
71 ),
72));