I have created a simple Hello World API that is called in a dashlet. The problem is it is not returning and not running success or error.
The dashlet should call the api and then console.log what is being return, which is hello world.
I have created a simple Hello World API that is called in a dashlet. The problem is it is not returning and not running success or error.
The dashlet should call the api and then console.log what is being return, which is hello world.
Are you receiving a 200 status when calling the endpoint?
I have installed your MLP into a local instance of Sugar. I made a basic GET call in Postman to {{url}}{{api_version}}/Hello/World/7 and my return result was "Hello World"
So i dont think there's anything wrong with your endpoint itself. I'm betting it has something to do with how you are calling it. I assume you are authenticating first and using the access_token. Otherwise, i'd think you would see at least some error message. Can you share with us your JS that is calling the endpoint?
I am calling the endpoint within the dashlet.(See custom/clients/base/views/hello-world-api/hello-world-api.js) I assumed since I was calling it from with in the dashlet, I would not need to auth.
I see. sorry about that. i didnt look at the other files!
I believe the issue is that nothing is calling your loadData function.
Try adding this.loadData() to your initialize function.
I added this.loadData() to both the initialize2021.HelloWorldAPI.zip and render function and neither work.
You don't have to add a slash before app.api.buildURL - that will generate a double slash which might not work in some browsers.
Eg: Change app.api.buildURL('/Hello/World/1') to app.api.buildURL('Hello/World/1')
The first thing that I noticed is that: The success/failure function is outside of app.api.call. It has to be passed as the last argument so that it can be used as a callback.
ie:
app.api.call('GET', app.api.buildURL('/Hello/World/1'), null),
{
success: function(data){
if(this.disposed){
return;
}
console.log(data);
},
error: function (e) {
console.log('error');
console.log(e);
}
}
Should be changed to:
app.api.call('GET', app.api.buildURL('/Hello/World/1'), null,
{
success: function(data){
if(this.disposed){
return;
}
console.log(data);
},
error: function (e) {
console.log('error');
console.log(e);
}
});
This should fix your callbacks. The API definition looks correct.
Thank you both!!! It works now.
Is there a good tutorial to look at what the api is returning using postman?
I always refer to this tutorial which has a Postman cookbook which can be used to get/set access tokens:
sugarclub.sugarcrm.com/.../sugarcrm-cookbook---the-school-of-rest---part-1
I have created a Hello World API package. The API sends Hello world and a number. The Dashlet calls the API with the number and receives Hello World and the number and then it adds it to the dashlet inside the app.api.call() with _.extend.HelloWorldAPIv2.zip