← Back to team overview

dhis2-devs team mailing list archive

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

 

You are correct for the error message - now putting back a period means
having multiple dimension's - is there any way to put multiple dimension
parameters through the object params? I agree this is much better than
using a long query string, but just using an array as value does not work -
I tried something like:

return getInstance().then(d2 =>
          d2.Api.getApi().get('analytics/events/query/jqKm7VLgdzL', {
            stage: 'tbLC6IHktf0',
            dimension: ['ou:VAPI4p81HAz;LEVEL-6','xxx'],
            displayProperty: 'NAME'
        }));

but this is not working. Any clues?

Martin

On Wed, Feb 21, 2018 at 2:40 PM, Edoardo Sabadelli <edoardo@xxxxxxxxx>
wrote:

> 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
>



-- 
*Martin Van Aken - **Freelance Enthusiast Developer*

Mobile : +32 486 899 652

Follow me on Twitter : @martinvanaken <http://twitter.com/martinvanaken>
Call me on Skype : vanakenm
Hang out with me : martin@xxxxxxxxxxxxxxxx
Contact me on LinkedIn : http://www.linkedin.com/in/martinvanaken
Company website : www.joyouscoding.com

Follow ups

References