It is currently Fri Jan 18, 2019 10:40 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Change a curl command to httprequest
PostPosted: Wed Jan 09, 2019 3:01 am 
Offline
User
User

Joined: Wed May 07, 2008 4:57 am
Posts: 51
Location: Adelaide, South Australia
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Change a curl command to httprequest
PostPosted: Thu Jan 10, 2019 6:00 am 
Offline
User
User

Joined: Wed May 07, 2008 4:57 am
Posts: 51
Location: Adelaide, South Australia
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"


Top
 Profile  
Reply with quote  
 Post subject: Re: Change a curl command to httprequest
PostPosted: Thu Jan 10, 2019 2:45 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 323
Location: Germany, Saarbrücken
It should work like this:
Code:
NewMap Header.s()

Header("Content-Type") = "application/json"

HTTPRequest(#PB_HTTP_Post, "https://websiet.com/download", ~"{\"identities\":[\"1736952\",\"1692646\",\"1835443\"],\"fileType\":\"MARC\"}", 0, Header())

_________________
Electronics, Crazy & Interesting Stuff, all that with text, image and sound? Click here!

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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Change a curl command to httprequest
PostPosted: Fri Jan 11, 2019 12:34 am 
Offline
User
User

Joined: Wed May 07, 2008 4:57 am
Posts: 51
Location: Adelaide, South Australia
Thanks Nic.

I did not know a literal string could be prefixed with ~ then \" could be used to insert double-quotes. Very handy.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: glomph and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye