OAuth2::api() call throws "Response content must not be an array"

Hi,

I use the OAuth2 class to obtain an auth token and then use the api() method to make REST api calls to a server.

The api() method promises to return the response as an array - this is great.

Everything works fine, except as a part of the api() call, the yii\web\Response::prepare() method throws an exception because “Response content must not be an array”.

The REST server returns content via HTTP as JSON. The framework converts this to an array.

I am completely confused why this exception is being thrown… Any ideas?

After a few hours of going through every line of code, I realized that the issue was “printing” the API response in the test controller method (returning it as an array) which is not a valid return type for yii\web\Response. The issue had nothing to do with yii\httpclient\Response…

Mystery solved :wink:

1 Like