Creating an activity through the CRM WebApi

Recentely I had to create a phonecall activity through the WebApi in Dynamics 365 CRM. As most WebApi calls are pretty straight forward, I didn’t think much of this task, although I haven’t done this before. As I knew activities are special in CRM I looked around to see examples and couldn’t find any good ones. Therefore I’m writing this post, to make sure I have an example on hand when I need one.


To create an activity you use the relevant endpoint. These are /api/data/v8.2/phonecalls, /api/data/v8.2/emails, ect. Maybe there’s an option to use the generic endpoint, but I haven’t tested this.

Json message

For a phonecall the Json message could look like this:

The special part in this are the activity parties. More special even, that it’s called phonecall_activity_parties. That array contains two objects with a navigation lookup to the record and a participationtypemask. The number in the participationtypemask stands for From (1) and To (2).

Easy contact form to CRM lead using Microsoft flow

Many companies are looking for an easy solution to process a contact form on their website to a lead in CRM. In this post I’ll provide an easy, self service solution that requires no code.


To build this solution we are assuming the following:

  • You have Dynamics 365 CRM
  • Microsoft Flow is enabled in your tenant
  • You are ok with using Cognitoform or any other form tool or custom code that can post the form data to an url
  • You already use WordPress and Contact Form 7

I’ll be using a generic approach where you parse the json data from a webhook call. The tool above also has a built in connector to Microsoft Flow. That would even be a better option, but not all platforms support Flow. This approach is very easy to implement for a developer building your website.


The first thing we need to create is the basic Microsoft Flow. Go to Microsoft Flow and log in with your Office 365 credentials.Create a new flow and start with a blank canvas.
The first step is adding a trigger. The trigger you are looking for is the Request trigger. Select it and don’t fill out anything just yet. Next, add the Dynamics 365 connector and configure it to create a lead in your CRM instance. For now just use some dummy values. Save your flow and notice that you’ll get a request url in the Request trigger. Copy that so we can use it in the Cognitoform setup.

It’s pretty easy to setup a test account with Cognitoformand and create your first form. It took me less than 5 minutes. After you are done configuring your fields, you want to go to the submission settings on the bottom of the page. Add the Flow url in the “Post Json data to a website”:

Test your form and return to your flow and you’ll likely see one run has failed. That’s ok for now. Click this failed run and look for the request body of the trigger. Copy that:

Edit your flow and click the Request trigger. Click “Use sample payload to generate schema” and paste in the json from the previous step. Now you have defined the schema from the request and you can use those schema values to create the lead. Click the “Create record” step and use the defined values form the previous step to enter the values for your CRM fields.

Now you’re all setup. Fill out a form a see that a lead is created in CRM.


For WordPress and Contact Form 7 users, there’s a great plugin available. It posts the form data to an http endpoint, like flow, with just a few clicks in configuration. At the time of writing, CF7 to Zapier is not very popular yet, but I’ve tested it personally and it works great. Although the name contains Zapier, you can use any http endpoint that accepts application/json as it’s body.

Other options

In this sample I used a service that allowed me to test this integration without creating a subscription. There are many alternatives like Wufoo or Typeform that most likely could deliver a similar integration.

Create certificate for Azure AD app only permissions

If you are creating an Azure AD app with app only permissions, or a so called deamon app, you need to use a certificate. One option would be to create a self signed certificate. In most blog posts they use the deprecated makecert tool. If you haven’t used this before, it can be a bit hard to come by.

The alternative is to use PowerShell commandlets. So far I’ve seen some samples but not one complete script that does it all. Here I would like to share the script I use:

After you’ve run the script, you can copy paste the results in your Azure AD manifest files.