Collection Level Auth is set to type API key

[COLLECTION] Collection level Auth is set to type API Key with header named API-key | TypeError: Cannot read properties of undefined (reading ‘type’)

I have followed all the steps that are mentioned in the documentation but still got this error.

Hey @altimetry-explorer11 :wave:

Welcome to the Postman community :postman:

Could you share an image of where and how you have set the Authorization at the Collection level.

The failure is pointing to that so it’s the best place to start.



My all tests cleared out of 16 except this. I am doing Postman API Fundamentals Student Expert certification

Hi @altimetry-explorer11.

It looks like you’re not configuring authorization in that specific request correctly. I will recommend you go over the course module again and read carefully through the step by step guide to find what you’re missing.

Hi @gbadebo-bello @danny-dainton
I also have same experience with altimetry-explorer11 .
Having diligently followed the steps in the training material, I still can’t get past this error. Please assist.

@gladnessa

Can you please share a screenshot of how you have setup the authentication for this collection?

Also check the submit request response. This should bring back the collection as a JSON response.

You should be able to look at the code for the failing test, and then logically step through the response to find that element as a troubleshooting step.

These courses aren’t meant to catch you out. The troubleshooting is part of the learning experience.

Thank you @michaelderekjones
I did the setup from the authorization page on the collection itself, not from the request page


I have worked back & through the steps as advised, still stuck with it.

I deleted the entire collection and re-performed all the tasks exactly as mentioned in the documentation, after that I did not get this error again. Apart from this, I have not found any other method through which I can solve this error.

It does look like you have it setup correctly at the collection level. Therefore next step is to review what is being returned in the collection JSON.

Can you cut and paste the actual test from the tests tab. So we can see what the test is looking for.

Can we also cut and paste the part of the response where its showing the api-key.

If you are unsure where this is, please look at the test code, as it should hopefully guide you to which element you need to look at.

A tip for trying to resolve these failures is to clone the submit request and then add some extra console logs into the code related to the test, so you can see what is being brought back and what the difference is.

This is an example of a similar test that is in the “15 Days of Postman” challenges.

let collection = pm.response.json().collection

pm.test("Auth added correctly", () => {
    pm.expect(collection.auth.type, 'check auth type').equals("apikey")
    pm.expect(collection.auth.apikey[0].value, 'check api key').contains.oneOf(["X-api-key", "{{postman_api_key}}"])

    pass += 1
})

In your error message screenshot, its complaining about the type. Which means that it can’t find the type parameter on the collection.auth, so the problem is more likely that the collection.auth is the issue.

This is what it should look like (I’ve minimized the non-relevant keys, so you can just see the auth elements).

image

Hopefully, you can see how this aligns to the test.

The Student Expert course has changed a few times over the years, so I don’t know exactly what code is in the latest course. Hence the request to post the test and response you are getting.