ExternalResourceClient Returning no response

Hello All,

I am using ExternalResourceClient with GET method with Bearer token to replace curl coding. 

URL and AuthKey are working on Postman. Also, POST Method on ExternalResourceClient is working well.

But GET method on ExternalResourceClient is returning 200-ok but with empty brackets, while server returns JSON response with message and status fields.

Please guide,

Prasad

$response = (new ExternalResourceClient())->get($url, ['Content-Type' => "application/json", 'Authorization' => 'Bearer ' . $dmsAuthKey ]);
var_dump($response->getBody()->getContents()); //returning {}

Parents
  • Hey ,

    You might be running into issues in your environment.

    How about you try something very basic first (see the example below) and then once that works, you try your URL.

    // ExternalResourceClient GET
    try {
        // Set timeout to 60 seconds and 10 max redirects
        $response = (new ExternalResourceClient(60, 10))->get('https://httpbin.org/get');
    } catch (RequestException $e) {
        $GLOBALS['log']->log('fatal', 'Error: ' . $e->getMessage());
        throw new \SugarApiExceptionError($e->getMessage());
    }
    $httpCode = $response->getStatusCode();
    if ($httpCode >= 400) {
        $GLOBALS['log']->log("fatal", "Request failed with status: " . $httpCode);
        throw new \SugarApiException("Request failed with status: " . $httpCode, null, null, $httpCode);
    }
    echo $response->getBody()->getContents();

    SugarCRM | Principal Developer Advocate

  • Yes, Can see response 

    { "args": {}, "headers": { "Host": "httpbin.org", "X-Amzn-Trace-Id": "Root=1-xx911461-243ebf43295ffb21388bexxf" }, "origin": "xxx.xxx.xxx.68", "url": "https://httpbin.org/get" }

    And also tried 

        $response = (new ExternalResourceClient(60, 10))->get($url, ['Content-Type' => "application/json", 'Authorization' => 'Bearer  ' . $token]);

    Postman is returning valid response with same $url and $token but ExternalResourceClient returning {}

Reply
  • Yes, Can see response 

    { "args": {}, "headers": { "Host": "httpbin.org", "X-Amzn-Trace-Id": "Root=1-xx911461-243ebf43295ffb21388bexxf" }, "origin": "xxx.xxx.xxx.68", "url": "https://httpbin.org/get" }

    And also tried 

        $response = (new ExternalResourceClient(60, 10))->get($url, ['Content-Type' => "application/json", 'Authorization' => 'Bearer  ' . $token]);

    Postman is returning valid response with same $url and $token but ExternalResourceClient returning {}

Children