← Back to team overview

dhis2-devs team mailing list archive

Re: [d2 lib] - API call failing with "Server connection failed for API request"

 

On Wed, Feb 21, 2018 at 11:31 AM, Martin Van Aken
<martin@xxxxxxxxxxxxxxxx> wrote:
> Now I'm trying a event analytics query:
>
> return getInstance().then(d2 =>
> d2.Api.getApi().get("/25/analytics/events/query/jqKm7VLgdzL?stage=tbLC6IHktf0&dimension:ou:VAPI4p81HAz;LEVEL-6&displayProperty=NAME"));
>
> And this show an error in the console with  "Server connection failed for
> API request"
>
> I've ran the query through the browser & Postman without any problems. I've
> debugged, the authorization header is correct.
>
> Any clue what could go wrong there?

Martin, I found one problem, possibly 2 with your code.
The first one is with the dimension parameter you're passing.

It should be:

dimension=ou:VAPI4p81HAz;LEVEL-6

instead of:

dimension:ou:VAPI4p81HAz;LEVEL-6

The second problem is URL encoding, specifically the ou dimension
query parameter.
The response I get in this case is "409: Dimension ou is present in
query without any valid dimension options."

It's better to pass the query parameters as a object in the 2nd
parameter of the get, so that the Api class takes care of all the URL
encoding, like this:

d2.Api.getApi().get('analytics/events/query/jqKm7VLgdzL', {
    stage: 'tbLC6IHktf0',
    dimension: 'ou:VAPI4p81HAz;LEVEL-6',
    displayProperty: 'NAME'
});

Once I do this, I get a different error about missing start and end
date, which is ok since this endpoint requires those parameters:
https://docs.dhis2.org/master/en/developer/html/webapi_event_analytics.html#webapi_event_analytics_request_query_parameters

Hope this helps,
-- 
Edoardo Sabadelli
DHIS 2
University of Oslo
edoardo@xxxxxxxxx
http://www.dhis2.org


Follow ups

References