C# Plugin calling an external REST API

This post provides a simple example of how a Dynamics 365 C# plugin can connect to an external REST API (i.e. sitting outside of the Dynamics 365 environment). (The class used to achieve this being the RestClient class.)

This post is similar to Download leads from the Facebook API

The Code

Based on my experience, it seems calling a REST API from a plugin can be a bit challenging. This could be based on security issues or perhaps the way Dynamics handles asynchronous code. Anyway, the code sample below works.

Figure 1

It represents a simple ‘action’ which was registered as ‘None’

Figure 2

and ‘PostOperation’

Figure 3

and tested with the CRM REST Builder tool

References

https://restsharp.dev/docs/usage/client/