Skip to content
This repository was archived by the owner on Jun 25, 2023. It is now read-only.

Sending requests with PB.Net

Adomix edited this page Oct 9, 2018 · 11 revisions

Sending a push notification

To send a push notification, we need to make a PushRequest After establishing your client we may safely begin to do so. Making the PushRequest is fairly simple.


  1. First, We need to find the device we want to send the notification to. For example, I will be using the first device made by Samsung I have registered.

See: How to get your devices

LINQ not working past FirstOrDefault()? See my warning on creating a new device

var device = devices.FirstOrDefault(x => x.Manufacturer.Equals("Samsung", StringComparison.OrdinalIgnoreCase));

I recommended using StringComparison.OrdinalIgnoreCase because if the API returns the manufacturer with different casing your device will be null.

  1. Sending the request
await client.PushAsync("NotificationTitle", "NotificationContent", "target device identity");
// My example:
await client.PushAsync("Wrapper test", "This request will work!", device.Iden);

Creating a new device

Creating a new device is a bit more complex than sending a notification. First, we must create a new instance of NewDeviceModel and pass that to our method.

WARNING: Do not make a blank device. If you do LINQ will not working on finding a device. You would have to use the "==" operator on a property of devices. Ex: devices.FirstOrDefault(x => x.Nickname == "DONTDOTHIS");

var newModel = new NewDeviceModel()
{
    AppVersion = 0, //	Version of the Pushbullet application installed on the device
    HasSms = "true", // true if the devices has SMS capability, currently only true for type="android" devices
    Icon = "Phone", // Icon to use for this device, can be an arbitrary string. Commonly used values are: "desktop", "browser", "website", "laptop", "tablet", "phone", "watch", "system"
    Manufacturer = "Samsung", // Manufacturer of the device
    Model = "Galaxy S 100", // Model of the device
    Nickname = "GF Phone", // Name to use when displaying the device
    Token = "example" // Platform-specific push token. If you are making your own device, leave this blank and you can listen for events on the Realtime Event Stream.
};

Note that all these options are actually optional. Now, we need to pass this model into our method.

await client.CreateDeviceAsync(newModel);

That is it, you are done!


WIP