Solved

powershell call api

Posted on 2014-10-15
1
160 Views
Last Modified: 2016-02-26
Hello EE,

I wish to connect to an api and send requests and get responses , so far I used the

$URI = "https://api.someplace.ca/v3.0/Booking.svc?wsdl"

Open in new window


$service = New-WebServiceProxy -Uri $URI -Namespace service -UseDefaultCredential

Open in new window


Now when I run a get-member on $service the results are below , I know it is relative to the api , but how would I then send requests and gather responses , what is the process/command, do I use the invoke-webrequest and send soap-env xml envelopes ?

$service |gm


   TypeName: service.BookingService

Name                                    MemberType Definition                                                                                                                                                                                                      
----                                    ---------- ----------                                                                                                                                                                                                      
BookReservationCompleted                Event      service.BookReservationCompletedEventHandler BookReservationCompleted(System.Object, service.BookReservationCompletedEventArgs)                                                                                 
CalculateProcessingFeeCompleted         Event      service.CalculateProcessingFeeCompletedEventHandler CalculateProcessingFeeCompleted(System.Object, service.CalculateProcessingFeeCompletedEventArgs)                                                            
Disposed                                Event      System.EventHandler Disposed(System.Object, System.EventArgs)                                                                                                                                                   
EmailItineraryCompleted                 Event      service.EmailItineraryCompletedEventHandler EmailItineraryCompleted(System.Object, service.EmailItineraryCompletedEventArgs)                                                                                    
GetAgencyCompanyListCompleted           Event      service.GetAgencyCompanyListCompletedEventHandler GetAgencyCompanyListCompleted(System.Object, service.GetAgencyCompanyListCompletedEventArgs)                                                                  
GetAirportCityPairsListCompleted        Event      service.GetAirportCityPairsListCompletedEventHandler GetAirportCityPairsListCompleted(System.Object, service.GetAirportCityPairsListCompletedEventArgs)                                                         
GetAirportCompleted                     Event      service.GetAirportCompletedEventHandler GetAirportCompleted(System.Object, service.GetAirportCompletedEventArgs)                                                                                                
GetAirportListCompleted                 Event      service.GetAirportListCompletedEventHandler GetAirportListCompleted(System.Object, service.GetAirportListCompletedEventArgs)                                                                                    
GetAirportSSRAllocationsCompleted       Event      service.GetAirportSSRAllocationsCompletedEventHandler GetAirportSSRAllocationsCompleted(System.Object, service.GetAirportSSRAllocationsCompletedEventArgs)                                                      
GetCountryListCompleted                 Event      service.GetCountryListCompletedEventHandler GetCountryListCompleted(System.Object, service.GetCountryListCompletedEventArgs)                                                                                    
GetCurrencyListCompleted                Event      service.GetCurrencyListCompletedEventHandler GetCurrencyListCompleted(System.Object, service.GetCurrencyListCompletedEventArgs)                                                                                 
GetFlightSSRAllocationsCompleted        Event      service.GetFlightSSRAllocationsCompletedEventHandler GetFlightSSRAllocationsCompleted(System.Object, service.GetFlightSSRAllocationsCompletedEventArgs)                                                         
GetLevelOfServiceListCompleted          Event      service.GetLevelOfServiceListCompletedEventHandler GetLevelOfServiceListCompleted(System.Object, service.GetLevelOfServiceListCompletedEventArgs)                                                               
GetPaymentMethodListByCurrencyCompleted Event      service.GetPaymentMethodListByCurrencyCompletedEventHandler GetPaymentMethodListByCurrencyCompleted(System.Object, service.GetPaymentMethodListByCurrencyCompletedEventArgs)                                    
GetPaymentMethodListCompleted           Event      service.GetPaymentMethodListCompletedEventHandler GetPaymentMethodListCompleted(System.Object, service.GetPaymentMethodListCompletedEventArgs)                                                                  
GetProvinceListCompleted                Event      service.GetProvinceListCompletedEventHandler GetProvinceListCompleted(System.Object, service.GetProvinceListCompletedEventArgs)                                                                                 
GetTaxConfigurationCompleted            Event      service.GetTaxConfigurationCompletedEventHandler GetTaxConfigurationCompleted(System.Object, service.GetTaxConfigurationCompletedEventArgs)                                                                     
GetTravelOptionsCompleted               Event      service.GetTravelOptionsCompletedEventHandler GetTravelOptionsCompleted(System.Object, service.GetTravelOptionsCompletedEventArgs)                                                                              
GetVoucherCompleted                     Event      service.GetVoucherCompletedEventHandler GetVoucherCompleted(System.Object, service.GetVoucherCompletedEventArgs)                                                                                                
LoginUserProfileCompleted               Event      service.LoginUserProfileCompletedEventHandler LoginUserProfileCompleted(System.Object, service.LoginUserProfileCompletedEventArgs)                                                                              
ReservationPaymentCompleted             Event      service.ReservationPaymentCompletedEventHandler ReservationPaymentCompleted(System.Object, service.ReservationPaymentCompletedEventArgs)                                                                        
Abort                                   Method     System.Void Abort()                                                                                                                                                                                             
BeginBookReservation                    Method     System.IAsyncResult BeginBookReservation(service.BookingRequest bookingRequest, System.AsyncCallback callback, System.Object asyncState)                                                                        
BeginCalculateProcessingFee             Method     System.IAsyncResult BeginCalculateProcessingFee(service.CalculateProcessingFeeRequest request, System.AsyncCallback callback, System.Object asyncState)                                                         
BeginEmailItinerary                     Method     System.IAsyncResult BeginEmailItinerary(service.SendItineraryRequest request, System.AsyncCallback callback, System.Object asyncState)                                                                          
BeginGetAgencyCompanyList               Method     System.IAsyncResult BeginGetAgencyCompanyList(System.AsyncCallback callback, System.Object asyncState)                                                                                                          
BeginGetAirport                         Method     System.IAsyncResult BeginGetAirport(service.AirportRequest airportReq, System.AsyncCallback callback, System.Object asyncState)                                                                                 
BeginGetAirportCityPairsList            Method     System.IAsyncResult BeginGetAirportCityPairsList(System.AsyncCallback callback, System.Object asyncState)                                                                                                       
BeginGetAirportList                     Method     System.IAsyncResult BeginGetAirportList(System.AsyncCallback callback, System.Object asyncState)                                                                                                                
BeginGetAirportSSRAllocations           Method     System.IAsyncResult BeginGetAirportSSRAllocations(service.AirportAllocRequest allocRequest, System.AsyncCallback callback, System.Object asyncState)                                                            
BeginGetCountryList                     Method     System.IAsyncResult BeginGetCountryList(service.CountryListRequest request, System.AsyncCallback callback, System.Object asyncState)                                                                            
BeginGetCurrencyList                    Method     System.IAsyncResult BeginGetCurrencyList(System.AsyncCallback callback, System.Object asyncState)                                                                                                               
BeginGetFlightSSRAllocations            Method     System.IAsyncResult BeginGetFlightSSRAllocations(service.FlightAllocRequest allocRequest, System.AsyncCallback callback, System.Object asyncState)                                                              
BeginGetLevelOfServiceList              Method     System.IAsyncResult BeginGetLevelOfServiceList(System.AsyncCallback callback, System.Object asyncState)                                                                                                         
BeginGetPaymentMethodList               Method     System.IAsyncResult BeginGetPaymentMethodList(System.AsyncCallback callback, System.Object asyncState)                                                                                                          
BeginGetPaymentMethodListByCurrency     Method     System.IAsyncResult BeginGetPaymentMethodListByCurrency(service.PaymentMethodListRequest request, System.AsyncCallback callback, System.Object asyncState)                                                      
BeginGetProvinceList                    Method     System.IAsyncResult BeginGetProvinceList(service.ProvinceListRequest request, System.AsyncCallback callback, System.Object asyncState)                                                                          
BeginGetTaxConfiguration                Method     System.IAsyncResult BeginGetTaxConfiguration(service.TaxConfigRequest request, System.AsyncCallback callback, System.Object asyncState)                                                                         
BeginGetTravelOptions                   Method     System.IAsyncResult BeginGetTravelOptions(service.TravelOptionsRequest optionsRequest, System.AsyncCallback callback, System.Object asyncState)                                                                 
BeginGetVoucher                         Method     System.IAsyncResult BeginGetVoucher(service.VoucherRequest request, System.AsyncCallback callback, System.Object asyncState)                                                                                    
BeginLoginUserProfile                   Method     System.IAsyncResult BeginLoginUserProfile(service.UserProfileLoginRequest request, System.AsyncCallback callback, System.Object asyncState)                                                                     
BeginReservationPayment                 Method     System.IAsyncResult BeginReservationPayment(service.ReservationPaymentRequest reservationPaymentRequest, System.AsyncCallback callback, System.Object asyncState)                                               
BookReservation                         Method     service.BookingResponse BookReservation(service.BookingRequest bookingRequest)                                                                                                                                  
BookReservationAsync                    Method     System.Void BookReservationAsync(service.BookingRequest bookingRequest), System.Void BookReservationAsync(service.BookingRequest bookingRequest, System.Object userState)                                       
CalculateProcessingFee                  Method     service.CalculateProcessingFeeResponse CalculateProcessingFee(service.CalculateProcessingFeeRequest request)                                                                                                    
CalculateProcessingFeeAsync             Method     System.Void CalculateProcessingFeeAsync(service.CalculateProcessingFeeRequest request), System.Void CalculateProcessingFeeAsync(service.CalculateProcessingFeeRequest request, System.Object userState)         
CancelAsync                             Method     System.Void CancelAsync(System.Object userState)                                                                                                                                                                
CreateObjRef                            Method     System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)                                                                                                                                                 
Discover                                Method     System.Void Discover()                                                                                                                                                                                          
Dispose                                 Method     System.Void Dispose()                                                                                                                                                                                           
EmailItinerary                          Method     service.SendItineraryResponse EmailItinerary(service.SendItineraryRequest request)                                                                                                                              
EmailItineraryAsync                     Method     System.Void EmailItineraryAsync(service.SendItineraryRequest request), System.Void EmailItineraryAsync(service.SendItineraryRequest request, System.Object userState)                                           
EndBookReservation                      Method     service.BookingResponse EndBookReservation(System.IAsyncResult asyncResult)                                                                                                                                     
EndCalculateProcessingFee               Method     service.CalculateProcessingFeeResponse EndCalculateProcessingFee(System.IAsyncResult asyncResult)                                                                                                               
EndEmailItinerary                       Method     service.SendItineraryResponse EndEmailItinerary(System.IAsyncResult asyncResult)                                                                                                                                
EndGetAgencyCompanyList                 Method     service.PaxCompanyListResponse EndGetAgencyCompanyList(System.IAsyncResult asyncResult)                                                                                                                         
EndGetAirport                           Method     service.AirportResponse EndGetAirport(System.IAsyncResult asyncResult)                                                                                                                                          
EndGetAirportCityPairsList              Method     service.AirportPairsResponse EndGetAirportCityPairsList(System.IAsyncResult asyncResult)                                                                                                                        
EndGetAirportList                       Method     service.AirportListResponse EndGetAirportList(System.IAsyncResult asyncResult)                                                                                                                                  
EndGetAirportSSRAllocations             Method     service.AirportAllocResponse EndGetAirportSSRAllocations(System.IAsyncResult asyncResult)                                                                                                                       
EndGetCountryList                       Method     service.CountryListResponse EndGetCountryList(System.IAsyncResult asyncResult)                                                                                                                                  
EndGetCurrencyList                      Method     service.CurrencyListResponse EndGetCurrencyList(System.IAsyncResult asyncResult)                                                                                                                                
EndGetFlightSSRAllocations              Method     service.FlightAllocResponse EndGetFlightSSRAllocations(System.IAsyncResult asyncResult)                                                                                                                         
EndGetLevelOfServiceList                Method     service.LevelOfServiceListResponse EndGetLevelOfServiceList(System.IAsyncResult asyncResult)                                                                                                                    
EndGetPaymentMethodList                 Method     service.PaymentMethodListResponse EndGetPaymentMethodList(System.IAsyncResult asyncResult)                                                                                                                      
EndGetPaymentMethodListByCurrency       Method     service.PaymentMethodListResponse EndGetPaymentMethodListByCurrency(System.IAsyncResult asyncResult)                                                                                                            
EndGetProvinceList                      Method     service.ProvinceListResponse EndGetProvinceList(System.IAsyncResult asyncResult)                                                                                                                                
EndGetTaxConfiguration                  Method     service.TaxConfigResponse EndGetTaxConfiguration(System.IAsyncResult asyncResult)                                                                                                                               
EndGetTravelOptions                     Method     service.TravelOptionsResponse EndGetTravelOptions(System.IAsyncResult asyncResult)                                                                                                                              
EndGetVoucher                           Method     service.VoucherResponse EndGetVoucher(System.IAsyncResult asyncResult)                                                                                                                                          
EndLoginUserProfile                     Method     service.UserProfileLoginResponse EndLoginUserProfile(System.IAsyncResult asyncResult)                                                                                                                           
EndReservationPayment                   Method     service.ReservationPaymentResponse EndReservationPayment(System.IAsyncResult asyncResult)                                                                                                                       
Equals                                  Method     bool Equals(System.Object obj)                                                                                                                                                                                  
GetAgencyCompanyList                    Method     service.PaxCompanyListResponse GetAgencyCompanyList()                                                                                                                                                           
GetAgencyCompanyListAsync               Method     System.Void GetAgencyCompanyListAsync(), System.Void GetAgencyCompanyListAsync(System.Object userState)                                                                                                         
GetAirport                              Method     service.AirportResponse GetAirport(service.AirportRequest airportReq)                                                                                                                                           
GetAirportAsync                         Method     System.Void GetAirportAsync(service.AirportRequest airportReq), System.Void GetAirportAsync(service.AirportRequest airportReq, System.Object userState)                                                         
GetAirportCityPairsList                 Method     service.AirportPairsResponse GetAirportCityPairsList()                                                                                                                                                          
GetAirportCityPairsListAsync            Method     System.Void GetAirportCityPairsListAsync(), System.Void GetAirportCityPairsListAsync(System.Object userState)                                                                                                   
GetAirportList                          Method     service.AirportListResponse GetAirportList()                                                                                                                                                                    
GetAirportListAsync                     Method     System.Void GetAirportListAsync(), System.Void GetAirportListAsync(System.Object userState)                                                                                                                     
GetAirportSSRAllocations                Method     service.AirportAllocResponse GetAirportSSRAllocations(service.AirportAllocRequest allocRequest)                                                                                                                 
GetAirportSSRAllocationsAsync           Method     System.Void GetAirportSSRAllocationsAsync(service.AirportAllocRequest allocRequest), System.Void GetAirportSSRAllocationsAsync(service.AirportAllocRequest allocRequest, System.Object userState)               
GetCountryList                          Method     service.CountryListResponse GetCountryList(service.CountryListRequest request)                                                                                                                                  
GetCountryListAsync                     Method     System.Void GetCountryListAsync(service.CountryListRequest request), System.Void GetCountryListAsync(service.CountryListRequest request, System.Object userState)                                               
GetCurrencyList                         Method     service.CurrencyListResponse GetCurrencyList()                                                                                                                                                                  
GetCurrencyListAsync                    Method     System.Void GetCurrencyListAsync(), System.Void GetCurrencyListAsync(System.Object userState)                                                                                                                   
GetFlightSSRAllocations                 Method     service.FlightAllocResponse GetFlightSSRAllocations(service.FlightAllocRequest allocRequest)                                                                                                                    
GetFlightSSRAllocationsAsync            Method     System.Void GetFlightSSRAllocationsAsync(service.FlightAllocRequest allocRequest), System.Void GetFlightSSRAllocationsAsync(service.FlightAllocRequest allocRequest, System.Object userState)                   
GetHashCode                             Method     int GetHashCode()                                                                                                                                                                                               
GetLevelOfServiceList                   Method     service.LevelOfServiceListResponse GetLevelOfServiceList()                                                                                                                                                      
GetLevelOfServiceListAsync              Method     System.Void GetLevelOfServiceListAsync(), System.Void GetLevelOfServiceListAsync(System.Object userState)                                                                                                       
GetLifetimeService                      Method     System.Object GetLifetimeService()                                                                                                                                                                              
GetPaymentMethodList                    Method     service.PaymentMethodListResponse GetPaymentMethodList()                                                                                                                                                        
GetPaymentMethodListAsync               Method     System.Void GetPaymentMethodListAsync(), System.Void GetPaymentMethodListAsync(System.Object userState)                                                                                                         
GetPaymentMethodListByCurrency          Method     service.PaymentMethodListResponse GetPaymentMethodListByCurrency(service.PaymentMethodListRequest request)                                                                                                      
GetPaymentMethodListByCurrencyAsync     Method     System.Void GetPaymentMethodListByCurrencyAsync(service.PaymentMethodListRequest request), System.Void GetPaymentMethodListByCurrencyAsync(service.PaymentMethodListRequest request, System.Object userState)   
GetProvinceList                         Method     service.ProvinceListResponse GetProvinceList(service.ProvinceListRequest request)                                                                                                                               
GetProvinceListAsync                    Method     System.Void GetProvinceListAsync(service.ProvinceListRequest request), System.Void GetProvinceListAsync(service.ProvinceListRequest request, System.Object userState)                                           
GetTaxConfiguration                     Method     service.TaxConfigResponse GetTaxConfiguration(service.TaxConfigRequest request)                                                                                                                                 
GetTaxConfigurationAsync                Method     System.Void GetTaxConfigurationAsync(service.TaxConfigRequest request), System.Void GetTaxConfigurationAsync(service.TaxConfigRequest request, System.Object userState)                                         
GetTravelOptions                        Method     service.TravelOptionsResponse GetTravelOptions(service.TravelOptionsRequest optionsRequest)                                                                                                                     
GetTravelOptionsAsync                   Method     System.Void GetTravelOptionsAsync(service.TravelOptionsRequest optionsRequest), System.Void GetTravelOptionsAsync(service.TravelOptionsRequest optionsRequest, System.Object userState)                         
GetType                                 Method     type GetType()                                                                                                                                                                                                  
GetVoucher                              Method     service.VoucherResponse GetVoucher(service.VoucherRequest request)                                                                                                                                              
GetVoucherAsync                         Method     System.Void GetVoucherAsync(service.VoucherRequest request), System.Void GetVoucherAsync(service.VoucherRequest request, System.Object userState)                                                               
InitializeLifetimeService               Method     System.Object InitializeLifetimeService()                                                                                                                                                                       
LoginUserProfile                        Method     service.UserProfileLoginResponse LoginUserProfile(service.UserProfileLoginRequest request)                                                                                                                      
LoginUserProfileAsync                   Method     System.Void LoginUserProfileAsync(service.UserProfileLoginRequest request), System.Void LoginUserProfileAsync(service.UserProfileLoginRequest request, System.Object userState)                                 
ReservationPayment                      Method     service.ReservationPaymentResponse ReservationPayment(service.ReservationPaymentRequest reservationPaymentRequest)                                                                                              
ReservationPaymentAsync                 Method     System.Void ReservationPaymentAsync(service.ReservationPaymentRequest reservationPaymentRequest), System.Void ReservationPaymentAsync(service.ReservationPaymentRequest reservationPaymentRequest, System.Obj...
ToString                                Method     string ToString()                                                                                                                                                                                               
AllowAutoRedirect                       Property   System.Boolean AllowAutoRedirect {get;set;}                                                                                                                                                                     
ClientCertificates                      Property   System.Security.Cryptography.X509Certificates.X509CertificateCollection ClientCertificates {get;}                                                                                                               
ConnectionGroupName                     Property   System.String ConnectionGroupName {get;set;}                                                                                                                                                                    
Container                               Property   System.ComponentModel.IContainer Container {get;}                                                                                                                                                               
CookieContainer                         Property   System.Net.CookieContainer CookieContainer {get;set;}                                                                                                                                                           
Credentials                             Property   System.Net.ICredentials Credentials {get;set;}                                                                                                                                                                  
EnableDecompression                     Property   System.Boolean EnableDecompression {get;set;}                                                                                                                                                                   
PreAuthenticate                         Property   System.Boolean PreAuthenticate {get;set;}                                                                                                                                                                       
Proxy                                   Property   System.Net.IWebProxy Proxy {get;set;}                                                                                                                                                                           
RequestEncoding                         Property   System.Text.Encoding RequestEncoding {get;set;}                                                                                                                                                                 
Site                                    Property   System.ComponentModel.ISite Site {get;set;}                                                                                                                                                                     
SoapVersion                             Property   System.Web.Services.Protocols.SoapProtocolVersion SoapVersion {get;set;}                                                                                                                                        
Timeout                                 Property   System.Int32 Timeout {get;set;}                                                                                                                                                                                 
UnsafeAuthenticatedConnectionSharing    Property   System.Boolean UnsafeAuthenticatedConnectionSharing {get;set;}                                                                                                                                                  
Url                                     Property   System.String Url {get;set;}                                                                                                                                                                                    
UseDefaultCredentials                   Property   System.Boolean UseDefaultCredentials {get;set;}                                                                                                                                                                 
UserAgent                               Property   System.String UserAgent {get;set;}  

Open in new window

0
Comment
Question by:davesnb
1 Comment
 
LVL 10

Accepted Solution

by:
JoeKlimis earned 500 total points
ID: 40408303
Hi

The scripting guy has a good example of this which can be found HERE

so in your case it will be something like

$results =  $servce.ChosenMethod(Param1)

It looks like  GetCountryList  take no parameters so try

$results =  $servce.GetCountryList ()        


I hope this helps
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Set OWA language and time zone in Exchange for individuals, all users or per database.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now