How to Call Remote API from ADF

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
vidhipanchal
Established Member

How to Call Remote API from ADF

Jump to solution

Hello

I have configure my adf with alfresco by giving Ip address like xxx.xxx.x.x:8080 and i am also able to login.

Now I am trying to call custom webscript from adf using below api

import * as AlfrescoApi from 'alfresco-js-api';
alfrescoJsApi: any;
constructor(private apiService: AlfrescoApiService) {
   this.alfrescoJsApi = new AlfrescoApi({ provider: 'ALL' });
   this.alfrescoJsApi.core.webscriptApi.executeWebScript('GET', 'api/task-instances?authority=' +    this.authService.getEcmUsername())
}

but api is call localhost url like this

http://127.0.0.1:8080/alfresco/service/api/task-instances?authority=admin

insted of my configured ip.

How can i solve this?

Thanks

Vidhi

1 Solution

Accepted Solutions
Moderator
Moderator

Re: How to Call Remote API from ADF

Jump to solution

Hi the problem in your code is that you are instantiating a new alfrescoApi when you do :

   this.alfrescoJsApi = new AlfrescoApi({ provider: 'ALL' });

and this API new object is missing of configuration of the ecmHost that you should pass in the constructor.

In your case, you are already anyway injecting the ADF AlfrescoApiService in the constructor when you do 

constructor(private apiService: AlfrescoApiService) {
....
}
and you could use that instance of the js-api to do your job:

constructor(private apiService: AlfrescoApiService) {
this.apiService.getInstance().webScripti.executeWebScript('GET', 'api/task-instances?authority=' +   this.authService.getEcmUsername())
}
3 Replies
Moderator
Moderator

Re: How to Call Remote API from ADF

Jump to solution

Hi the problem in your code is that you are instantiating a new alfrescoApi when you do :

   this.alfrescoJsApi = new AlfrescoApi({ provider: 'ALL' });

and this API new object is missing of configuration of the ecmHost that you should pass in the constructor.

In your case, you are already anyway injecting the ADF AlfrescoApiService in the constructor when you do 

constructor(private apiService: AlfrescoApiService) {
....
}
and you could use that instance of the js-api to do your job:

constructor(private apiService: AlfrescoApiService) {
this.apiService.getInstance().webScripti.executeWebScript('GET', 'api/task-instances?authority=' +   this.authService.getEcmUsername())
}
vidhipanchal
Established Member

Re: How to Call Remote API from ADF

Jump to solution

Hi Eugenio Romano,

Thanks for reply.

What is the difference between "alfrescoJsApi.core.webscriptApi" and "apiService.getInstance().webScript"?

Thanks

Vidhi

Moderator
Moderator

Re: How to Call Remote API from ADF 

Jump to solution

The first is a new instance that you are going to declare that is nor initialized by ADF and you need to configure it and handle the lifecycle.

The second is an instance created by ADF when bootstrap the core. It gets the configuration from the app.config.json of the framework and you can consume it without care about the lifecycle of it