Hi! Is there an easy way to call the CSV export fo...
# gooddata-platform
p
Hi! Is there an easy way to call the CSV export for a given insight using the API? I'd like to implement unit tests that check coherence with expected results within our data warehouse
1
p
Hey Martin! Thanks for your answer. Will this provide a static output (runs once and saves under an ID) or will it recalculate every time I query the API?
And is there an endpoint that allows recalculation every time?
m
GoodData Platform (the hosted version) provides always recalculated data. There is now way how to get old results. Data loads invalidates report caches.
p
Nice, great thanks! And the endpoint is always the same for a given insight?
m
There are 2 options 1. Documented - You have to execute insight (resource executeAfm), take the payload, save it somewhere and when you want to do the export, you run the payload against executeAfm, take resonse and run it against exportResult 2. Undocumented - There is secret resource executeVisualisation, it can execute insight without knowing body of for executeAfm.
p
So for option #1 I have to run executeAfm, save the response body and later run executeAfm with said body of the first run of executeAfm?
m
If you want to do it one time, you need to save and use response body, if you want to do it repeatedly you have to save request body and then do > executeAfm > exportResult
p
OK thanks!
@Martin Burian After looking into it some more, I realize that using executeAfm would require me to open the devtools & copy the request body every time I modify an insight so as to update my ci tests. If I can save that step by using the executeVisualisation endpoint that would be really helpful. What's the URL, method, query params, and request body necessary for executeVisualisation?
m
resource /gdc/app/projects/pid/executevisualization
Copy code
{
  "visualizationExecution": {
    "reference": "/gdc/md/PID/obj/ObjIdOfAd"
  }
}
p
Hey Martin! For the following request:
Copy code
POST https://{{GD_HOSTNAME}}/gdc/app/projects/{{GD_PROJECT}}/executevisualization

{
  "visualizationExecution": {
    "reference": "/gdc/md/{{GD_PROJECT}}/obj/{{GD_VISUALIZATION}}"
  }
}
For which:
Copy code
GD_HOSTNAME=<http://votresucces-dev.on.gooddata.com|votresucces-dev.on.gooddata.com>
GD_PROJECT=vyx9zuicsvv3rtjk9ry1myao6x4i2a40
GD_VISUALIZATION=3911
I get 404:
Copy code
{
  "error": {
    "errorClass": "NotFoundException",
    "trace": "",
    "message": "Resource not found /gdc/app/projects/vyx9zuicsvv3rtjk9ry1myao6x4i2a40/executevisualization",
    "component": "Webapp",
    "errorId": "7ea9bdfc-c1a2-4080-a95e-1bca99022d47",
    "errorCode": "gdc851",
    "parameters": []
  }
}
Is there something I am missing? Alternatively can I get the afm from querying the visualization object? That way I could do GET visualization object, GET afm, executeAfm, exportResult
m
My super bad! I am so sorry!!! the resource is case senstive it is executeVisualization
If I am not mistaken it is not easily possible to transform visualizationObject to AFM... It is done in the JS code. Easier way is to use the executeVisualization ... with capital V.
p
No worries! 🙂 So then I'm definitely better off to have a date field filter on the visualization so that the execution result is always consistent, and I can override it with the dashboard's date filter.
I will use executeVisualization then 🙂
m
The executeVisualization support adding filters I think let me check.
p
OooOOhhh! I'm definitely interested
m
Copy code
{
  "visualizationExecution": {
    "reference": "/gdc/md/PID/obj/1",
    "filters": [
      {
        "positiveAttributeFilter": {
          "displayForm": {
            "uri": "/gdc/md/PID/obj/2"
          },
          "in": {
            "uris": [
              "/gdc/md/PID/obj/3/elements?id=9"
            ]
          }
        }
      },
      {
        "positiveAttributeFilter": {
          "displayForm": {
            "uri": "/gdc/md/PID/obj/4"
          },
          "in": {
            "uris": [
              "/gdc/md/PID/obj/5/elements?id=8"
            ]
          }
        }
      }
    ]
  }
}
example ^
p
OK, and what are these elements ids? Dates?
m
Those are values of the attribute.
p
And I guess I can query those to know which is which?
m
Sure ... go to ... /gdc/md/PID/query/attributes .. chose attribute and click to elements
btw this is really low level technic ... maybe it would be easier to use our GoodData.UI = JS SDK
p
Yea, I'm also starting to think this is very complex 😅
I could, but that would mean that I would have to write my tests in JS rather than in python, which is the language of my data pipeline. I think I'll have to ponder a bit more whether or not I will put tests in place 😅
m
More about filters is possible to find here - https://sdk.gooddata.com/gooddata-ui/docs/4.1.1/afm.html#measure-with-global-filters but it already contains some abstraction provided by the SDK. New versions work little bit differently. 4.1.1 is old.
I recommend to at least look into the GoodData.UI. It could be useful for other use cases - https://sdk.gooddata.com/gooddata-ui/docs/about_gooddataui.html
p
Looking at the docs already 🙂
Can I use GoodData.UI to query an existing GoodData visualization and receive the result without having to render a React component?
Cause my main goal is to have an easy way to test that the results of my visualizations match the upstream data
m
I will check with our experts.
I discussed with our engineering and we will support it in next version of GoodData.UI SDK. Currently it is possible, but tricky. Something similar was discussed here: https://gooddataconnect.slack.com/archives/C01P3H2HTDL/p1650460737363029?thread_ts=1650036162.072649&amp;cid=C01P3H2HTDL
p
Hey Martin, thanks for circling back 🙂 At this time, I'm implementing in python with executeVisualization. If I encounter blocking issues, maybe I'll consider using GD UI, but I think it's very unlikely given the rest of the code base is in python. I could wrap the above code in a Jupyter Notebook and then obtain the result back in python, but that sounds like a lot of work
👍 1
Hey Martin! I confirm I was able to use executeVisualization endpoint to build some automated test suite. Works really well 🙂 Cheers!
m
NICE!!!!
😄 1
Anything else I can help with?
p
Nope, works well! 🙂
m
Good work.
p
Thanks!