@@ -52,18 +52,25 @@ public function getInstance()
52
52
* @param string $type Type of request
53
53
* @param string $url URL
54
54
* @param array $params (Optional) Parameters
55
+ * @param string $tenantId (Optional) Organization UID
55
56
* @access public
56
57
* @return mixed
57
58
* @throw ApiException Invalid method requested
58
59
*/
59
- public function request ($ type , $ url , $ params = array ())
60
+ public function request ($ type , $ url , $ params = array (), string $ tenantId = null )
60
61
{
61
62
ApiDebug::p ('running request from ' . __CLASS__ );
62
63
63
64
switch ($ type ) {
64
65
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
+ }
67
74
68
75
$ url = ApiUtils::getFullUrl ($ url , self ::$ _epoint );
69
76
break ;
@@ -84,6 +91,9 @@ public function request($type, $url, $params = array())
84
91
// do not use getParsedResponse, it returns an array
85
92
// but we need a raw json that will be decoded and returned as StdClass object
86
93
$ response = $ this ->getInstance ()->getResponse ($ request );
94
+ } catch (\GuzzleHttp \Exception \ClientException $ e ) {
95
+ $ eResponse = $ e ->getResponse ();
96
+ $ response = $ eResponse ->getBody ()->getContents ();
87
97
} catch (\Exception $ e ) {
88
98
$ response = $ e ->getResponseBody ();
89
99
}
0 commit comments