Hi @maxmarkusprogram
In the future I recommend you to post in the Plugin Development forum when you have a question regarding plugin development. That way it’ll get the attention from the people that can answer your questions.
The problem in your code is that you are not calling the path you are defining in your plugin.json, you are merely calling the proxy url. that’s not enough.
This is what you currently have:
getBackendSrv().fetch({
// simply calling the data proxy url without
// specifying which path
url `${this.baseUrl}?${urlParams}`
});
you need to specify the path you want to call. From your plugin json I can see you named your route forecast
so you should modify your code like this:
getBackendSrv().fetch({
//notice I added `/forecast`
url `${this.baseUrl}/forecast?${urlParams}`
});
This will actually call the API you want.
Please don’t be confused thinking this will call /forecast
in your API url (i.e. https://api.openweathermap.org/data/2.5/forecast
), that’s not the case. that first path will match with your plugin.json defined route.
To understand this better, imagine that you defined 3 different routes in your plugin json: forecast
(the one you have now), health
and metrics
if you call baseUrl
without specifyin the path, how would the data proxy know which of those three to call?.
You might be wondering what if you want different paths of the same url? let’s say you want to call https://api.openweathermap.org/data/2.5/metrics
.
in that case all you have to do is add /metrics
after the path name (in this example /forecast
)
so you could write:
getBackendSrv().fetch({
// this will call the URL defined in the `forecasts` path
// and append `/metrics` to it
// this will call https://api.openweathermap.org/data/2.5/metrics
url `${this.baseUrl}/forecast/metrics?${urlParams}`
});
Additionally you should avoid hardcoding the url in the plugin.json, it is very likely the user will want to change it, so you can use a variable in the url field to populate it with something the user put in their configuration:
"routes": [
{
"path": "forecast",
"url": "{{ .JsonData.apiUrl }}",
"urlParams": [
{
"name": "pass",
"content": "{{ .SecureJsonData.password }}"
}
]
}
]