If you use Visual Studio Code and worked with API you probably know the extension called REST Client. It has more than 2 million downloads, the advantages are that you can use it inside Visual Studio Code (meaning you don't need to have or switch to Postman) and it has a file format (.http) to save the requests.
Let me be clear here, I prefer Postman but as I said many times not everybody uses the same tools so let's explore a bit how REST Client extension works.
If you don't consider authentication it's pretty simple, you write your endpoint and you can click to execute the request, something like this:
First of all we create/update the settings.json in order to add the required syntax by REST Client to add environment variables, like this:
{ "rest-client.environmentVariables": { "$shared": {}, "Dataverse": { "url": "https://mydemo.crm.dynamics.com", "tenantid": "89d6b4f0-f93c-4d88-800c-ff6acdae523a", "clientid": "71aa6fe0-040f-493f-b19d-9f248692bf93", "clientsecret": "notsosecret" } } }
If you are familiar with REST Client you probably done something similar, in the above example we defined a "Dataverse" environment and we can use the defined variables.
REST Client format allows to save multiple requests in a single .http file and reuse variables filled by previous requests, the idea here is to first execute a request to get the bearer token and use it as authorization for the next requests.
If we use the V2 Endpoint the request would be like this:
### Get Access Token # @name getAADToken POST https://login.microsoftonline.com/{{tenantid}}/oauth2/v2.0/token Content-Type: application/x-www-form-urlencoded grant_type=client_credentials&client_id={{clientid}}&client_secret={{clientsecret}}&scope={{url}}/.default ### Extract access token from getAADToken request @token = {{getAADToken.response.body.access_token}}We are using the variables defined inside the settings.json and store the bearer token inside a variable called token.
### Get Contacts GET {{url}}/api/data/v9.1/contacts?$select=contactid,fullname Authorization: Bearer {{token}} OData-MaxVersion: 4.0 OData-Version: 4.0 Content-Type: application/json; charset=utf-8 Accept: application/json Prefer: odata.include-annotations=*In this way you can now execute your queries inside REST Client.
Hope it helps
Hello,
ReplyDeleteThank you for providing this amazing tool.
I have a question will it be possible using this tool to query EntityDefinitions attributes?
Example: /api/data/v9.2/EntityDefinitions(LogicalName='account')/Attributes(LogicalName='emailaddress1')
Or if you want to query multiple specific attributes what will be the URL? I tried the below but it doesn't work:
/api/data/v9.2/EntityDefinitions(LogicalName='account')/Attributes(LogicalName='emailaddress1' and LogicalName='emailaddress2')
Hi Julien, right now the tool doesn't allow to fetch that kind of metadata, regarding your query I believe the correct syntax would be api/data/v9.2/EntityDefinitions(LogicalName='account')/Attributes?$select=LogicalName,SchemaName
ReplyDelete