ross13
asked on
Help with Web API
Looking at integrating a vb.net application to pull orders from a web API. In the past I have added a reference and used the WSDL. The software I am trying to integrate is:
http://docs.handshake.com/?json-doc#quickstart
It would be better if I could use a WSDL type integration but from the documentation it looks like you have to do a HTTP request.
Really looking for the best way to move this forward. don't know if I should use the HttpWebRequest.
The documentation says :
# Use the command below to dump the JSON data for your orders. Replace the `2c493d74` with your own API key (which will be much longer)
curl -u 2c493d74:X "https://app.handshake.com/api/latest/orders"
I am a bit unsure if I keep my httpwebrequest as:
Dim myRequest As HttpWebRequest = CType(WebRequest.Create("https://app.handshake.com/api/latest/orders" ), HttpWebRequest)
If I try and anything else it fails. I can call myRequest.Credentials but is this what I should be trying to do?
Best Regarsd,
Ross
Example.JPG
http://docs.handshake.com/?json-doc#quickstart
It would be better if I could use a WSDL type integration but from the documentation it looks like you have to do a HTTP request.
Really looking for the best way to move this forward. don't know if I should use the HttpWebRequest.
The documentation says :
# Use the command below to dump the JSON data for your orders. Replace the `2c493d74` with your own API key (which will be much longer)
curl -u 2c493d74:X "https://app.handshake.com/api/latest/orders"
I am a bit unsure if I keep my httpwebrequest as:
Dim myRequest As HttpWebRequest = CType(WebRequest.Create("https://app.handshake.com/api/latest/orders"
If I try and anything else it fails. I can call myRequest.Credentials but is this what I should be trying to do?
Best Regarsd,
Ross
Example.JPG
ASKER
Thanks for your reply. Trying to do some research to get this working from what you sent. I am trying to find out what the second param should be on the postasync call. I have probably spent more time than I should on this. As soon as I get a response back I will look at the jason part.
Best Regards,
Ross
Best Regards,
Ross
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
These days, the preferred tool for interacting with RESTful web services is the the HttpClient:
Open in new window
The site you linked specifies that it uses basic authentication (which should be fine since it looks like they require SSL connections--I wouldn't trust this API security-wise if they allow you to use the site without SSL, because your API key will be sent in clear-text across the Interent). Basic auth requires a specific header in your request. That is established in line 11. The stuff that line 11 needs is set up at the beginning of the function. Once you get the auth configured, it should be a matter of simply making the request, as I'm doing in line 13. Now, what you get back--using the particular GetStringAsync that I used--will be a string. This represents the JSON that the service returns. If you want to programmatically work with that data, then you need to deserialize the data into classes. You can use a site like https://jsonutils.com/ to paste in a chunk of data and have it spit out some VB.NET classes to represent the structure of that data. (You can also build the classes by hand, if you want better control over naming and whatnot.)
Open in new window
You can install JSON.NET from NuGet. That will give you the JsonConvert that I uses in line 14. You can see that the end result is an instance of the Example class that https://jsonutils.com/ created for me.
GETs, POSTs, DELETEs, and PUTs should all function mostly the same. You're generally just changing the method you invoke in line 13, and how you append the parameters. With PostAsync and PutAsync, there is an additional parameter to the method. You'll most likely have to serialize that data into either XML or JSON (depending on your preference) and send the parameter as a string.
Keep in mind that HttpClient was designed to be reused. While it has a Dispose method, you generally don't want to use either a Using or to call Dispose until you are done with any and all interactions with the service. HttpClient is designed to be resilient to failures.