1

Endpoint: https://graph.microsoft.com/v1.0/deviceAppManagement/mobileApps

Error:

RuntimeError - {"error"=>{"code"=>"BadRequest", "message"=>"Request not applicable to target tenant.", "innerError"=>{"request-id"=>"476e2f7d-e539-4b93-82c1-45be7e0b183b", "date"=>"2019-07-18T08:21:53"}}}

I am trying to fetch all apps from my Microsoft account but I got a runtime exception. Using the same approach I am Successful to fetch all users.

def admin_authorize
    client = Signet::OAuth2::Client.new(
      authorization_uri: 'https://login.microsoftonline.com/51f6420c-47a1-4701-8bf9-e5b71795f17a/adminconsent',
      client_id: CLIENT,
      redirect_uri: 'http://localhost:3000/integrations/microsoft/oauth2callback',
      state: '12345678900'
    )
    redirect_to client.authorization_uri.to_s
end

def authorize_callback
    if params[:admin_consent] == "True"
      response = token
      #users response.parsed_response["access_token"]
      apps response.parsed_response["access_token"]
    else
      redirect_to 'http://test-company.localhost:3000/dashboard'
    end
end

def token
    body = {
          grant_type: 'client_credentials',
          client_id: CLIENT,
          client_secret: SECRET,
          scope: 'https://graph.microsoft.com/.default',
          redirect_uri: 'http://localhost:3000/integrations/microsoft/oauth2callback',
        }
    headers = {'Content-Type': "application/x-www-form-urlencoded"}
    response = HTTParty.post "https://login.microsoftonline.com/#{TENANT}/oauth2/v2.0/token", headers: headers, body: body
end

def users access_token
    url = '/v1.0/users'
    response = make_api_call url, access_token
    raise response.parsed_response.to_s || "Request returned #{response.code}" unless response.code == 200
    response.parsed_response['value']
end

def apps access_token
    url = '/v1.0/deviceAppManagement/mobileApps'
    response = make_api_call url, access_token
    raise response.parsed_response.to_s || "Request returned #{response.code}" unless response.code == 200
    response.parsed_response['value']
end

def make_api_call(endpoint, token, params = nil)
    headers = {
      Authorization: "Bearer #{token}",
      'Content-Type': 'application/json'
    }
    query = params || {}
    HTTParty.get "#{GRAPH_HOST}#{endpoint}",
                    headers: headers,
                    query: query
end

1 Answer 1

1

All Intune Graph APIs require Azure AD Premium P2 version. If you enable Azure AD Premium P2 then it will give output.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.