Tag: Api

  • Using Cloudflared & Python for remote executing stuff on your closed home network!

    Using Cloudflared & Python for remote executing stuff on your closed home network!

    As you might be aware Cloudflare recently started offering a tunnel so that you could access your home network from your own domain, this is great news as before we had to open ports or made more complex configurations to make this work.

    So one of the first uses that comes to mind is remote executing stuff on your computer when your away! this opens so many possibilities. I created a python program that basically is a webhook server. It keeps listening for requests and once it has those it will open a program in your local machine! How cool that sounds!

    Th final program looks like this:

    I will go in more detail about how this webhook program works in another post, this post is mostly about how to setup Cloudflared and quicktunnels if you want to skip the creation of a domain.

    Let’s get into the details

    In order to expose a webhook server so it can be accessed from an external source we need to allow external traffic into our network, this is most of the times very risky so in order to allow traffic and not expose ourselves by opening ports in our router and firewall, we can use a tunneling solution, one that’s easy to set up and free to use is the one that is provided by Cloudflare called Cloudflared.

    To make this work the summarized steps are:

    • Get a free domain name *Create a cloudflare account *Add domain name to cloudflare account, point nameservers to cloudflare. *Setup tunnel inside cloudflare account *Setup cloudflared tunnel inside pc.

    To install it on other machines only the last two steps are needed.

    A guide on how to install CloudFlared can be found in the following links:

    https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/remote/

    https://www.makeuseof.com/use-cloudflare-tunnel-expose-local-servers-internet/

    After setting up the tunnel we can just start the webhook server, and every request sent to the domain configured when creating the tunnel in Cloudflared will be received by our webhook server.

    Some common webhook parameters to configure in the solution that sends the webhooks are:

    API Endpoint URL:

    This needs to be the domain you configured when setting up your tunneling solution) (For example: www.mydomain.com/webhook/docx)

    Payload Type:

    Json

    Wrap Request In Array:

    No

    Authentication:

    Basic Authentication (The user and password you configured in the webhook server configuration tab)

    Add Headers,Set parameters, etc :

    Unchecked

    Webhook Server Configuration

    In order to use the webhook server we need to define some parameters.

    Host: the default ip address where the webhook server will run: 127.0.0.1 is the default as this means “run on the local machine”.

    Port: You can choose any port you want that is unused.

    Username: the username used for basic authentication when sending webhooks from the outside world.

    Password: the password used for basic authentication when sending webhooks from the outside world.

    URL_Prefix: if no URL prefix is desired for the webhook receiving url, then just input “

    Adding new webhook endpoints: Then in the part below you can associate any webhook endpoint to any file you want in your computer, and the server will open the file whenever a new webhook in this endpoint, windows will use the default program associated with the file extension of this file.

    Thne just hit run and you should start receiving webhooks on your machine!

    Setting up Cloudflared without a Domain.

    To bypass setting up a domain name: (using Quick tunnels) If used for production setting up a domain name is recommended.

    https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/do-more-with-tunnels/trycloudflare/

    Steps to create a Quick Tunnel.

    -Go to https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation/

    -Download The CloudFlared Tunnel Setup

    -Grab the .MSI version x64 from here: https://github.com/cloudflare/cloudflared/releases and install it.

    -Open the command line and run the following command specifying the port where the webhook server is running:

    cloudflared tunnel --url <http://localhost:7000>
    

    -Copy this address to setup the webhook for example:

    -Then webhooks can be received by sending webhooks to this address and adding basic authentication.:

  • How to consume a Rest API in Dynamics 365

    How to consume a Rest API in Dynamics 365

    There are many ways you can consume an API Data in Dynamics, one of them is by doing a plugin.

    The basic plugin creation workflow is as follows:

    1-Select a programming language and a framework.

    2-Create the connection to your dynamics instance(Online or On-premises).

    3-Create the connection to your API.

    4-Write the logic that will perform the syncing process between records.

    5-Compile and Register your plugin using the Microsoft’s provided Plugin registration tool.

    6-Debug your plugin, using the plugin registration tool.

    7-Call your plugin from within dynamics and use it as you like.

    Figure1. Plugin registration tool’s Step, this is where you assign a name to your plugin that will be called by an action inside a dynamics solution.

    One way to do all these things in one place, is by using the .NET ecosystem. Microsoft offers all Dynamics’s Sdk as NuGet packages, so you always have access to up to date data.

    Just by installing one NuGet package you have access to a vast set of tools to mingle with your CRM installation.

    What’s a plugin? Why should I use it instead of JavaScript Web Resources? Well you always should try to accomplish the task in hand by using the dynamics provided processes tools, as they more performant, then if it’s impossible to do it that way, try to see if you can achieve it using power apps using the Power Automate “Microsoft Data verse” tools. Just notice that these are paid solutions.

    Then you can start exploring custom web resources written on JavaScript which will give you a lot more customization power but need to be maintained.

    Finally, If nothing of the previous methods is enough for your needs you can write a custom plugin in C# using the .NET framework.

    Of course this is just an oversimplification, as each tool has it’s specific purpose.

    You can find more information about this in Microsoft’s official Docs:

    https://docs.microsoft.com/en-us/power-apps/developer/data-platform/tutorial-write-plug-in