#2 Retrieve a List of CategoriesIn this example, you

if no categories, then exitIf IsNothing(Response.CategoryArray) ThenTextBox1.Text = No categories returned for this site id. Exit SubEnd If display the categoriesFor Each items In Response.CategoryArrayTextBox1.Text = TextBox1.Text & vbCrLf & Category ID: & _ items.CategoryID & vbCrLfTextBox1.Text = TextBox1.Text & Category Name: & _ items.CategoryName & vbCrLfNextElse display any errors that occurredTextBox1.Text = For intCount = 0 To Response.Errors.Length – 1TextBox1.Text = TextBox1.Text & Error: & _ Response.Errors(intCount).ErrorCodeTextBox1.Text = TextBox1.Text & vbCrLf & Message: & _ Response.Errors(intCount).LongMessageNext intCountEnd IfExit Subhandleerror: MsgBox( An error occurred: & Err.Number & – & Err.Description) Exit SubEnd Sub2.Run the project and specify 2when prompted to run this example. XML ExampleThe following XMLcode retrieves categories for the specified site using the GetCategoriesmethod.Torun this example from the existing project, see the earlier instructions. Also, replace theCategorySiteIdvalue with the identifier corresponding to the eBay site you wish to use in yoursearch. < ?xml version= 1.0 encoding= utf-8 ?> Your Token Here 1 0 GetCategories 4 #3 Retrieve List of Pending Auctions for SellerThis example calls the GetSellerListmethod to retrieve all pending auctions for a specified seller. 138Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services

#2 Retrieve a List of CategoriesIn this example, you

#2 Retrieve a List of CategoriesIn this example, you use the GetCategoriesmethod to retrieve all of the categories for a particulareBay site. SOAP Example1.Add the following Example2procedure to the code section of the existing project. Replace where specified with your own eBay credentials. Sub Example2() On Error GoTo handleerrorDim strToken As StringDim strDevId As StringDim strAppId As StringDim strCertId As String specify credentials required to access APIstrToken = Your Token Here strDevId = Your Dev Id Here strAppId = Your App Id Here strCertId = Your Cert Id Here Dim SOAPService As New ebay.eBayAPIInterfaceServiceSOAPService.Url = _ https://api.sandbox.ebay.com/wsapi?callname=GetCategories&siteid=0&appid= & strAppId & version=383 SOAPService.RequesterCredentials = New ebay.CustomSecurityHeaderTypeSOAPService.RequesterCredentials.eBayAuthToken = strTokenSOAPService.RequesterCredentials.Credentials = New ebay.UserIdPasswordTypeSOAPService.RequesterCredentials.Credentials.AppId = strAppIdSOAPService.RequesterCredentials.Credentials.DevId = strDevIdSOAPService.RequesterCredentials.Credentials.AuthCert = strCertIdDim Request As New ebay.GetCategoriesRequestTypeDim Response As New ebay.GetCategoriesResponseType specify the API versionRequest.Version = 383 get the categories for the U.S. Request.CategorySiteID = 0 call the GetCategories methodResponse = SOAPService.GetCategories(Request) Dim intCount As Integer display the list of eBay categoriesIf IsNothing(Response.Errors) ThenDim items As ebay.CategoryType137Using

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services

SOAPService.RequesterCredentials.Credentials.DevId = strDevIdSOAPService.RequesterCredentials.Credentials.AuthCert = strCertIdDim Request As New

eBay after the listing was successfulTextBox1.Text = Item Listed & vbCrLf & Item ID: & Response.ItemIDElse display the errors that were returnedTextBox1.Text = For intCount = 0 To Response.Errors.Length – 1TextBox1.Text = TextBox1.Text & Error: & _ Response.Errors(intCount).ErrorCodeTextBox1.Text = TextBox1.Text & vbCrLf & Message: & _ Response.Errors(intCount).LongMessageNext intCountEnd IfExit Subhandleerror: MsgBox( An error occurred: & Err.Number & – & Err.Description) Exit SubEnd Sub4.Run the program, and specify 1when prompted to run this example. XML ExampleThe following code is an example of XMLthat lists an item using the AddItemmethod. Follow theinstructions described in the beginning of this section if you want to run this example from the existingproject. Also, replace the values with the information for the item you wish to list. < ?xml version= 1.0 encoding= utf-8 ?> Your Token Here 0 1 0 0 0 US 1 < ![CDATA[ A forgotten classic! ]]> 7 Indianapolis, IN 6 1.00 1 1 60 0 2 1 AddItem 136Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services

SOAPService.RequesterCredentials.Credentials.DevId = strDevIdSOAPService.RequesterCredentials.Credentials.AuthCert = strCertIdDim Request As New

SOAPService.RequesterCredentials.Credentials.DevId = strDevIdSOAPService.RequesterCredentials.Credentials.AuthCert = strCertIdDim Request As New ebay.AddItemRequestTypeDim Response As New ebay.AddItemResponseTypeDim Item As New ebay.ItemType specify the API versionRequest.Version = 383 Item.Title = Johnny Horton Greatest Hits CD Item.Description = A forgotten classic! specify the listing detailsItem.QuantitySpecified = TrueItem.Quantity = 1Item.CurrencySpecified = TrueItem.Currency = New ebay.CurrencyCodeTypeItem.Currency = ebay.CurrencyCodeType.USDItem.CountrySpecified = TrueItem.Country = New ebay.CountryCodeTypeItem.Country = ebay.CountryCodeType.USItem.ListingDurationSpecified = TrueItem.ListingDuration = New ebay.ListingDurationCodeTypeItem.ListingDuration = ebay.ListingDurationCodeType.Days_7Item.Location = Indianapolis, IN Item.ListingDetails = New ebay.ListingDetailsTypeItem.ListingDetails.ConvertedBuyItNowPrice = New ebay.AmountTypeItem.ListingDetails.ConvertedBuyItNowPrice.currencyID = New _ ebay.CurrencyCodeTypeItem.ListingDetails.ConvertedBuyItNowPrice.currencyID = _ ebay.CurrencyCodeType.USDItem.ListingDetails.ConvertedBuyItNowPrice.Value = 5.0Item.StartPrice = New ebay.AmountTypeItem.StartPrice.currencyID = New ebay.CurrencyCodeTypeItem.StartPrice.currencyID = ebay.CurrencyCodeType.USDItem.StartPrice.Value = 1.0Item.RegionID = 60Item.ShippingTerms = ebay.ShippingTermsCodeType.BuyerPaysItem.PrimaryCategory = New ebay.CategoryTypeItem.PrimaryCategory.CategoryID = 1573Item.ListingTypeSpecified = TrueItem.ListingType = ebay.ListingTypeCodeType.FixedPriceItemItem.ShippingOption = ebay.ShippingOptionCodeType.WorldWide assign the item object to the request objectRequest.Item = Item call the AddItem method to list the itemResponse = SOAPService.AddItem(Request) Dim intCount As IntegerIf IsNothing(Response.Errors) Then display the new item ID returned from135Using

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services

The account credentials are duplicated in each of

2.Add the following procedure to the Clickevent of the new button. This procedure will promptyou to specify which example you want to run. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles Button3.ClickDim intExample As Integer run the example specified by the userintExample = InputBox( Please enter example number (1-5): ) Select Case intExampleCase 1Call Example1() Case 2Call Example2() Case 3Call Example3() Case 4Call Example4() Case 5Call Example5() Case ElseMsgBox( Please enter a number from 1-5 ) End SelectEnd Sub3.Add the Example1procedure that calls the AddItemmethod to list a new item on eBay. Replacethe variables in the following code with your account information. Sub Example1() On Error GoTo handleerrorDim strToken As StringDim strDevId As StringDim strAppId As StringDim strCertId As String specify credentials required to access APIstrToken = Your Token Here strDevId = Your Dev Id Here strAppId = Your App Id Here strCertId = Your Cert Id Here Dim SOAPService As New ebay.eBayAPIInterfaceServiceSOAPService.Url = _ https://api.sandbox.ebay.com/wsapi?callname=AddItem&siteid=0&appid= & _ strAppId & version=383 SOAPService.RequesterCredentials = New ebay.CustomSecurityHeaderTypeSOAPService.RequesterCredentials.eBayAuthToken = strTokenSOAPService.RequesterCredentials.Credentials = New ebay.UserIdPasswordTypeSOAPService.RequesterCredentials.Credentials.AppId = strAppId134Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services

