I have an Angular project in which I need to interact with a CRM 2016 instance, that is, I need to create a record and open/navigate to it from within Angular.

I dont want to use the javascript SDK files because well they just seem klunky and non angular -ish.. So instead I wanted to do it with just a regular service.. Turns out it was quite easy. The hardest part was figuring out where Microsoft stored the GUID of the created record (spoiler: they stuck it in the header, more details on that here).

First off you need to add a service (or copy paste the CreateRecord method from this service to your own).

myApp.service('dataService', function ($http, $rootScope, $timeout, $q) {
    var pub = {};

    var crmAPIURL = Xrm.Page.context.getClientUrl() + "/api/data/v8.1/";

    pub.CreateRecord = function (entityName, record) {
        var url = crmAPIURL + entityName;
        return $http
                method: "POST",
                url: url,
                data: record,
                dataType: 'json',
                timeout: 15000
        }).then(function (data) { return data; });

    return pub;

Now with that service method defined we can call it like this from one of our controllers:

$scope.CreateCompany = function ()
    // define the entity record with all the fields you want to set.
    var account = {
        name: "My Test Company",
        address1_line1: "SyntaxWarriors road 1337"

    // call the service defined previously with the data and the name of the entity according to the web api
    // the entity names are listed here: https://your_organization_name.crm4.dynamics.com/api/data/v8.1/
    // in my case I wanted to create an account record which is called "accounts" (yes, the service tries to pluralize all things).
    $dataService.CreateRecord("accounts", account).then(function (data)
        // this will return something like: "https://your_organization_name.crm4.dynamics.com/api/data/v8.1/accounts(59e11f14-4489-e611-80de-c4346bacbdc4)"
        // the service returns the GUID of the created record in the header.. for some unexplained annoying reason I dont know. 
        var entityUrl = data.headers("OData-EntityId");

        // do some regex to get the data in between parentheses.
        var getDataBetweenParenthesesRegex = /\(([^)]+)\)/;
        var matches = getDataBetweenParenthesesRegex.exec(entityUrl);

        // uncomment these if you want to see what you're actually getting back.
        // console.log(data)
        // console.log(matches); the guid matches

        // the second match (1) is the guid without the (). Lets open a new window to that.
        if (matches.length >= 1) {
            Xrm.Utility.openEntityForm("account", matches[1]);