getJSON HTTP authorization request header?

Hi

I’m trying to access a JSON API with getJSON.
Is there a way to send user & pswd in the header and not as part of the url? The API would only allow header authorization .

Thanks

Hugo is a static site generator.

To send a HTTP authorization request header you need to configure your server.

Your question is OT in this forum. Look in other channels about server configuration and the like.

Sorry to insist about the possibility of using getJSON with the authorization in the header. I’m trying to achieve this with hugo’s getJSON:

curl --location --request GET API_URL \
--header 'user: USER' \
--header 'pass: PSWD'

If this is out of topic, please forgive my ignorance on the topic.

Hugo is a static site generator built with Go.

getJSON is meant to retrieve a file not send an authorization request header.
Typically one uses the API key in the URL to retrieve the JSON.

If the API you are working with does not provide public API keys and you need to send a username and password then you need to look for help elsewhere.

This is not a forum for generic web development and servers.
Please respect that and do not open another topic with the same question.

getJSON does not support auth request headers, but we really should. I had planned to do this as as part of replacing the getJSON with a more flexible resources.GetRemote function – but time … This is probably important enough that we probably should just do it for getJSON as well, but time …

2 Likes

Related:

1 Like

Thank you for posting for all those links @jmooring
Really appreciate it.

@sgrins I have re-opened the topic and re-categorized it as a feature request, since the maintainer thinks that getJSON should be expanded to add support for sending auth request headers.

Great. Thanks.

I have reopened and labeled this issue:

PR welcome …

2 Likes