@@ -52,18 +52,25 @@ public function getInstance()
5252 * @param string $type Type of request
5353 * @param string $url URL
5454 * @param array $params (Optional) Parameters
55+ * @param string $tenantId (Optional) Organization UID
5556 * @access public
5657 * @return mixed
5758 * @throw ApiException Invalid method requested
5859 */
59- public function request ($ type , $ url , $ params = array ())
60+ public function request ($ type , $ url , $ params = array (), string $ tenantId = null )
6061 {
6162 ApiDebug::p ('running request from ' . __CLASS__ );
6263
6364 switch ($ type ) {
6465 case \League \OAuth2 \Client \Provider \AbstractProvider::METHOD_POST :
65- $ options = array ('headers ' => array ('content-type ' => 'application/x-www-form-urlencoded ' ));
66- $ options ['body ' ] = http_build_query ($ params , null , '& ' , \PHP_QUERY_RFC3986 );
66+ if (self ::$ _epoint == UPWORK_GRAPHQL_EP_NAME ) {
67+ $ options = array ('headers ' => array ('content-type ' => 'application/json ' ));
68+ is_null ($ tenantId ) || $ options ['headers ' ]['X-Upwork-API-TenantId ' ] = $ tenantId ;
69+ $ options ['body ' ] = $ params ;
70+ } else {
71+ $ options = array ('headers ' => array ('content-type ' => 'application/x-www-form-urlencoded ' ));
72+ $ options ['body ' ] = http_build_query ($ params , null , '& ' , \PHP_QUERY_RFC3986 );
73+ }
6774
6875 $ url = ApiUtils::getFullUrl ($ url , self ::$ _epoint );
6976 break ;
@@ -84,6 +91,9 @@ public function request($type, $url, $params = array())
8491 // do not use getParsedResponse, it returns an array
8592 // but we need a raw json that will be decoded and returned as StdClass object
8693 $ response = $ this ->getInstance ()->getResponse ($ request );
94+ } catch (\GuzzleHttp \Exception \ClientException $ e ) {
95+ $ eResponse = $ e ->getResponse ();
96+ $ response = $ eResponse ->getBody ()->getContents ();
8797 } catch (\Exception $ e ) {
8898 $ response = $ e ->getResponseBody ();
8999 }
0 commit comments