The account credentials are duplicated in each of

The account credentials are duplicated in each of these SOAP examples so each can stand alone. Youshould specify the credentials in a single place to avoid duplication of code in your own eBay solutions. The XMLexamples are also provided for your convenience. However, if you want to run the XMLexam- ples from Visual Studio .NET, modify the strXMLvalue in Button1_Clickevent of Form1to includethe XMLcode shown in the respective example. You also will need to modify the X-EBAY-API-CALL- NAME parameter to specify the verb (procedure to call) as shown in the respective example, instead GetSearchResults procedure. #1 List an Item for SaleThis example illustrates how to use the AddItemmethod to list an item for sale. You must first create Seller s Account on the Sandbox text environment for this example to work. Visit sandbox.ebay.select the Sellers option, and follow the links to create a new account. SOAP ExampleYou must set up a few details in your existing Visual Studio .NET project so these five examples run ily. You then add the code specific to this first example. 1.Open the project you created earlier in this chapter. Add another command button to the formand change the Text property to Examples 1 to 5, as shown in Figure 5-12. Figure 5-12133Using

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services

5.Click the Add Reference button to add the

NextEnd Sub7.Input your Token, Dev ID, App ID, and Cert ID on the lines of code where indicated. As men- tioned previously, these values are provided in the information screens provided when you setup your account. 8.Select File.Save All to save all changes to the project. 9.Select Debug.Start (or press F5) to run the project. Click the button that says SOAPExampleto run the SOAPExample. 10.You should see a window similar to that shown in Figure 5-11 that displays the search results. Notice that you were able to refer to the data elements of the API call within your code withouthaving to parse any XML. Figure 5-11As new versions of the eBay API are released, some of the code in this chapter may no longer functioninexactly the same way as it did in prior versions. This is certainly true of the other APIs as well, buteBay seems to release new versions more frequently than some of the others. Five Creative Ways to Use the eBay APINow look at five ways to use the eBay API. You see both SOAPand XMLcode examples. The completecode listing is provided for the SOAPexample, as that is probably what you will use from within VisualStudio .NET. 132Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services

5.Click the Add Reference button to add the

5.Click the Add Reference button to add the reference to your project. Visual Studio .NET uses to identify the methods that are available for execution from your project. 6.Add the following procedure to Form1to the click event of the second button: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles Button2.Click SOAP exampleDim strToken As StringDim strDevId As StringDim strAppId As StringDim strCertId As String specify credentials required to access APIstrToken = Your Token Here strDevId = Your Dev Id Here strAppId = Your App Id Here strCertId = Your Cert Id Here Dim SOAPService As New ebay.eBayAPIInterfaceServiceSOAPService.Url = _ https://api.sandbox.ebay.com/wsapi?callname=GetSearchResults&siteid=0&appid= strAppId & version=383 SOAPService.RequesterCredentials = New ebay.CustomSecurityHeaderTypeSOAPService.RequesterCredentials.eBayAuthToken = strTokenSOAPService.RequesterCredentials.Credentials = New ebay.UserIdPasswordTypeSOAPService.RequesterCredentials.Credentials.AppId = strAppIdSOAPService.RequesterCredentials.Credentials.DevId = strDevIdSOAPService.RequesterCredentials.Credentials.AuthCert = strCertIdDim Request As New ebay.GetSearchResultsRequestTypeDim Response As New ebay.GetSearchResultsResponseType specify the search criteriaRequest.Query = computer Request.Version = 383 call the GetSearchResults method to run the searchResponse = SOAPService.GetSearchResults(Request) Dim items As ebay.SearchResultItemTypeTextBox1.Multiline = True loop through the results and display the resultsFor Each items In Response.SearchResultItemArrayTextBox1.Text = TextBox1.Text & Title: & items.Item.Title & vbCrLfTextBox1.Text = TextBox1.Text & Description: & _ items.Item.Description & vbCrLfTextBox1.Text = TextBox1.Text & Item Id: & items.Item.ItemID & _ vbCrLf & vbCrLf131Using

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services

