# Generated code returns Unauthorized

**URL:** <https://community.postman.com/t/generated-code-returns-unauthorized/46696>\
**Category:** Help Hub\
**Tags:** authentication\
**Created:** [April 24, 2023, 3:55pm UTC](https://community.postman.com/t/generated-code-returns-unauthorized/46696 "2023-04-24T15:55:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rororuke](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rororuke](https://community.postman.com/u/rororuke)\
**Post date:** [April 24, 2023, 3:55pm UTC](https://community.postman.com/t/generated-code-returns-unauthorized/46696/1 "2023-04-24T15:55:02Z")

</div>

Initially set up an API test call in Linqpad referencing the latest RestSharp Nuget. Specified the client, and resource (i.e., the url components) and a basic authenticator per the specifications required for the API. This failed with Unauthorized.

In a last ditch effort, I turned to Postman. Using the same info it works. Just to be clear, no extra headers, no body, authorization is still basic (see attached screenshots).

I took the generated C# RestSharp code and pasted it into a new Linqpad query (again, referencing the latest RestSharp Nuget) and ran it. Surprisingly, it returned Unauthorized.

**Postman Get Request**

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/0/3046f555be2cad6c00e0f172c63df6a024308b06.jpeg)

**Postman Result**

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/7/6/766cc79e3047ebb7f812edd2886a013563dd71cb.png)

**Generated Code**

```auto
var options = new RestClientOptions("http://blade.apiserver.com")
{
  MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("/system/api/User/user.name", Method.Get);
request.AddHeader("Authorization", "Basic Generated-Authorization=");
var response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);

```
