Here is something very "off topic". I am developing a system that will allow schools to download cataloguing data from a site in Australia. The site has introduced an API with examples given as curl commands. I would like to translate the commands into a single line that can be sent via httprequest() in PB. Can't quite work out how to do it.
Examples from the API integration guide:
Heath check:
curl -i -X GET --url https://api-uat.scisdata.com/checkStatus --basic -u testapi2:abc123
Search:
curl -i -X GET --url 'https://apiuat.
scisdata.com/catalogue/api/search?query=titleSearch%3Adogs%20AND%20publicationYear%3A2015&from=0&size
=20&sort=author&order=asc' -H 'Authorization: Basic dGVzdGFwaTI6YWJjMTIz'
Download MARC records:
curl -X POST -H "Content-Type: application/json" -d '{"identities":["1736952","1692646","1835443"],"fileType":"MARC"}'
https://api-uat.scisdata.com/catalogue/download -H 'Authorization: Basic dGVzdGFwaTI6YWJjMTIz'
Download image:
curl -X POST -H "Content-Type: application/json" -d '{"identities":["1736952","1692646"]}' https://apiuat.
scisdata.com/catalogue/image/download -H 'Authorization: Basic dGVzdGFwaTI6YWJjMTIz' -o testdownload.zip
I was not able to get curl to work as it kept rejecting the https type but I could make example 1 work in a browser.
These commands include authentication - username (testapi2) and password (abc123). Apart from example 1, the others are base-64 encoded.
Results are returned in JSON format.
If anyone can help, I would be grateful.
Thanks.
Change a curl command to httprequest
- DeanH
- Enthusiast
- Posts: 223
- Joined: Wed May 07, 2008 4:57 am
- Location: Adelaide, South Australia
- Contact:
Re: Change a curl command to httprequest
I was able to work out how to include the username and password in the URL line. Something like https://username:password@site.com.
I have another curl command and could use some help turning it into a Httprequest in PureBasic.
The curl statement is
curl --request POST --header "Content-Type: application/json" --data '{"identities":["1736952","1692646","1835443"],"fileType":"MARC"}' "https://websiet.com/download"
I have another curl command and could use some help turning it into a Httprequest in PureBasic.
The curl statement is
curl --request POST --header "Content-Type: application/json" --data '{"identities":["1736952","1692646","1835443"],"fileType":"MARC"}' "https://websiet.com/download"
- NicTheQuick
- Addict
- Posts: 1224
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Change a curl command to httprequest
It should work like this:
Code: Select all
NewMap Header.s()
Header("Content-Type") = "application/json"
HTTPRequest(#PB_HTTP_Post, "https://websiet.com/download", ~"{\"identities\":[\"1736952\",\"1692646\",\"1835443\"],\"fileType\":\"MARC\"}", 0, Header())
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
- DeanH
- Enthusiast
- Posts: 223
- Joined: Wed May 07, 2008 4:57 am
- Location: Adelaide, South Australia
- Contact:
Re: Change a curl command to httprequest
Thanks Nic.
I did not know a literal string could be prefixed with ~ then \" could be used to insert double-quotes. Very handy.
I did not know a literal string could be prefixed with ~ then \" could be used to insert double-quotes. Very handy.