getting started with YNAB API in C# using RestSharp - how do I authenticate?

Anyone here have experience using RestSharp to talk to the YNAB API?  I think I see how the general operations will work, but am stuck on the authentication.

I successfully generated my API key and ran the curl command line example from the YNAB API website.

Just trying to translate that over to RestSharp so I can use the same API key there to authenticate.  If anyone has a brief code snippet for this I'd appreciate it.

2replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Got it working!  Thought I'd post my code in case it helps others.  This mirrors the curl command line example given on the YNAB API page but in C# using RestSharp.  Of course for a real app, you may want to take a look at the RestSharp recommended usage page, they suggest making a proxy class and making data classes to map the JSON results.  But this quick and dirty example at least shows how to deal with the authentication (when using the API key method) for YNAB from C#.


            const string apiKey = "--- put your API key here ---";
            public void Run()
                    var client = new RestClient("");
                    var req = new RestRequest("/budgets", DataFormat.Json);
                    req.AddHeader("Authorization", $"bearer {apiKey}");
                    var resp = client.Execute(req);
                    Debug.WriteLine("got resp => " + resp.Content);
                catch (Exception e)
                    Debug.WriteLine("oops! " + e);
    Like 3
  • Thank you!

Like Follow
  • 1 yr agoLast active
  • 2Replies
  • 119Views
  • 2 Following