Access Mendix API from External application through Token

0
  Hi All, I have published an API in Mendix application and which will accessed by external application through  Token. We don’t wanted to provide access to Menidx app to users present in external application.    Could you pleas guide me on this issue .   Thanks , Girish  
asked
2 answers
0

To access the Mendix API from an external Angular application, you will need to use Mendix's published REST API. Here are the basic steps you need to follow:

  1. Create an API key in your Mendix application. To do this, log in to your Mendix application, go to the "Security" tab, and click on "API Keys". Then click "New API Key" and fill in the necessary details.

  2. Add an HTTP client library to your Angular application, such as HttpClientModule

  3. In your Angular application, make an HTTP request to the Mendix API using the API key you created in step 1. For example, you could use the following code to retrieve a list of entities from your Mendix application:

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable()
export class MendixService {

  private apiUrl = 'https://myapp.mendixcloud.com/rest/';

  constructor(private http: HttpClient) { }

  public getEntities() {
    const apiKey = 'my-api-key';
    const url = this.apiUrl + 'data/v1/entities';
    const headers = {
      'Mendix-ApiKey': apiKey
    };
    return this.http.get(url, { headers });
  }
}

In this example, myapp.mendixcloud.com is the URL of your Mendix application, and my-api-key is the API key you created in step 1.

  1. Handle the response from the Mendix API in your Angular application. You can use the subscribe() method to handle the response asynchronously. For example:
import { Component } from '@angular/core';
import { MendixService } from './mendix.service';

@Component({
  selector: 'app-root',
  template: '<ul><li *ngFor="let entity of entities">{{entity.name}}</li></ul>',
  providers: [MendixService]
})
export class AppComponent {

  public entities: any[];

  constructor(private mendixService: MendixService) { }

  ngOnInit() {
    this.mendixService.getEntities().subscribe(
      (data: any[]) => {
        this.entities = data;
      },
      (error) => {
        console.error(error);
      }
    );
  }
}

This code creates a simple Angular component that retrieves a list of entities from the Mendix API and displays their names in a list.

answered
-1

Hi Girish,

Simplest way would be to create user role to access the API and the token API and not grant any other access to this role which is not required for instance pages, home page etc.

Also, if you generate a token and share that with external application then it would not be possible for them to access your Mx app without for instance having the correct combination of username/password.

You can find more information on user roles here

Hope this helps!

answered