C# .NET Code Example

Document created by JackCowardin Administrator on Nov 1, 2016Last modified by JackCowardin Administrator on Apr 4, 2017
Version 8Show Document
  • View in full screen mode

Example Data Classes for API Return Data

Use these example classes to deserialize return data form API calls.

 

Text version for cut and paste:

 

A simple C# console application

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Diagnostics;

 

//API Sandbox Example Code
namespace API_Sandbox_Example
{
  class Program
  {
    static void Main(string[] args)
    {                                   // GuideStar Sandbox Search Example URI 
      string uri = "https://sandboxdata.guidestar.org/v1_1/search?q=ein:54-1774039";
      string username_or_api_key = "<User Name or API Key here>";
      string passwd = "<Password here - use empty string if logging in with API Key>";
      var req = WebRequest.Create(uri);
      req.Credentials = new NetworkCredential(username_or_api_key, passwd);
      req.Proxy = null;
      var response = req.GetResponse();
      using (Stream dataStream = response.GetResponseStream())
      {
        using (StreamReader reader = new StreamReader(dataStream))
        {
          string responseFromServer = reader.ReadToEnd();
          Console.WriteLine(responseFromServer);
        }
      }
      Console.ReadKey();
      response.Close();
    }
  }
}

Attachments

    Outcomes