Business Central how to invoke a Web Service from Powershell

Business Central how to invoke a Web Service from Powershell

How-to re-call a WebService from Powershell (BC On-Premise)

Scenario:

We already have Web Services defined, with several fields calculated or recovering difficult management data (e.g. dimensions shortcuts etc.), the Web Services are ready and we want to reuse them.

We don’t want to redo them, we don’t want to create APIs or create other external procedures to read them, for example, we want to read them to feed tables in a datawarehouse without using SQL Server (through stored procedures the functions).

One possibility is to recall them from powershell, there are some ways to do it.

Remember: calculated fields are NOT seen in SQL Server, in Web Services yes; Powershell and Sql Server are not available for BC Cloud

#1 – Publish a Web Service on Business Central

Example “ItemListWs” Web Service, publish SOAP & Odata Web Services

Example WS Link

http://localhost:7848/INSTANCE/WS/CRONUS%20Italia%20S.p.A./Page/SalesOrder

#2 – Use Powershell to re-call Web Services

Invoke-WebRequest

Module: Microsoft.PowerShell.Utility – “Gets content from a web page on the internet

You can pipe the body of a web request to Invoke-WebRequest

The Invoke-WebRequest cmdlet sends HTTP and HTTPS requests to a web page or web service. It parses the response and returns collections of links, images, and other significant HTML elements.

Beginning in PowerShell 7.0, Invoke-WebRequest supports proxy configuration defined by environment variables.

Microsoft Example

EXAMPLE

WebServiceProxy

Invoke-RestMethod

Module: Microsoft.PowerShell.Utility – “Sends an HTTP or HTTPS request to a RESTful web service”

You can pipe the body of a web request to Invoke-RestMethod

The Invoke-RestMethod cmdlet sends HTTP and HTTPS requests to Representational State Transfer (REST) web services that return richly structured data.

PowerShell formats the response based to the data type. For an RSS or ATOM feed, PowerShell returns the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML, PowerShell converts, or deserializes, the content into objects.

EXAMPLE

Microsoft Docs

Invoke-WebRequest

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7

Invoke-RestMethod

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7

1 thought on “Business Central how to invoke a Web Service from Powershell”

  1. As a mule developer, I have used a consumer component or SOAP web application for the WSDL file. this business central new to me but the terminology is relevant to me will book bark this blog for my future references

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: