Skip to content

Instantly share code, notes, and snippets.

@brianlow
Created December 18, 2012 06:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianlow/4325610 to your computer and use it in GitHub Desktop.
Save brianlow/4325610 to your computer and use it in GitHub Desktop.
public static string CreateDatapoint(string feedId, string datastreamId, string value)
{
string url = string.Format("http://api.cosm.com/v2/feeds/{0}/datastreams/{1}/datapoints", feedId, datastreamId);
var datapoints = new {datapoints = new[] {new {at = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"), value}}};
var datapointsJson = new JavaScriptSerializer().Serialize(datapoints);
var webClient = new WebClient();
webClient.Headers.Set("X-ApiKey", "KbI9MZtLvhaOuAi0DKXWzc4UZk-SAKxhQjd3MHJtd2ZwYz0g");
return webClient.UploadString(url, "POST", datapointsJson);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment