Last active
November 10, 2015 20:25
-
-
Save couellet/b78dcc0226957f891a92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using Newtonsoft.Json.Linq; | |
using RestSharp; | |
using RestSharp.Authenticators; | |
namespace Demo | |
{ | |
class Program | |
{ | |
private const string SNIPCART_API_KEY = "SECRET_API_KEY"; | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Getting orders from Snipcart"); | |
var client = new RestClient("https://app.snipcart.com"); | |
client.Authenticator = new HttpBasicAuthenticator(SNIPCART_API_KEY, ""); | |
var request = new RestRequest("api/orders"); | |
request.AddHeader("Accept", "application/json"); | |
request.AddHeader("Content-Type", "application/json"); | |
request.AddQueryParameter("offset", "0"); | |
request.AddQueryParameter("limit", "20"); | |
var response = client.Get(request); | |
// Response content will be the raw data in JSON | |
Console.WriteLine(response.Content); | |
var json = JObject.Parse(response.Content); | |
var raw = json["items"]; | |
var items = raw.ToObject<List<dynamic>>(); | |
foreach (var i in items) | |
{ | |
Console.WriteLine(i.token); | |
} | |
Console.WriteLine(items.Count); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment