Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Second Array on Data Response is NULL #68

Closed
marcoadasilvaa opened this issue Sep 3, 2016 · 2 comments
Closed

Error Second Array on Data Response is NULL #68

marcoadasilvaa opened this issue Sep 3, 2016 · 2 comments

Comments

@marcoadasilvaa
Copy link

What steps will reproduce the problem?

API Resfull endpoint has array on your body response, for example:

{
  "code": 412,
  "httpMessage": "Precondition Failed",
  "message": "Request Active ",
  "data": {
    "requestId": 10,
    "userId": "17",
    "registryDate": "2016-08-19 21:54:40",
    "contractedServiceData": {
      "id": 6,
      "status": true
    }
  },
  "errors": null
}

What's expected?

Expected an array on tag contractedServiceData, for example:

array (size=5)
  'code' => int 412
  'httpMessage' => string 'Precondition Failed' (length=19)
  'message' => string 'Request Active' (length=14)
  'data' => 
    array (size=9)
      'requestId' => int 10
      'userId' => string '17' (length=2)
      'registryDate' => string '2016-08-17 20:42:35' (length=19)
      'contractedServiceData' => 
         array (size=2)
           'id' => 6
           'status' => true
  'errors' => null

What do you get instead?

My current response is tag contractedServiceData null

array (size=5)
  'code' => int 412
  'httpMessage' => string 'Precondition Failed' (length=19)
  'message' => string 'Request Active' (length=14)
  'data' => 
    array (size=9)
      'requestId' => int 10
      'userId' => string '17' (length=2)
      'registryDate' => string '2016-08-17 20:42:35' (length=19)
  'contractedServiceData' => null
  'errors' => null

Additional info

This is my code to request:

      $client = new Client([
            'baseUrl' => $this->baseUrl,
        ]);
                    $response = $client->createRequest()
            ->setUrl("user_requests/$orderId")
                ->setMethod('get')
                ->addHeaders([
                    'content-type' => 'application/json',
                    'authorization' => "Bearer $tokenBearer"
                ])
            ->setFormat(Client::FORMAT_JSON)
            ->setData([])
            ->send();
Q A
Yii version 2.0.9
PHP version PHP 5.6.24-0+deb8u1
Operating system Debian Wheezy
yii-httpclient 2.0.1

Thank you for your attention

cebe added a commit that referenced this issue Sep 3, 2016
@cebe
Copy link
Member

cebe commented Sep 3, 2016

possibly not related to the issue, but why do you set 'content-type' => 'application/json', header on a GET request?

I am also unable to reproduce your issue. If the API returns the JSON you posted it will be transformed using JsonParser which simply calls json_decode on the data. Can you give more information or steps to reproduce?

@marcoadasilvaa
Copy link
Author

Thanks for you aswer!
I am very sorry, that is worth the error data. The response is proper!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants