Skip to content

Push Examples

AJ Tatum edited this page Nov 7, 2019 · 2 revisions

For detailed information on the request objects used below, check out the Push Request Objects wiki page.

All of the Push methods returns a PushResponse which is documented on the Response Objects page.

Pushing a Note Example

You can push to a single client if you know the device_iden.

PushBulletClient client = new PushBulletClient("--YOURAPIKEY--");

//If you don't know your device_iden, you can always query your devices
var devices = await client.CurrentUsersDevices();

var device = devices.Devices.Where(o => o.manufacturer == "Apple").FirstOrDefault();

if (device != null)
{
    PushNoteRequest request = new PushNoteRequest
    {
        DeviceIden = device.iden,
        Title = "hello world",
        Body = "This is a test from my C# wrapper."
    };

    PushResponse response = await client.PushNote(request);
}

Alternatively you can always push to all devices for the account by using an email address instead of a specific device_iden (this is not specific to just pushing notes; it'll work for all push types).

PushBulletClient client = new PushBulletClient("--YOURAPIKEY--");

var currentUserInformation = await client.CurrentUsersInformation();

if (currentUserInformation != null)
{
        PushNoteRequest request = new PushNoteRequest
        {
            Email = currentUserInformation.Email,
            Title = "hello world",
            Body = "This is a test from my C# wrapper."
        };
    
        PushResponse response = await client.PushNote(request);
}

Pushing a Link Example

PushBulletClient client = new PushBulletClient("--YOURAPIKEY--");

//If you don't know your device_iden, you can always query your devices
  var devices = await client.CurrentUsersActiveDevices();

  var device = devices.Devices.Where(o => o.manufacturer == "Apple").FirstOrDefault();

  if (device != null)
  {
      PushLinkRequest request = new PushLinkRequest
      {
          device_iden = device.iden,
          title = "Google",
          url = "http://google.com/",
          body = "Search the internet."
      };

      PushResponse response = await client.PushLink(request);
  }

Pushing a File Example

PushBulletClient client = new PushBulletClient("--YOURAPIKEY--");

//If you don't know your device_iden, you can always query your devices
var devices = await Client.CurrentUsersDevices();

var device = devices.Devices.Where(o => o.manufacturer == "Apple").FirstOrDefault();

using(var fileStream = new FileStream(@"c:\daftpunk.png", FileMode.Open, FileAccess.Read, FileShare.Read))
{
    PushFileRequest request = new PushFileRequest
    {
        device_iden = device.iden,
        file_name = "daftpunk.png",
        file_type = "image/png",
        file_stream = fileStream,
        body = "Work It Harder\r\nMake It Better\r\nDo It Faster"
    };
        
    var response = await client.PushFile(request);
}
Clone this wiki locally