@@ -23,6 +23,15 @@ class IntercomClient
2323{
2424 const SDK_VERSION = '4.4.0 ' ;
2525
26+ const BASE_URI_US = 'https://api.intercom.io ' ;
27+ const BASE_URI_EU = 'https://api.eu.intercom.io ' ;
28+ const BASE_URI_AU = 'https://api.au.intercom.io ' ;
29+
30+ /**
31+ * @var string
32+ */
33+ private $ baseUri ;
34+
2635 /**
2736 * @var HttpClient $httpClient
2837 */
@@ -139,9 +148,14 @@ class IntercomClient
139148 * @param string $appIdOrToken App ID.
140149 * @param string|null $password Api Key.
141150 * @param array $extraRequestHeaders Extra request headers to be sent in every api request
142- */
143- public function __construct (string $ appIdOrToken , string $ password = null , array $ extraRequestHeaders = [])
144- {
151+ * @param string $baseUri The Intercom API base URI
152+ */
153+ public function __construct (
154+ string $ appIdOrToken ,
155+ string $ password = null ,
156+ array $ extraRequestHeaders = [],
157+ string $ baseUri = self ::BASE_URI_US ,
158+ ) {
145159 $ this ->users = new IntercomUsers ($ this );
146160 $ this ->contacts = new IntercomContacts ($ this );
147161 $ this ->events = new IntercomEvents ($ this );
@@ -158,6 +172,7 @@ public function __construct(string $appIdOrToken, string $password = null, array
158172 $ this ->notes = new IntercomNotes ($ this );
159173 $ this ->teams = new IntercomTeams ($ this );
160174
175+ $ this ->baseUri = rtrim ($ baseUri , '/ ' );
161176 $ this ->appIdOrToken = $ appIdOrToken ;
162177 $ this ->passwordPart = $ password ;
163178 $ this ->extraRequestHeaders = $ extraRequestHeaders ;
@@ -206,7 +221,7 @@ public function setUriFactory(UriFactory $uriFactory)
206221 */
207222 public function post ($ endpoint , $ json )
208223 {
209- $ response = $ this ->sendRequest ('POST ' , "https://api.intercom.io /$ endpoint " , $ json );
224+ $ response = $ this ->sendRequest ('POST ' , "{ $ this -> baseUri } / $ endpoint " , $ json );
210225 return $ this ->handleResponse ($ response );
211226 }
212227
@@ -219,7 +234,7 @@ public function post($endpoint, $json)
219234 */
220235 public function put ($ endpoint , $ json )
221236 {
222- $ response = $ this ->sendRequest ('PUT ' , "https://api.intercom.io /$ endpoint " , $ json );
237+ $ response = $ this ->sendRequest ('PUT ' , "{ $ this -> baseUri } / $ endpoint " , $ json );
223238 return $ this ->handleResponse ($ response );
224239 }
225240
@@ -232,7 +247,7 @@ public function put($endpoint, $json)
232247 */
233248 public function delete ($ endpoint , $ json )
234249 {
235- $ response = $ this ->sendRequest ('DELETE ' , "https://api.intercom.io /$ endpoint " , $ json );
250+ $ response = $ this ->sendRequest ('DELETE ' , "{ $ this -> baseUri } / $ endpoint " , $ json );
236251 return $ this ->handleResponse ($ response );
237252 }
238253
@@ -245,7 +260,7 @@ public function delete($endpoint, $json)
245260 */
246261 public function get ($ endpoint , $ queryParams = [])
247262 {
248- $ uri = $ this ->uriFactory ->createUri ("https://api.intercom.io /$ endpoint " );
263+ $ uri = $ this ->uriFactory ->createUri ("{ $ this -> baseUri } / $ endpoint " );
249264 if (!empty ($ queryParams )) {
250265 $ uri = $ uri ->withQuery (http_build_query ($ queryParams ));
251266 }
0 commit comments