30 Days Postman Developer: Day 18 The response body needs to be of type object, but we found an array instead

I have been stuck in this step since almost 2 days - :frowning:
Getting this exception while sending the request - The response body needs to be of type object, but we found an array instead

Request {{baseUrl}}/cosmos

[
    {
        "id": 301,
        "name": "Cassiopeia",
        "tag": "cosmos"
    },
    {
        "id": 302,
        "name": "Orion",
        "tag": "cosmos"
    },
    {
        "id": 303,
        "name": "Scorpius",
        "tag": "cosmos"
    }
]

Here is the API Definition: openapi: "3.0.0"info: version: 1.1.0 title: Cosmos description: A sam - Pastebin.com

Hi @ishaanx, Welcome to the community!

Please check the example in the request.

@pranavdavar If we check the examples, there is a slight difference -

This is the example:

{
 "id": 41364023,
 "name": "Ut proident",
 "tag": "sint sunt do ullamc"
}

And this is my actual response -

[
    {
        "id": 301,
        "name": "Cassiopeia",
        "tag": "cosmos"
    },
    {
        "id": 302,
        "name": "Orion",
        "tag": "cosmos"
    },
    {
        "id": 303,
        "name": "Scorpius",
        "tag": "cosmos"
    }
]

The thing that I don’t understand is in my Schema definition the response type is already set as ‘object’. But this error is still here.

To fix the issue you may need to have sync at all places i.e. specifications, example response and actual response.

@pranavdavar I changed the object type in Schema definition to ‘object’ and yet I don’t see any difference in the response or the error.

Hi @ishaanx,

Api is returning array but you have specified object. It will never match, that is actually the error.

Hi @pranavdavar ,
If I understand correctly, API is returning array and my schema definition should also have object type array? Even if I change the ‘object type’ in my schema definition I still see the error. So what am I missing?

Sorry for asking too many questions. I’m a fairly new to Javascript and Postman.

Now you have 2 things in array
1 API Specification
2 Response

Last thing left is example
Change the example, so that it is in array data type

@pranavdavar Nevermind, I figured it out. Thank you for showing your patience with me and for your help. :slight_smile:

Good to hear that, you were able to fix.:blush:

1 Like