Introduction:
This document provides a comprehensive, step-by-step
guide on how to create and utilize a .http file for testing out-of-the-box
(OOTB) APIs available in Microsoft Dynamics 365 Finance and Operations (D365
FnO). The .http file format, supported in modern IDEs such as Visual Studio
Code, offers a simple and efficient way to compose, send, and validate HTTP
requests directly from your development environment. By leveraging this
approach, developers can streamline the API testing process, enhance
productivity, and reduce dependency on external tools like Postman or SOAP UI.
This guide covers the fundamentals of setting up your environment, configuring
authentication, defining request bodies, and interpreting responses to
effectively interact with D365 FnO APIs.
Prerequisites:
- Visual Studio 2022 version 17.8 or later with the ASP.NET and web development workload installed.
Steps for testing FnO APIs:
1)Project configurations:
a.
Create
a new project with the template ASP.NET Core Empty
b.
In
Configuration of project name the project and define the location of the
project and click ‘Next’
c.
Setup
Additional information by selecting the .Net framework and mark ‘Configure
for HTTPS’. Uncheck ‘Enable container support’.
2) Setting up .env file for environment variables:
a. Right click on the project and click on ‘New Item’
b.
Name
the file exactly as ‘http-client.env.json’. Locate the file in the
same directory as the .http file or in one of its parent directories.
c. Here is an example of an environment file:
3) 3)Create
and configure .http file for API testing:
a.
Right
click on the project and click on ‘New Item’
b.
One
this compact view window of ‘Add New Item’ pops up, click on ‘Show
All Templates’
c. Go to ‘ASP.NET Core’ section and find the item ‘HTTP File’. Name the file with .http extension and click on ‘Add’
e.
On
the right – top corner you can see the env dropdown which enlists the environment
configuration defined in Section 2.
f.
Add
the below configuration to setup an endpoint to get the Token through OAuth from
the token authentication URL, while utilizing the environment variables defined
in the .env file. Once done click on ‘Send request’ to send the request
to the endpoint URL and you can generate the response on the right hand side of
the window as shown below
g.
You
can setup the custom service or any other OOB FnO endpoint using the below
configuration. While utilizing the token value retrieved from the response under
attribute ‘access_token’.
Reference
: Use
.http files in Visual Studio 2022