Skip to main content
Solved

Is it possible to download underlying table data from URL using JSON-query with POST - lost or totally lost?

  • September 19, 2018
  • 4 replies
  • 29 views

Hi,

I'm trying to download table data from Statistics Finland PX-Web API (documentation here http://pxnet2.stat.fi/api1.html). URL for example for the cube and the table containing population demographic data is: http://pxnet2.stat.fi/PXWeb/api/v1/fi/StatFin/vrm/vaerak/statfin_vaerak_pxt_001.px . Px-Web API can return table data in various formats, including csv and excel.

Using HTTPCaller and GET or/and JSON-reader I've been able to receive nested JSON containing list of all the different variables of the desired table, but the problem is that this request does NOT retrieve the actual data.

In my understanding I should send a specified JSON-query using GET/POST-command to API to be able to download the actual data. But I have no clue how to do this in FME. I've tried to go through JSON-readers schema scan using JSON-query, and I looked for the HTTPcaller but don't know if Query String Parameters or Body settings could help me with this. JSON-query should look somewhat like this:

{
  "query": [
    {
      "code": "Vuosi",
      "selection": {
        "filter": "item",
        "values": [
          "2017"
        ]
      }
    },
    {
      "code": "Sukupuoli",
      "selection": {
        "filter": "item",
        "values": [
          "S"
        ]
      }
    },
    {
      "code": "Ikä",
      "selection": {
        "filter": "agg:1-vuotisikä.agg",
        "values": [
          "SSS"
        ]
      }
    },
    {
      "code": "Tiedot",
      "selection": {
        "filter": "item",
        "values": [
          "lkm"
        ]
      }
    }
  ],
  "response": {
    "format": "csv"
  }
}

Any help (including sceencaps) to go futher with this is very much appreciated! :D

Best answer by mark2atsafe

I think you're correct. It is not returning data, it is just returning metadata. In fact, their web site says that the query you are using is for metadata:

0684Q00000ArLhQQAV.png

So that specifies the table and then - you are right - that you need to use a POST command to specify a query. What that involves is changing the type to post and then adding the query as the upload body:

0684Q00000ArLpaQAF.png

Also set the Content Type to JSON. The above is a snippet of JSON that I used:

{"query":[],"response":{"format":"json"}}

That is basically no query (so retrieve the entire table) and return the contents as JSON. According to their documentation the contents can also be returned as px, xlsx, or csv. I have little to no idea how their query language works! I am afraid I will leave that to you. I think you would just post the query inside this string, just as I did with the format.

So, when I try that, I get this:

0684Q00000ArLpiQAF.png

...which looks correct to me. 

I hope this helps get you started!

Mark

 

View original
Did this help you find an answer to your question?

4 replies

siennaatsafe
Safer
Forum|alt.badge.img+11
Hello @joukojarnefelt,

 

I believe I'm a little confused by your question. From my understanding, you are having difficulties downloading data using the HTTPCaller. You provided a link, http://pxnet2.stat.fi/PXWeb/api/v1/fi/StatFin/vrm/vaerak/statfin_vaerak_pxt_001.px here. Would you like to get that data from the HTTPCaller? When you use the HTTPCaller and with that Request URL and the HTTP Method GET, are you missing anything in the response body?

 

Thanks,

 

Sienna

 


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • Best Answer
  • September 19, 2018

I think you're correct. It is not returning data, it is just returning metadata. In fact, their web site says that the query you are using is for metadata:

0684Q00000ArLhQQAV.png

So that specifies the table and then - you are right - that you need to use a POST command to specify a query. What that involves is changing the type to post and then adding the query as the upload body:

0684Q00000ArLpaQAF.png

Also set the Content Type to JSON. The above is a snippet of JSON that I used:

{"query":[],"response":{"format":"json"}}

That is basically no query (so retrieve the entire table) and return the contents as JSON. According to their documentation the contents can also be returned as px, xlsx, or csv. I have little to no idea how their query language works! I am afraid I will leave that to you. I think you would just post the query inside this string, just as I did with the format.

So, when I try that, I get this:

0684Q00000ArLpiQAF.png

...which looks correct to me. 

I hope this helps get you started!

Mark

 


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • September 19, 2018
mark2atsafe wrote:

I think you're correct. It is not returning data, it is just returning metadata. In fact, their web site says that the query you are using is for metadata:

0684Q00000ArLhQQAV.png

So that specifies the table and then - you are right - that you need to use a POST command to specify a query. What that involves is changing the type to post and then adding the query as the upload body:

0684Q00000ArLpaQAF.png

Also set the Content Type to JSON. The above is a snippet of JSON that I used:

{"query":[],"response":{"format":"json"}}

That is basically no query (so retrieve the entire table) and return the contents as JSON. According to their documentation the contents can also be returned as px, xlsx, or csv. I have little to no idea how their query language works! I am afraid I will leave that to you. I think you would just post the query inside this string, just as I did with the format.

So, when I try that, I get this:

0684Q00000ArLpiQAF.png

...which looks correct to me. 

I hope this helps get you started!

Mark

 

Here's the workspace I created. It's currently returning data as CSV, but you can change that to something else quite easily. fi-workspace.fmw

 

 


mark2atsafe wrote:

I think you're correct. It is not returning data, it is just returning metadata. In fact, their web site says that the query you are using is for metadata:

0684Q00000ArLhQQAV.png

So that specifies the table and then - you are right - that you need to use a POST command to specify a query. What that involves is changing the type to post and then adding the query as the upload body:

0684Q00000ArLpaQAF.png

Also set the Content Type to JSON. The above is a snippet of JSON that I used:

{"query":[],"response":{"format":"json"}}

That is basically no query (so retrieve the entire table) and return the contents as JSON. According to their documentation the contents can also be returned as px, xlsx, or csv. I have little to no idea how their query language works! I am afraid I will leave that to you. I think you would just post the query inside this string, just as I did with the format.

So, when I try that, I get this:

0684Q00000ArLpiQAF.png

...which looks correct to me. 

I hope this helps get you started!

Mark

 

Just perfect! Thanks @Mark2AtSafe! This is just what I was looking for!

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings