How To Send Push Notification With Parse REST API and C#

Lately, I’ve been doing a lot of iOS app development. I’ve been messing around with Objective-C since around 2009, but never really got deep into it.

Objective-C is hard and I try to stay away from it. But to use other languages such as Swift or even C# with Xamarin, you should at least have a basic knowledge and understanding of Objective-C. We can save the Objective-C for another post. This is to show an example of how to call the Parse server using their REST API that sends a push notification to a device. You must install the RestSharp client for this to work.

// Output "BEGIN" to console

// Build Request URL
 var client = new RestClient("");
 var request = new RestRequest("1/push", Method.POST);

// Build JSON string to send to server
 string json = "{\"where\": {\"deviceType\": \"ios\"}, \"data\": { \"alert\": \"Cubs Score: " + score + "\"}}";

// Output json to console

// Build Parameters and Headers to send with request
 request.AddParameter("application/json", json, ParameterType.RequestBody);

// Enter your App ID and REST API Key from your Parse account. Login and go to Settings and Keys.
 request.AddHeader("X-Parse-Application-Id", "APP ID");
 request.AddHeader("X-Parse-REST-API-Key", "REST API KEY");

// Let the Parse server know you're sending JSON
 request.AddHeader("Content-Type", "application/json");

// Execute the Request
 IRestResponse response = client.Execute(request);

// Get the response back from server
 var content = response.Content;

// Output "END" to console

[highlighter line=0]

Hopefully this helps get your push notifications to work. Please let me know if this works for your app.

Leave a Reply

Your email address will not be published. Required fields are marked *