An official website of the United States government
Accessing the Public Data API with C#On This Page:API Version 2.0 C# Sample CodeSingle SeriesHere is an example of how to use POST method in c# (Version 2.0, single series): //Post request example version 2.0 var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.bls.gov/publicAPI/v2/timeseries/data/"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; //Using Javascript Serializer using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var jS = new JavaScriptSerializer(); var newJson = jS.Serialize(new SeriesPost() { seriesid = (new List Multiple SeriesHere is an example of how to use POST method in c# (Version 2.0, multiple series): //Post request example version 2.0 var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.bls.gov/publicAPI/v2/timeseries/data/"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; //Using Javascript Serializer using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var jS = new JavaScriptSerializer(); var newJson = jS.Serialize(new SeriesPost() { seriesid = (new List One or More Series with Optional ParametersHere is an example of how to use POST method in c# (Version 2.0, one or more series with optional parameters):
//Post request example version 2.0 var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.bls.gov/publicAPI/v2/timeseries/data/"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; //Using Javascript Serializer using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var jS = new JavaScriptSerializer(); var newJson = jS.Serialize(new SeriesPost() { seriesid = (new List
API Version 1.0 C# Sample CodeSingle SeriesHere is an example of version 1.0 single series:
//Post request example version 1.0 var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.bls.gov/publicAPI/v1/timeseries/data/CUUR0000SA0"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; Multiple SeriesHere is an example of version 1.0 multiple series:
//Post request example version 1.0 var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.bls.gov/publicAPI/v1/timeseries/data/"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; //Using Javascript Serializer using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var jS = new JavaScriptSerializer(); var newJson = jS.Serialize(new SeriesPost() { seriesid = (new List Multiple Series, Multiple YearsHere is an example of version 1.0 multiple series specifying years:
//Post request example version 1.0 var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.bls.gov/publicAPI/v1/timeseries/data/"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; //Using Javascript Serializer using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { var jS = new JavaScriptSerializer(); var newJson = jS.Serialize(new SeriesPost() { seriesid = (new List
Last Modified Date: June 22, 2016 |