Can't use Authorization header in GET request (solved)

Hi everyone of Codecademy,
I’am working on my endproject for the front-end engineer path and fell into a problem. (see the picture)
When I make an GET request I need to set an Authorization Header. The content-Type was easily set but the Authorization header doesn’t seem to save it as a string. I type ‘Authorization’ in and when I save in Visual Studio Code it changes automatically into Authorization without single quotes. It’s a mystery, searched all over the internet and can’t find a solution. Does someone know how to fix this?

I’m actually not too sure as to why VS Code would automatically replace it without the quotes, unless the Intellisense is bringing up the Authorization suggestion and you’re accidentally selecting it, but if it’s changing on save that’s not the case either! My best guess would be you have an extension installed like Prettier or something like that that formats code on save and it removes the quotes for Authorization.

However regardless of if you save it as a name without quotes or with quotes I find that API calls should work the same, since it’s essentially just the name of a property in the headers object it doesn’t need to be a string to work. I’d check your extensions and their settings so see if they have any auto-formatting that’s done to object property names, perhaps the auto-formatting sees a single string (i.e. no spaces, hyphens etc) object property name and removes the quotes as they’re not required.

2 Likes

I think this being a case of Intellisense missing the mark is likely…

2 Likes

Thank you for your quick response. You were right the prettier extension was causing the problem. I was able to change the settings for it and know it works the way I like it. Again thank you so much for your solution.

2 Likes

I’ve had a few issues with Prettier myself, it can sometimes do things a bit wrong and you need to customise it yourself often to get it working for everything. Glad that was able to solve your problem!

2 Likes