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.
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:
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.
Related
Hi I have this cURL request that I have been trying and failing to get it right, it gives me a 500 Error (Internal Error)
Please see my curl request below:
curl --location --request POST "https://api.monday.com/v2" --header "Authorization: XXXXX" --header "Content-Type: application/json" --data-raw "{\"query\":\"mutation { create_item (board_id: 1622487816,group_id: \"emailed_items\", item_name: \"Test from Curl\") { id } }\"}" -v
I get back an empty object as a response but on the response header I see a 500 error message
Make sure your quotes are nested and escaped properly.
Your code:
"{\"query\":\"mutation { create_item (board_id: 1622487816,group_id: \"emailed_items\", item_name: \"Test from Curl\") { id } }\"}"
You are right to begin with a double quote and you are right to escape the first set of quotes within those quotes.
However, when you get further in the query, "emailed_items" also needs to be escaped, but since you are already in a set of quotes, you actually need three backslashes.
Corrected code:
"{\"query\":\"mutation { create_item (board_id: 1622487816,group_id: \\\"emailed_items\\\", item_name: \\\"Test from Curl\\\") { id } }\"}"
Make use of the npm package for monday.com queries. One such package is monday-sdk-js
Assigning parameters could be confusing thus make use of this package which takes query as a parameter and makes things easy.
I am trying to pass the below API request in ROBOT framework:
curl --request POST --url <API End Point> --form 'mldata={"id": “idname”, "author": “author name, "title": “title name, "description": “description details“, "version": "0.0.4", "image": “/path/to/image”, "icon": "base64 encoded image"};type=application/json' --header "Authorization: <Bearer Token>”
Written the same in ROBOT framework [Version: 3.2.2], but getting error: "status=400, reason=Bad Request body={"message":"Request is not a multipart request!"}"strong text
It seems I am not passing the --form data in a right way. Request for help in passing the form data [--form 'mldata={"id": “idname”, "author": “author name, "title": “title name, "description": “description details“, "version": "0.0.4", "image": “/path/to/image”, "icon": "base64 encoded image"};type=application/json'] in robot framework.
How should I pass in the right way?
Onboard ML From External Repo
[Arguments] ${token}=default
Create Session session ${host}
${data}= Create Dictionary id=${id} author=${author} title=${title} description=${description} version=${version} image=${repo_path}
${form_data}= Evaluate {'mldata=': ${data}}
${header}= Create Dictionary Authorization=${token}
${response}= Post Request session /v1/ml data=${form_data} headers=${header}
Should Be Equal As Strings ${response.status_code} 200
I tried the below code and it worked. There are two modifications I had done from the original post.
No dictionary is created, instead all the items are directly evaluated
Instead of 'data', passing 'files' in post request, as for multi-form request, files is required.
Onboard ML From External Repo
[Arguments] ${token}=default
Create Session mxesession ${host}
# ${data}= Create Dictionary id=${id} author=${author} title=${title} description=${description} version=${version} image=${repo_path} "icon": ${icon_image}
${form_data}= Evaluate {'mldata': (None,'{"id": "${id}", "author": "${author}", "title": "${title}", "description": "${description}", "version": "${version}", "image": "${repo_path}", "icon": "${icon_image}"}')}
# ${form_data}= Evaluate {'mldata': "'"+${data}+"'"}
# ${form_data}= Evaluate {'mldata': str(${data})}
# ${form_data}= Evaluate {'mldata': (None,str(${data}))}
# ${form_data}= Evaluate {'mldata': (None,${data})}
${header}= Create Dictionary Authorization=${token}
${response}= Post Request session /v1/ml files=${form_data} headers=${header}
Should Be Equal As Strings ${response.status_code} 200
I am not sure is it the right way for passing multi-form data, but it worked in my case. If anyone has a better workable idea, please comment. It will be helpful for me to refine this code to a much better shape.
Updated the answer as per #PDHide comments.
Onboard ML From External Repo
[Arguments] ${token}=default
Create Session mxesession ${host}
${data}= Create Dictionary id=${id} author=${author} title=${title} description=${description} version=${version} image=${repo_path} "icon": ${icon_image}
${form_data}= Evaluate {'mldata=': str(${data}).replace("'",'"')}
${header}= Create Dictionary Authorization=${token}
${response}= Post Request session /v1/ml files=${form_data} headers=${header}
Should Be Equal As Strings ${response.status_code} 200
P.S. Thanks #PDHide for your support.
It should be send as a string , and also you don't need equal
${form_data}= Evaluate {'mldata=': str(${data}).replace("'",'"')}
As you observed , we have to pass this as
files=${form_data}
This was what ended working for me. For anyone else with this issue
${data}= Evaluate {'username': (None, 'myusername'), 'password': (None, 'mypwd')}
${response}= Post Request ${Session_id} ${AUTH_TOKEN_URL_PATH} files=${data}
Using this link: https://learn.microsoft.com/en-us/azure/cognitive-services/form-recognizer/quickstarts/curl-train-extract I follow each step and use the sample data in the guide. All of them are successful until the last step which is "Get the Analyze results", where it returns the following:
{
"status": "failed",
"createdDateTime": "2020-07-09T14:59:12Z",
"lastUpdatedDateTime": "2020-07-09T14:59:14Z",
"analyzeResult": {
"version": null,
"readResults": null,
"pageResults": null,
"documentResults": null,
"errors": [
{
"code": "2003",
"message": "Download failed. Please check your input URL."
}
]
}
}
Unfortunately, there are no references to error codes and possible explanation/solutions. Assistance is highly appreciated.
The error message is quite clear: the url that you provided for the analysis does not allow the service to download the document.
Please check the content that you sent during the operation called "Analyze forms for key-value pairs and tables":
curl -v "https://<Endpoint>/formrecognizer/v2.0/custom/models/<model ID>/analyze" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: <subscription key>" -d "{ \"source\": \""<SAS URL>"\" } "
In particular, can you detail the last part? The piece with the '' block is the one causing the error
I have some problem with the "Find Entities by URNs" API in order to retrieve the metadata and value information for a collection of URNs.
If I use the URL described in the doc (Sample request) with a valid access token:
https://api.linkedin.com/v2/adTargetingEntities?q=urns&urns=List(urn%3Ali%3AfieldOfStudy%3A100990,urn%3Ali%3Aorganization%3A1035,urn%3Ali%3Aseniority%3A9)&locale=(language:en,country:US)&oauth2_access_token=<a-valid-token>
I receive the message:
{
"serviceErrorCode": 0,
"message": "java.lang.ClassCastException",
"status": 500
}
Anyone have experience the same issue? Any idea how to fix it?
Also: how can i contact for technical support as in this case?
UPDATE:
I made some try and I fix using the following version:
https://api.linkedin.com/v2/adTargetingEntities?q=urns&urns=urn%3Ali%3AfieldOfStudy%3A100990&urns=urn%3Ali%3Aorganization%3A1035&urns=urn%3Ali%3Aseniority%3A9&locale.language=it&locale.country=IT&oauth2_access_token=<a-valid-token>
BUT the locale/language translation is not working. Could be this a working solutions?
From the support team:
Our docs are missing 1 critical piece of information. Whenever using
LIST and encoded URNs in the URL, we expect an additional header 'x-restli-protocol-version: 2.0.0'
The correct API call would be Request:
curl -X GET \
'https://api.linkedin.com/v2/adTargetingEntities?q=urns&urns=List(urn%3Ali%3Aindustry%3A1,urn%3Ali%3Aseniority%3A9)&locale=(language:it,country:IT)'
\
-H 'x-restli-protocol-version: 2.0.0' \
-H 'Authorization: Bearer <Token>'
Response:
{
"elements": [
{
"facetUrn": "urn:li:adTargetingFacet:industries",
"name": "Difesa e spazio",
"urn": "urn:li:industry:1"
},
{
"facetUrn": "urn:li:adTargetingFacet:seniorities",
"name": "Partner",
"urn": "urn:li:seniority:9"
}
],
"paging": {
"count": 2147483647,
"links": [],
"start": 0
}
}
Yes, it does provide a response in locale.
Hope this can help other guys in the future
This curl call works to create a new droplet on Digital Ocean
curl -X POST "https://api.digitalocean.com/v2/droplets" \
-d '{"name":"test3","region":"nyc2","size":"512mb","image":5562742,"ssh_keys":[89103]}' \
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
However, I'm having trouble getting an httr::POST() request to work only when the parameter ssh_keys is given. In the above method the ssh_keys parameter, if given, has to be an array.
I assumed the list of parameters could be passed to the body as, e.g., where the ssh_keys parameter is inside a list
args <- list(name="test3", region="nyc2", size="512mb", image="5562742", ssh_keys=list(891111))
POST(url, config=auth, body=args)
I assume this is what's happening on the inside:
jsonlite::toJSON(args)
[1] "{ \"name\" : [ \"test3\" ], \"region\" : [ \"nyc2\" ], \"size\" : [ \"512mb\" ], \"image\" : [ \"5562742\" ], \"ssh_keys\" : [ [ 89103 ] ] }"
Which I imagine would work, but perhaps that's not what's happening? Fiddling with the encode parameter in POST doesn't seem to help.
The curl call works from terminal, but using httr::POST() I keep getting the error message
You specified invalid ssh key ids for Droplet creation.
In this specific case,
x <- jsonlite::toJSON(args, auto_unbox=TRUE)
cat(x)
seems to return the correct format (assuming the problem is not with the headers) so them
POST(url, config=auth, body=x)
should send the correct request.
Maybe something like:
req <- POST(
url = "https://api.digitalocean.com/v2/droplets",
body = toJSON(args, auto_unbox=TRUE),
add_headers (
"Content-Type" = "application/json",
"Authorization" = paste("Bearker", TOKEN)
)
)