← Back to team overview

dhis2-devs team mailing list archive

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

 

Ok, sorry, figure it out, just require a "new" as Request is a class:

const req = new d2.analytics.request()
.withProgram('jqKm7VLgdzL')
.addDataDimension(['fyKddt8DF3P', 'RH9knJBq3gv', 'GbtVi9hJhl1',
'pCU50gRMGQh', 'el1mbPDIDSD', 'sn3PEvqjGPp', 'jsZgVNf1fuR'])
.addPeriodDimension([2016, 2017, 2018])
.addOrgUnitDimension(['UpjTv540YGw']);

But this falls back to the same problem as before - getting a server error
("uncaught exception: Server connection failed for API request:") - despite
the exact same request working as a REST call.

Martin

On Wed, Feb 28, 2018 at 3:20 PM, Martin Van Aken <martin@xxxxxxxxxxxxxxxx>
wrote:

> Hello again Edoardo & d2 team,
> I just tested the d2 29x version for the analytics. My problem is I don't
> manage to make the simplest example work. I took an analytics query working
> in the REST API and tried to convert it to d2:
>
> getAnalytics() {
> return getInstance().then(d2 => {
> const req = d2.analytics.request()
> .withProgram('jqKm7VLgdzL')
> .addDataDimension(['fyKddt8DF3P', 'RH9knJBq3gv', 'GbtVi9hJhl1',
> 'pCU50gRMGQh', 'el1mbPDIDSD', 'sn3PEvqjGPp', 'jsZgVNf1fuR'])
> .addPeriodDimension([2016, 2017, 2018])
> .addOrgUnitDimension(['UpjTv540YGw']);
>
> d2.analytics.events.getQuery(req).then(console.log)
> });
> }
>
>
> (this is closely following the example here: http://dhis2.github.io/d2/
> module-analytics.AnalyticsEvents.html)
>
> This fails with a "Cannot call a class as a function AnalyticsRequest.js
> :25
> <http://localhost:3000/home/martin/code/dhis2/unicef-va-reports/node_modules/d2/lib/analytics/AnalyticsRequest.js>"
> message, on the very first line about the request (looks like request() is
> not returning what it expect). Any clue?
>
> Martin
>
> On Fri, Feb 23, 2018 at 12:31 PM, Edoardo Sabadelli <edoardo@xxxxxxxxx>
> wrote:
>
>> On Thu, Feb 22, 2018 at 10:14 AM, Edoardo Sabadelli <edoardo@xxxxxxxxx>
>> wrote:
>>
>> > Still it will be much easier to build analytics requests with
>> d2.analytics.
>>
>> Support for analytics and geofeatures requests in d2 is out!
>>
>> d2@29.0.2
>>
>> Check it out!
>> --
>> 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
>



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

References