How To Fix API Calls That Always Return 401 With Access Token

I stumbled across a problem when accessing the Gumroad API that always returns 401 when using an access token. Here is a solution for you! Link to heading

You probably know Gumroad. Many people use it, but rather few know about their API. You can query products, sales, users, and more. They also provide instructions on how to access it properly. Or so I thought, at least. However, the web api always returns 401 HTTP status code (“Unauthorized”) when using the access token.

So, I created the app, obtained the access token, and wrote a small C# app that queries all sales using the RestSharp package. Here is the code:

Fun fact: The following cURL command works!

Then, I used Dart because I thought that maybe C# or RestSharp had some default setting that prevented the call from working. However, my Dart example fails with the same error code.

The final solution came from ChatGPT because there aren’t really code examples for the Gumroad API available via a Google search. The AI pointed out that the standard way of including access tokens in HTTP requests is with the Authorization Bearer header field. I thought that it’s enough to use the same header fields as in the cURL request. And that was my mistake!

I should have asked an AI before using Google search. That would have saved me half an hour!

My short conversation with ChatGPT about the problem.

My short conversation with ChatGPT about the problem.

Here is the correct code:

And now, everything works as expected.

Conclusion Link to heading

When your web API always returns 401 when using an access token, try the Authorization Bearer header. I was fooled by the cURL example that works differently.

How to Fix CORS Errors in Web Applications Link to heading

Cross Origin Resources Sharing can be a huge pain. So here is how to fix CORS errors in web applications.

How to Fix Missing Documentation in SwaggerUI of your .NET WebApi Project Link to heading

Your .NET WebApi project is up and running but the SwaggerUI doesn’t show the XML documentation of your code? Here is an easy fix!

Can’t use your pipeline in Azure DevOps with .NET7? Here is a solution! Link to heading

After upgrading your app to a newer .NET version the cloud build agent of Azure DevOps fails. Here is what you can do against it!