1

I am attempting to post login credentials to an apigility login API:

    $response = ClientStatic::post(
        'http://www.example.com/api/login',
        array('email' => 'test@eample.com','password' => 'test'),
        array('Accept' => 'application/json')
    );

This returns the error:

Cannot honor Accept type specified

As far as I can tell, application/json has been whitelisted in the configs:

Any ideas?

My Apigility config:

<?php
return array(
    'controllers' => array(
        'factories' => array(
            'Api\\V1\\Rpc\\Login\\Controller' => 'Api\\V1\\Rpc\\Login\\LoginControllerFactory',
        ),
    ),
    'router' => array(
        'routes' => array(
            'api.rpc.login' => array(
                'type' => 'Segment',
                'options' => array(
                    'route' => '/api/login',
                    'defaults' => array(
                        'controller' => 'Api\\V1\\Rpc\\Login\\Controller',
                        'action' => 'login',
                    ),
                ),
            ),
        ),
    ),
    'zf-versioning' => array(
        'uri' => array(
            0 => 'api.rpc.login',
        ),
    ),
    'zf-rpc' => array(
        'Api\\V1\\Rpc\\Login\\Controller' => array(
            'service_name' => 'Login',
            'http_methods' => array(
                0 => 'POST',
                1 => 'GET',
            ),
            'route_name' => 'api.rpc.login',
        ),
    ),
    'zf-content-negotiation' => array(
        'controllers' => array(
            'Api\\V1\\Rpc\\Login\\Controller' => 'Json',
        ),
        'accept_whitelist' => array(
            'Api\\V1\\Rpc\\Login\\Controller' => array(
                0 => 'application/vnd.api.v1+json',
                1 => 'application/json',
                2 => 'application/*+json',
            ),
        ),
        'content_type_whitelist' => array(
            'Api\\V1\\Rpc\\Login\\Controller' => array(
                0 => 'application/vnd.api.v1+json',
                1 => 'application/json',
            ),
        ),
    ),
    'zf-content-validation' => array(
        'Api\\V1\\Rpc\\Login\\Controller' => array(
            'input_filter' => 'Api\\V1\\Rpc\\Login\\Validator',
        ),
    ),
    'input_filter_specs' => array(
        'Api\\V1\\Rpc\\Login\\Validator' => array(
            0 => array(
                'required' => true,
                'validators' => array(
                    0 => array(
                        'name' => 'Zend\\Validator\\EmailAddress',
                        'options' => array(
                            'useDomainCheck' => true,
                        ),
                    ),
                ),
                'filters' => array(),
                'name' => 'email',
                'description' => 'Email address',
                'error_message' => 'Email address error',
            ),
            1 => array(
                'required' => true,
                'validators' => array(),
                'filters' => array(),
                'name' => 'password',
                'description' => 'Password required',
                'error_message' => 'Password error',
            ),
        ),
    ),
    'zf-mvc-auth' => array(
        'authorization' => array(
            'Api\\V1\\Rpc\\Login\\Controller' => array(
                'actions' => array(
                    'Login' => array(
                        'GET' => false,
                        'POST' => false,
                        'PUT' => false,
                        'PATCH' => false,
                        'DELETE' => false,
                    ),
                ),
            ),
        ),
    ),
);
Wilt
  • 41,477
  • 12
  • 152
  • 203
HappyCoder
  • 5,985
  • 6
  • 42
  • 73

3 Answers3

1

You did setup a controllers key in the zf-content-negotiation config and point to a Json selector. But this selector is not configured. This might be part of your problem. You can also read about this in the zfcampus/zf-content-negotiation documentation. You should add something like:

'selectors'   => array(
    'Json' => array(
        'ZF\ContentNegotiation\JsonModel' => array(
            'application/json',
            'application/*+json',
        ),
    ),
),

If that doesn't solve your issue please add a comment...

Wilt
  • 41,477
  • 12
  • 152
  • 203
  • Thank you - I am using the wysiwig admin to create my api. Would this be controlled from there or do I need to add this manually? thanks – HappyCoder May 26 '15 at 13:51
1

You can add a new selector over the Admin UI under [main menu] -> Content Negotiation -> [button] New selector

enter image description here

and add/delete/edit selectors there, e.g. adding ViewModels to them.

Content negotioation settings for a service are available in [side menu] -> Foo API -> Bar service -> Content Negotiation. There a Content Negotiation Selector for the service can be chosen from the lists of content and media types can be edited

enter image description here

(deleting seems to be buggy and not working -- but anyway it can also be done in the module.config.php in the key zf-content-negotiation).

automatix
  • 14,018
  • 26
  • 105
  • 230
0

The solution in this case was to run a composer.phar update which resolved the issue.

HappyCoder
  • 5,985
  • 6
  • 42
  • 73