SlimPay / hapiclient-php

HAPI Client for PHP.
MIT License
14 stars 12 forks source link

406 Not Acceptable Error #6

Closed csuredag closed 7 years ago

csuredag commented 7 years ago

Hi,

I'm getting user your examples when calling to sendFollow a 406 Not Acceptable error. I have tried to change headers but still the same.

Thanks,

Carlos

ghost commented 7 years ago

Hi, could you please give us more info about the request(s) you made ?

csuredag commented 7 years ago

I'm using your hapi client and getting a demo from slimpay page, When I catch the error I get that:

require_once 'vendors/hapiClient/autoload.php';

use \HapiClient\Http;
use \HapiClient\Hal;

// The HAPI Client
$hapiClient = new Http\HapiClient(
    'https://api-sandbox.slimpay.net',
    '/',
    'https://api.slimpay.net/alps/v1',
    new Http\Auth\Oauth2BasicAuthentication(
        '/oauth/token',
        'democreditor01',
        'demosecret01'
    )
);

// The Relations Namespace
$relNs = 'https://api.slimpay.net/alps#';

// Follow create-orders
$rel = new Hal\CustomRel($relNs . 'get-orders');
$follow = new Http\Follow($rel, 'POST', null, new Http\JsonBody(
[
    'started' => true,
    'creditor' => [
        'reference' => 'democreditor'
    ]
]
));

//print var_dump(get_headers("https://api.slimpay.net/alps/v1#get-orders"));

//echo var_dump($follow);
//die();
try{
    $res = $hapiClient->sendFollow($follow);

    // The Resource's state
    $state = $res->getState();

    echo $state;
}
catch(Exception $e){
    print $e->getMessage();
}
ghost commented 7 years ago

Are you using the examples given in https://dev.slimpay.com/hapi/browser ? They should work.

csuredag commented 7 years ago

Yes I'm just using the examples that you have. I have created a slim.php page with the example, when I call it, it throws: 406 Not Acceptable.

I have put the code above as is, and in sendFollow function throws that error. I have tried to change in HapiClient: $headers['Accept'] = '/', but still don't work for me. I don't know what am I doing wrong.

Thanks!

Carlos

ghost commented 7 years ago
$follow = new Http\Follow($rel, 'POST', null, new Http\JsonBody(
[
    'started' => true,
    'creditor' => [
        'reference' => 'democreditor'
    ]
]
));

Aren't you making a POST request on an endpoint which accept only GET requests ?

csuredag commented 7 years ago

I have coppied this as is:

csuredag commented 7 years ago

https://dev.slimpay.com/hapi/browser#get-orders

I have changed to GET, and still throwing the same error...

csuredag commented 7 years ago

Sorry, that was because I have changed just to try, but with PUT and GET the same error... I don't know if I have to do anything else...

ghost commented 7 years ago

That's strange because I also took the code given and it worked for me. Are you on the lastest version ? If yes, could you dump the whole request ? (With headers and data)

csuredag commented 7 years ago

Thanks a lot! I think I'm missing something...

It doesn't let me to upload the zip in this message, how can I do it?

ghost commented 7 years ago

Do what ? Are you using composer to manage your versions ?

csuredag commented 7 years ago

No, I'm not using composer, I have downloaded the full version today and I have tried to connect directly.

ghost commented 7 years ago

So you do have the lastest version ? What about the request sent ?

csuredag commented 7 years ago

I send you a picture of the version I have downloaded. Also the error I get. download error

Also the source code: https://dl.dropboxusercontent.com/u/31659387/Clientes.zip

YoussefBO commented 7 years ago

Hi Carlos,

Did you get the latest version? https://github.com/SlimPay/hapiclient-php/releases/download/v1.0.2/hapiclient-php-v1.0.2-with-dependencies.zip

Before this version, using the wrong credentials would result in a 406 Not Acceptable error.

This also means that you have to check your app ID and secret as they may not be correct.

Please tell me if this helped fix your issue. Thanks.

csuredag commented 7 years ago

Hi!!! Now it's working!

I had changed:

$follow = new Http\Follow($rel, 'GET', null, new Http\JsonBody( [ 'started' => true, 'creditor' => [ 'reference' => 'democreditor' ] ] ));

For this one:

$follow = new Http\Follow($rel, 'GET', [ 'creditorReference' => 'democreditor', 'reference' => null ]);

And works, I don't know where I got the first one.... sorry about that ;-)