Trying to access the API for Shortboxed: https://api.shortboxed.com/ using Visual Studio Code. I saw that on the website there is no way to generate a key, and not completely accustomed to the use of APIs, I ask if there is a way to access the data with just the API domain.
The following images are of my code, most likely this is an error in that.
The index for the main HTML page Script calling for the data of the API
CodePudding user response:
It depends on the way the API was developed. Many APIs will use authentication/authorization (not the same thing exactly, but grouped together here to keep things simple). This involves the sender of the HTTP request identifying themselves, often by including a client key or token.
You'll know if the API answers unauthenticated or unauthorized requests by calling it. If you get a 2xx response (200, 204, etc) then you were allowed to. If the API's developer sticks to the HTTP spec strictly, they will return a status code like 401 Unauthorized (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400). You can often find this information in the API docs so that you don't have to try things out to figure it out from scratch.
So at this point, it's up to that particular API's public documentation to describe its authentication/authorization to you so you know how you can call it.
I notice you say:
I saw that on the website there is no way to generate a key
So if you've already consulted their documentation and it says that you shouldn't need a key to call the API, but you get a response code like 401, you should contact their support to find out what may be going wrong.
Also worth mentioning that this will work the same no matter the HTTP client. Visual Studio Code, curl, Insomnia, Postman, a web browser (as long as it supports CORS), etc.