title: Consuming JSON from another API in own .NET Core API
body: <p>For my project at the company I do an internship at, I was tasked with creating an API that could manage multiple admin-interfaces of other services. These admin-interfaces are controlled by API endpoints.</p>
  <p>They asked me to start with the admin API of their &quot;forms engine&quot;. An API which allows &quot;tenants&quot; (people that have a contract to use said engine) to make surveys and such. My task is to make an interface that can get the tenants, create and delete. The usual.</p>
  <p>Thing is, I'm not getting any output from the API, even though I should. This is also the first time I am consuming JSON in .NET Core so I might be missing something.</p>
  <p>The data structure for the /admin/tenants endpoint looks as follows:</p>
  <pre><code>{
      &quot;_embedded&quot;: {
          &quot;resourceList&quot;: [
              {
                  &quot;id&quot;: &quot;GUID&quot;,
                  &quot;name&quot;: &quot;MockTenant1&quot;,
                  &quot;key&quot;: &quot;mocktenant1&quot;,
                  &quot;applicationId&quot;: &quot;APPGUID&quot;,
                  &quot;createdAt&quot;: &quot;SOMEDATE&quot;,
                  &quot;updatedAt&quot;: &quot;SOMEDATE&quot;
              },
              {
                  &quot;id&quot;: &quot;GUID&quot;,
                  &quot;name&quot;: &quot;MockTenant2&quot;,
                  &quot;key&quot;: &quot;mocktenant2&quot;,
                  &quot;applicationId&quot;: &quot;APPGUID&quot;,
                  &quot;createdAt&quot;: &quot;SOMEDATE&quot;,
                  &quot;updatedAt&quot;: &quot;SOMEDATE&quot;
              }
          ]
      },
      &quot;_page&quot;: {
          &quot;size&quot;: 10,
          &quot;totalElements&quot;: 20,
          &quot;totalPages&quot;: 2,
          &quot;number&quot;: 1
      },
      &quot;_links&quot;: {
          &quot;self&quot;: {
              &quot;href&quot;: &quot;SOMELINK&quot;
          },
          &quot;first&quot;: {
              &quot;href&quot;: &quot;SOMELINK&quot;
          },
          &quot;last&quot;: {
              &quot;href&quot;: &quot;SOMELINK&quot;
          },
          &quot;next&quot;: {
              &quot;href&quot;: &quot;SOMELINK&quot;
          }
      }
  }
  </code></pre>
  <p>So I let Visual Studio automatically create following structure from said JSON:</p>
  <pre><code>    public class Rootobject
      {
          public _Embedded _embedded { get; set; }
          public _Page _page { get; set; }
          public Dictionary&lt;string, Href&gt; _links { get; set; }
      }
  
      public class _Embedded
      {
          [JsonProperty(&quot;resourceList&quot;)]
          public Tenant[] tenantList { get; set; }
      }
  
      public class Tenant
      {
          public string id { get; set; }
          public string name { get; set; }
          public string key { get; set; }
          public string applicationId { get; set; }
          public DateTime createdAt { get; set; }
          public DateTime updatedAt { get; set; }
      }
  
      public class _Page
      {
          public int size { get; set; }
          public int totalElements { get; set; }
          public int totalPages { get; set; }
          public int number { get; set; }
      }
      public class Href
      {
          public string href { get; set; }
      }
  </code></pre>
  <p>I changed the Classname from ResourceList to Tenant, because that's what it is.
  So, now coming to the code that gets the tenants:</p>
  <pre><code>        public async Task&lt;List&lt;Tenant&gt;&gt; getTenants()
          {
              List&lt;Tenant&gt; tenantList = new List&lt;Tenant&gt;();
              if (accessToken == &quot;&quot; || validUntil &lt; DateTime.Now)
              {
                  getNewAccessToken();
              }
              using (var request = new HttpRequestMessage(new HttpMethod(&quot;GET&quot;), baseUrl + &quot;admin/tenants&quot;))
              {
                  request.Headers.TryAddWithoutValidation(&quot;Authorization&quot;, $&quot;Bearer {accessToken}&quot;);
                  request.Headers.TryAddWithoutValidation(&quot;apikey&quot;, apiKey);
                  using (var response = await httpClient.SendAsync(request))
                  {
                      if (response.IsSuccessStatusCode)
                      {
                          try
                          {
                              Rootobject result = JsonConvert.DeserializeObject&lt;Rootobject&gt;(await response.Content.ReadAsStringAsync());
                              tenantList.AddRange(result._embedded.tenantList);
                          }
                          catch (Exception ex)
                          {
                              Debug.Write(ex);
                          }
                      }
                  }
              }
              foreach (Tenant t in tenantList)
              {
                  Debug.Write(t);
              }
              return tenantList;
          }
  </code></pre>
  <p>The Debug.Write(t) and the return give me nothing. It is an empty list.
  Anybody have any idea as to why this is, and what I can do about it?</p>
  <p>Thanks in advance and kind regards
  Lennert</p>