Sankar Bhavan
Sankar Bhavan

Reputation: 11

Azure Time series Insight preview API fail with Environment with id is not found

I have test TSI preview environment in azure connected to an IoTHub. I am experimenting with the TSI test APIs, however, there seems to be something I am doing wrong.

Here are the things that I did.

  1. Created a Service Principal
  2. Gave it access to my resource group with the TSI instance
  3. Using API https://login.microsoftonline.com/{{tenantId}}/oauth2/token to login and obtain a token.
  4. On the portal, it does not allow me to create a Data access policy for a Service Principle but the AZ CLI does, so I created one.
  5. My postman screenshot is given below, I am using the dataaccesFQDN as the prefix, and I have verified the environment ID as well.
    1. However, all the APIs call return,

{ "error": { "code": "ResourceNotFound", "message": "Environment with id 'a5442850-c542-4602-a289-5ec1e1064280' is not found." } }

Any thoughts on whats going wrong?

enter image description here

Upvotes: 1

Views: 550

Answers (2)

Mohamad Sobhie
Mohamad Sobhie

Reputation: 141

To get a token for the TSI API you need to register an application in your Azure active directory, the command for that is this:

az ad app create --display-name myAppName
// for more options like replyUrls or roles refer to https://learn.microsoft.com/en-us/cli/azure/ad/app?view=azure-cli-latest#az-ad-app-create

or if you want to do it using the portal you can follow these steps here Register Application Using Azure Portal

Next step is to create a password credential for the registered app, using this command in your power-shell

$startDate = Get-Date
$endDate = $startDate.AddYears(3)
$aadAppsecret = New-AzureADApplicationPasswordCredential -ObjectId <ObjectId of your registered application> -CustomKeyIdentifier "myPassword" -StartDate $startDate -EndDate $endDate

If you check the value of $aadAppsecret you should get the password which you will then use in your postman so you need to store it somewhere for later.

If you are unsure of how to get your ObjectId use this command:

az ad app list --display-name myAppName

Next step is to give the application an access to your TSI environment which you have done in your point 2

Finally in your postman do a POST request to

https://login.microsoftonline.com/<Tenant Id>/oauth2/token

And the body of the request should contain the following :

grant_type : client_credentials
client_id : <your registered appId>
client_secret : <the password you generated earlier>
resource: https://api.timeseries.azure.com/

Screenshot of the Postman Request

Upvotes: 3

Torched90
Torched90

Reputation: 305

Try using https://login.microsoftonline.com/{tenantId}

remove the /oauth2/token

Upvotes: 0

Related Questions