Using Firebase for simple CRM logging

Sometimes you want to do some simple logging in your CRM plugin or custom workflow and you can't do any debugging and tracing is just not what you need.

Firebase is a database. The cloud kind. It has a REST interface through which you can manipulate its contents. Why is this good?

In case your access is very limited, but can still make HTTP calls to the outside world, Firebase can be your log sink. You can create a free account and have a free-tier plan which is more than enough for simple logging.

Keep in mind that a database is publicly readable and writable by default. You'll need to consult the docs to tighten security.

The data is represented in JSON-like key/value pairs. The database you have created located example.firebaseio.com will present you with a simple interface to manipulate your data. You can walk the data graph just by tweaking the url, e.g. example.firebaseio.com/ logging and so on. If you walked passed the existing data, you'll get back a null value. If you append .json to the end of the url, you'll get back the JSON representation, like example.firebaseio.com/logging.json

Let's create a simple Workflow as an example. Well just send a fixed message every time the workflow runs. We will need to send the content as JSON. Create a new Workflow in Visual Studio and add the following code somewhere in the execution path.

try
{
	using (var client = new WebClient())
	{
		var dbName = "your-db-name";

		client.UploadString("https://" + dbName + ".firebaseio.com/logging.json",
                            "{\"Message\": \"Hello from code\" }");
	}
}
catch (Exception ex)
{
	// handle but don't crash the whole workflow
}

Once deployed, activated, and executed check the dashboard of your database, you'll see the value has appeared.

As you can see it is very simple to send something to Firebase.
Since this is a logging aid, it is extremely important to make sure that if it fails, it must not affect the workflow's original task.

Next time we'll look at how to make this a bit more convenient.