Why cant I authenticate my infura project with my secret key?

im trying to authenticate my infura project through curl but its not working for no reason. Im doing this on powershell in windows.
curl --user :my-secret-key https://mainnet.infura.io/v3/myprojectID
the result I get is:
404 page not found
Not really much to work with. Looked around in the infura community and im not seeing any answers figured i’d ask here. By the way, Im actually using the real curl and not invoke-webrequest as aliased by windows on powershell. I turned it off and installed curl through choco.
their tutorial and their docs say i should be doing this exact same thing but its not working on my machine
I tried the same command on a debian machine and I got the same result, I dont think its a powershell/curl on windows issue.

1 Like

If you are submitting that request as a GET request then the 404 means you are authenticating properly but there is no resources available via GET. Our API is JSON-RPC which expects a POST request. try that same curl but with a valid JSON-RPC API POST request and you should get data back. Sorry for the confusion. I will note it with our engineering team that we should add more detail to our documentation.

curl -u :[YOUR_PROJECT_SECRET]  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://mainnet.infura.io/v3/[YOUR_PROJECT_ID]
1 Like

Yeah I just tried that it gave me this
{"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid json request"}}
There shouldn’t be any problems on my end as im just making a request correct? I should just be getting ‘answers’ or in this case the blocknumber in the terminal.

Yes you should be getting a hex number back as a response. That error means that you are sending invalid JSON in your data payload. Double check your data payload by pasting it at jsonlint.com and make sure there isn’t some utf-8 character or some other typo.

If you share you code or the full curl request we can take a look at it for you.

curl -u :MYSECRET  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://mainnet.infura.io/v3/myid

I just used the line above as you said and replaced my credentials in the placeholders. I had already verified that my JSON was valid. Not really sure what the problem is here. If I deliberately mess up my secret or project ID I get an authentication error so at least I know its successfully attempting to connect the infura API.

Continuing the discussion from Why cant I authenticate my infura project with my secret key?:

I got it to work. Tested it on a third linux machine I got up and running and it worked. Somehow my windows and my first linux tests both failed for known reasons. Thanks for the help.

This is extremely confusing. The first command in https://blog.infura.io/getting-started-with-infura-28e41844cc89/ says to just do a raw curl GET, which returns a 404. Would be helpful for future newcomers if you updated the tutorial to only include valid code samples.

I also see the same commands suggested in the documentation here: https://infura.io/docs/ethereum.
Am I missing something? They all return 404’s for me.

1 Like

Hi @Jared_Nielsen, and welcome to the Infura community! We appreciate your feedback and will definitely update our docs so you don’t get a 404.

Hey @Jared_Nielsen - the reason you’re running into the error is that our API is JSON-RPC, which expects a POST request. The request you’re sending is a GET request, which has no resources available.

Try the same curl but with a valid JSON-RPC API POST request and you should get a response back.

Thanks again for bringing this up to us - we are updating our docs to make this clear so others don’t run into the same confusion!

Thanks! I understand that now. Was just confusing because the intro docs instruct you to make a GET request.

Ahhh, that makes sense! We’re updating them to reflect the need for a POST request :slight_smile:

It looks like docs aren’t updated yet: https://blog.infura.io/getting-started-with-infura-28e41844cc89/

Hey @vyorkin, and welcome to the Infura community! We’ve updated our docs, but we’ll also make sure to update the blog post - thanks!

1 Like

Hello. I am sending ERC721 token via rinkeby.infura. First question.

  1. When I check the “Require project secret for all requests” checkbox, the “getTransactionCount” function stops working and gives the error “Error: Error returned: rejected due to project ID settings”
  2. When the transaction goes through, rinkeby.etherscan.io sees the transaction, in Metamask I get 1 token, but the transaction itself and metadata are not displayed in Metamask …
    What could be the problem?

Hey @Yevhen_Dubovka, and welcome to the Infura community!

  1. If you’re using a WebSocket connection, check this thread out for an example: How to use project secret with wss?
    If not, our API is JSON-RPC, as EG mentioned above on this thread, which expects a POST request. Make sure you’re using a valid JSON-RPC API POST request.
    If neither of these work to fix, can you please send over your code so we can try to debug that way?

  2. What nonce are you using? If you have an incorrect nonce (i.e. a future nonce so the current nonce is 3 and yours is 6), the node won’t receive the next sequential nonce it needs, so your transaction with that future nonce will eventually get dropped. Without having raw transaction information we can’t help you check that, but it’s probably a good place to start! If you need help with getting the nonce, check out our docs!

Hi @starblackDS I had the same issue and it worked with the POST command on my Mac but not Windows (always the outlier :-()))

1 Like

Hey @Solasnarealta, welcome to the Infura community, and thanks for updating this post with your experience! We love to see our users helping each other out :smile:

@Leiya_Kenney ,you are keep saying you will update the documentation and it is just the same after months of complaints of users!
And it is not the blog post, it is documentation that says to try curl https://.infura.io/v3/YOUR-PROJECT-ID
I am sending you the screenshot of the first step of your own documentation guys, where literally everyone goes to start working with you.

Looks like you are really kidding guys

For those using Windows, here’s how I solved the issue of getting the “invalid json request” error: adding escaping backslashes to the "s inside the other quotes. Here’s the example:

What’s on the tutorial:

curl https://mainnet.infura.io/v3/YOUR-PROJECT-ID
-X POST 
-H "Content-Type: application/json" 
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params": [],"id":1}'

The solution:

curl https://mainnet.infura.io/v3/YOUR-PROJECT-ID 
-X POST 
-H "Content-Type: application/json" 
-d "{\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\",\"params\": [],\"id\":1}"

Result:

    {"jsonrpc":"2.0","id":1,"result":"0xc43001"}

Alternatively if you want to avoid adding \s to every call,
a) Windows 7: install cygwin and run a command line with that (which will have the commands work as if it’s linux)
b) Windows 10: install WSL (Windows Subsystem for Linux) and run a command line with that

1 Like