strAppId + ; + strCertId) web.Headers.Add( X-EBAY-API-DEV-NAME , strDevId) web.Headers.Add( X-EBAY-API-APP-NAME ,

Figure 5-10Executing a Query Using SOAPAs you learned in Chapter 1, when you call a Web API over SOAP, you specify the location of the WSDLfile so your application knows how the Web API functions. The WSDLfile for the eBay API is currentlylocated at: http://developer.ebay.com/webservices/latest/eBaySvc.wsdl The WSDLfile is then interpreted by your programming language, such as Visual Studio .NET, to allowyou to refer to the API in a more object-oriented fashion in your code. In other words, by using theSOAPprotocol to execute eBay calls, you can work with the results without having to parse XML. Let slook at an example of how this works. Walkthrough Example Calling the eBay API Using SOAP from Visual Studio .NETYou can extend the prior example to add the functionality to call the eBay API using SOAP. Because youare using SOAPinstead of HTTP-POST, the steps to call that same Web service are quite different. 1.Reopen the eBaySample application you created in the prior example if it is not already open. 2.Add a reference to the eBay API by selecting Project.Add Web Reference. For the URLfield, specify the location of the WSDLfile, for example with this URL: http://developer.ebay. com/webservices/latest/eBaySvc.wsdl. 3.Click the GO button so that Visual Studio locates the eBay Web API. 4.Change the Web Reference Name to eBayso that you can use a shorter name in your project. 130Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services

strAppId + ; + strCertId) web.Headers.Add( X-EBAY-API-DEV-NAME , strDevId) web.Headers.Add( X-EBAY-API-APP-NAME ,

strAppId + ; + strCertId) web.Headers.Add( X-EBAY-API-DEV-NAME , strDevId) web.Headers.Add( X-EBAY-API-APP-NAME , strAppId) web.Headers.Add( X-EBAY-API-CERT-NAME , strCertId) Dim strXML As String list of items for sale that match search criteriastrXML = < ?xml version= 1.0 encoding= utf-8 ?> & _ & _ Your Token Here & _ 1 & _ GetSearchResults & _ computer & _ 1000.00 & _ 5 & _ 0 & _ add the xml string to the byte arrayDim d As Byte() = System.Text.Encoding.ASCII.GetBytes(strXML) call the ebay api and pass the byte array containing the XML stringDim res As Byte() = _ web.UploadData( https://api.sandbox.ebay.com/ws/api.dll , POST , d) TextBox1.Multiline = True display the results of the call in a text box on the formTextBox1.Text = System.Text.Encoding.ASCII.GetString(res) End Sub5.Input your Dev ID, App ID, Cert ID, and Token on the lines of code where indicated. As I tioned previously, these values are provided on the information screens you received when up your account. 6.Select File.Save All to save all changes to the project. 7.Select Debug.Start (or press F5) to run the project. Click the button that says HTTP-POSTExample to run the HTTP-POST Example. 8.You should see a window similar to Figure 5-10 that displays the XMLresults returned from API. They begin with the first item that matched the search criteria. You must use an XMLparser to parse the values you use in your application in order to work with meaningful ways. eBay has recently announced a SOAPenhancement for many API operations you the option of calling the API without having to parse XMLin your underlying programs. how this works.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services