Element API - Order results by Category Is there a way to order the Craft Element-API results by the category title?

I'm just getting the error

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data


The "hostingCompany" field is a category field.

'hostings.json' =&gt; [
        'elementType' =&gt; Entry::class,
        'criteria' =&gt; [
            'section'   =&gt; 'hostings',
            'orderBy' =&gt; 'hostingCompany desc'
        ],
        'paginate' =&gt; true,
        'transformer' =&gt; function(Entry $entry) {

            return [
                'hostingDomain'  =&gt; $entry-&gt;hostingDomain,
                'hostingCompany' =&gt; (string)$entry-&gt;hostingCompany[0],
                'url'            =&gt; $entry-&gt;url,
            ];
        },
    ],


Updated error message:

PHP Warning 'yii\base\ErrorException' with message 'Header may not contain more than a single header, new line detected' 
in /Applications/AMPPS/www/crm.local/vendor/yiisoft/yii2/web/Response.php:380
Stack trace:
0 /Applications/AMPPS/www/crm.local/vendor/craftcms/cms/src/web/ErrorHandler.php(81): yii\base\ErrorHandler-&gt;handleError(2, 'Header may not ...', '/Applications/A...', 380)
1 [internal function]: craft\web\ErrorHandler-&gt;handleError(2, 'Header may not ...', '/Applications/A...', 380, Array)
2 /Applications/AMPPS/www/crm.local/vendor/yiisoft/yii2/web/Response.php(380): header('HTTP/1.1 404 SQ...')
3 /Applications/AMPPS/www/crm.local/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response-&gt;sendHeaders()
4 /Applications/AMPPS/www/crm.local/vendor/yiisoft/yii2/base/Application.php(392): yii\web\Response-&gt;send()
5 /Applications/AMPPS/www/crm.local/web/index.php(21): yii\base\Application-&gt;run()
6 {main}
This seems more like it may be an error in your code somewhere, do you have dev mode turned on?

I think you may want to output the title of the category:

'hostingCompany' =&gt; (string)$entry-&gt;hostingCompany[0]-&gt;title,


See if that helps, if not I would update your question with your complete element-api.php