Advertisements

Archive

Posts Tagged ‘Postman’

Post a File and Data to SandBlast API using Postman and generate C# code

We got a requirement to use SandBlast Threat Extraction  process, for cleansing the files.

SandBlast Threat Extraction, is a solution by ‘Check Point’ company,  which removes exploitable content, including active content and embedded objects, reconstructs files to eliminate potential threats.

‘Threat Extraction’ Upload API, requires following parameters

  • Header
    • Authorization
    • Content-Type
  • Body
    • File Content
    • request (This is string)

If you notice, we need to pass ‘File’ as well as ‘Data’ to the API.

As of now, Sandblast doesn’t have a native .Net library to make API calls. So I’ve used Postman tool as a starting point for my development.

Below is the step-by-step, to pass ‘File’ and ‘Data’ in request ‘Body’, using Postman

  • Open Postman tool
  • Create a new ‘Request’

PM_2

  • Set the method as ‘Post’ and URL.
  • From the ‘Body’ tab, select ‘form-data’ option
  • To pass the ‘File’,  add a new ‘KEY’ of type ‘File’ and browse the file in ‘VALUE’ parameter.
  • To pass the ‘Data’, add a new ‘KEY’ of type ‘Text’ and set the ‘VALUE’

PM_1

Generate C# code from the Request:

  • Postman has an amazing feature to generate the code in your required language.
  • Click on ‘Code’ link and for C#, choose ‘C# (RestSharp)’ option.

PM_3

If anyone having struggling to use Sandblast API’s, post in comments section and I will address.

🙂

 

Advertisements
Categories: Misc Tags: , , ,

[Step by Step] Postman tool to test Dynamics 365 online Web API

February 13, 2019 7 comments

In this article, lets see how to connect and test Dynamics 365 Web API requests using Postman tool, step by step along with troubleshooting steps.

Those who are not familiar with Postman tool, it is a request composer tool, which allows you to authenticate to your Dynamics 365 instance,  compose Web API requests, send them, and view response. Link to download

Prerequisites:

  • Download Postman tool
  • Dynamics 365 online instance. (Subscribe to 30 days trial, if you have not one)
  • Azure Active Directory Portal (You need to login with your Office 365 Credentials)

Register App in Azure Active Directory:

As a first step, you need to register an App in Azure Active Directory (i.e., oAuth) by following below steps

  • Connect to the Azure Active Directory (AD) Portal with your Office 365 credentials.
  • Register a new Dynamics 365 App by following steps mentioned here
  • Once you are done with App registration, copy ‘Application ID’ and ‘Home page’ values, which you need to use next steps.

PostMan_14

Setup your Postman tool:

Create ‘Environment’

  • Create a new Postman ‘Environment’ with below variables. This is one time activity for a single D365 instance.
    • url : Your Dynamics 365 URL
    • clientid : ‘Application ID’ from Azure AD,  generated in above section.
    • version : Dynamics version
    • webapiurl : Set this to {{url}}/api/data/v{{version}}/
    • callback : ‘Home page’ value from Azure AD,  generated in above section.
    • authurl : Set this to https://login.microsoftonline.com/common/oauth2/authorize?resource={{url}}
  • I created a new ‘Environment’ with name ‘DynamicsCRM’ and it looks as below

PostMan_13

Generate oAuth Access Token:

Post ‘Environment’ creation, we need to generate oAuth Access Token. This is one time activity for a single D365 instance.

  • Make sure you select ‘Environment’ created in previous section. In my case its ‘DynamicsCRM’.
  • Under ‘Authorization’ tab, set ‘Type’ to ‘oAuth 2.0’ and click on ‘Get New Access Token’.

PostMan_15

  • In the ‘GET NEW ACCESS TOKEN SCREEN’ make sure you set values as below.

PostMan_1

  • Click ‘Request Token’ and system will prompt you for credentials, pass your O365 credentials.

PostMan_2

  • When you click ‘Next’, you may encounter “response_type ‘token’ is not enabled for the application” exception.
    • To fix this, make sure in your Azure AD Application’s manifest “oauth2AllowImplicitFlow” property is set to ‘true’

PostMan_4

  • You may also encounter “The reply url specified in the request does not match the reply urls configured for the application“.
    • To fix this, make sure you set the Postman’s ‘Environment’ -> ‘callback’ variable set correctly.
  • Click ‘Continue’ to complete the ‘Access Token’ generation process.
  • On successful ‘Access Token’ generation, you would get the screen as below.

PostMan_8

  • Click ‘Use Token’.

That’s it! we are done with settings and its time to test the Dynamics API’s with Postman

Test by executing ‘WhoAmI’ request:

  • Make sure you select the right ‘Environment’ and generated your ‘Access Token’.
  • Select ‘GET’ operation and set the URL as {{webapiurl}}WhoAmI
  • Click ‘Send’
  • You should get “200 OK” response up on success.

PostMan_10

  • You may get “401 Unauthorized” response.

PostMan_11

  • To fix this, make sure you set “Add authorization data to” to “Request Headers”.

PostMan_12

🙂