Testing custom service/odata logic in postman for D365 F&O

Hi All,

Today I'm sharing few thoughts while I was testing the custom service logic from Postman.


I have searched many sources and blogs regarding this concept, But all shared about the logic of building the custom service in Dynamics365 and no one shared how to test the logic which was written in those x++ classes or to test the request/response output.

 Below are the steps need to follow for REST API custom service through POSTMAN.

1. Register an app (like for dev envn or QA/UAT)  for postman testing.



2. Client id will be auto populate and mention the below options to register app.

  •  Select accounts in any organizational directory (Any Azure AD directory - Multitenant)
  • Give Redirect Url as http://localhost




 3. Go to API permission tab Create API Permission and Mention the type of app (like Custom service or AX or Odata).

4. Go to Manifest and edit few lines for   

        "allowPublicClient": true, "oauth2AllowImplicitFlow": true





5. Go to Certificate and secrets tab and Create a Secret token and save the value in the notepad, Why because its one time visible.



6. Go to Certificate and secrets tab and Create a Secret token and save the value in the notepad, Why because its one time visible.

7. Go to Dynamics 365 F&O >>Login>>System Administration>>Setup>>Azure Active Directory  Application form>>Click New Button and enter Client Id and User



8. Now go to postman website and download the desktop app. Create the environment(in my case its Dev2) and create a collection(GetAccessToken) and mention   the below values in the body level.

    Client id : you will get it in portal.azure.com>>app registration.

    Client_secret: secret value which we saved in notepad

    Grant_type : Client_Credentials

  Scope: https://xxxxxxxxxxxxxxxxxxxxxxxxxxx.cloudax.dynamics.com/.default ((dot)default mention this at the end) replace xxxxxxx with your environment url.

9. Mention this in url column (https://login.microsoftonline.com/xxxxxxxxxxxxxxxxxxxxxxx/oauth2/v2.0/token)     

( https://login.microsoftonline.com/TenentId/oauth2/v2.0/token ) and post it.


10. Go to test tab and run the below code (Please expose all the client id,BearerToken,Sercet token and grantType as Global Variables)

       <pre><code class="language-C#">

      var json = JSON.parse(responseBody);

      tests["Get Azure AD Token"] = !json.error && responseBody !== '' && responseBody !== '{}'       &&   json.access_token !== '';

     postman.setEnvironmentVariable("bearerToken", json.access_token);

     </code></pre>



11. Create one more collection for your requirement(Like Calling Custom service) Eg: In my case its         Call Service.

12. Below is the code of sample as JSON file. 

 (Note: All the below parameters are parameter methods[parm methods] which I created in RequestDataContract Class.)

         <pre><code class="language-C#">       

        {   "_request" :

                {   

                        "PaymentReference": "100000",

                        "TransDate": "2021-09-28",

                        "BankTransactionType": "ACH-P",

                        "PaymOriginId": "ACI-PP",

                        "PaymMethodName": "EPAY",

                        "InvoiceId": " ",

                        "AmountCurCredit": "0.00",

                        "AmountCurDebit": "25.47",

                        "AmountCur": "0.00",

                        "CustAccount": "100000451",

                        "DivisionId": "Test",

                        "Description": "ACH-P",

                        "TransactionText" :"TEST",

                         "ChequeStatus": "Created",

                         "OriginalConfirmation":  "100",

                         "LedgerJournalId": " "

            }

    }

  </code></pre>

13.Select POST type and paste custom service url which we created and Click Send Button

For Custom Service:

 https://xxxxxxxxxxxxxxxx.cloudax.dynamics.com/api/services/ServiceGroup/CustomerPaymentOptio nService/createRecord

For Odata:

https://xxxxxxxxxxxxxxxx.cloudax.dynamics.com/data/[DataentityName]


Output:

This output will get depends upon the respond data contract parameters which we created in Dynamics 365 F&O



Thanks....




No comments:

Post a Comment