0

I am using swagger codegen to create C# code to use as a client api call.

java -jar swagger-codegen-cli.jar generate -i http://testing.com/swagger/docs/v1 -c config.json -l csharp -o testing-api

config.json:

{
  "modelPropertyNaming": "PascalCase",
  "securityDefinitions": {
    "apiKey": {
      "type": "apiKey",
      "description": "API Key Authentication",
      "name": "X-Key",
      "in": "header"
    }
  }
}

This is how I call the api using the generated c# code:

var apiInstance = new EventApi();
var testRequest = new TestRequest(); 

apiInstance.TestSendEvent(testRequest );

How can I add spi key in the header?

Alvin
  • 8,219
  • 25
  • 96
  • 177

2 Answers2

1

I can do this, and it works:

apiInstance.Configuration.AddDefaultHeader("X-Key", "12345");
Alvin
  • 8,219
  • 25
  • 96
  • 177
-1

Are you calling your API through http? If thats the case, you can add your key to the authorization header of the http request.

fstam
  • 669
  • 4
  • 20