0

I am new to this topic and reviewed several SO answers before, but still cannot figure it out.

Trying to access API, using R:

curl -X POST "http://api.spending.gov.ua/api/rest/1.0/transactions" -H "accept: application/json" -H 
"Content-Type: application/json" -d "{ \"payers_edrpous\": [ \"string\" ], \"recipt_edrpous\": [ 
\"string\" ], \"startdate\": \"string\", \"enddate\": \"string\", \"regions\": [ 0 ]}"

My current stage

library(httr)
r <- GET("http://api.spending.gov.ua/api/rest/1.0/transactions")

status_code(r)

This works, I have 200 response. But how to write a query to get data in json format? Appreciate any tips.

6
  • 2
    Have you seen this post: stackoverflow.com/questions/56958500/… ? This might point you in the right direction. Commented May 11, 2020 at 11:45
  • 1
    Do you have some sample data that can be tested on the API test page? Commented May 12, 2020 at 19:33
  • @dcruvolo, I checked it, still do not understand :(. Commented May 12, 2020 at 20:30
  • @Dave2e, apologize, not sure what do you mean :(. If you can tell me any example of how to query any data from there, using their variables, I would be very grateful. Commented May 12, 2020 at 20:31
  • 1
    I don't understand the language thus it makes it impossible to fill in the blanks. So values for payers_edrpous, recipt_edrpous, start date, endnote and regions would help Commented May 12, 2020 at 20:44

1 Answer 1

2

The link from @dcruvolo was helpful.

In order get to this to work, you need to start with some valid values. From the API link in the question, there is a test page to order to test the submittal:

enter image description here

One can substitute in test values and then press the "Execute" button submit values. Attempted values from the comments above, valid enough not to cause an error but also did not return any valid results.

To perform the POST in R here is an example:

posting<-'{
  "payers_edrpous": [
    "00013534"
  ],
  "recipt_edrpous": [
    ""
  ],
  "startdate": "2020-03-01",
  "enddate": "2020-03-28",
  "regions": [
    0
  ]
}'

library(httr)
r <- POST("http://api.spending.gov.ua/api/rest/1.0/transactions", body=posting, 
          httr::add_headers(`accept` = 'application/json'), 
          httr::content_type('application/json')) #encode="json"
content(r)

Posting is the JSON body to pass, edit this as necessary. All variables are strings except "regions" where it is an integer, not sure what the valid range is.

Sorry this is the best I can do. Good luck.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.