Trade Me-8-Retrieve your won items API testing | Postman API automation testing

API Function

Retrieves a list of purchases for the authenticated user.

Multiple-quantity auctions can be purchased multiple times.

API - Retrieve your won items script development steps

API Specification -> Business Presentation -> API Testing Script Debugging -> API Testing Script Enhancement -> API Testing Script Negative Cases Extension -> API Testing Script Publishment

API Specification

  • Key request fields

  • Key response fields - A list of items the authenticated user has purchased.

    TotalCount Integer The total number of results in the collection. Can be larger than the number of returned results.
    Page Integer The index of the current page of results (starts at 1).
    PageSize Integer The number of results in the current page.
    List Collection of or null A list of the results in the current page.
    ListingId Long Integer The ID of the listing.
    PurchaseId Integer A unique ID that identifies the sale.

More refer to: Retrieve your won items

  • Example request

GET https://api.tmsandbox.co.nz/v1/MyTradeMe/Won/All.JSON

  • Example response - 1 item on the won list:

{
    "TotalCount": 1,
    "Page": 1,
    "PageSize": 1,
    "List": [
        {
            "ListingId": 2149290179,
            "Title": "Samsung Galaxy BV Weaving S9 Case",
            "Category": "0344-0899-1135-5537-",
            "StartPrice": 0,
            ...
            "ListingGroupId": 73059,
			...
            "PaymentInfo": "NZ Bank Deposit",
            "Price": 12.99,
            "SelectedShipping": "rural",
            "ShippingPrice": 9.99,
            "ShippingType": 4,
			...
            "PurchaseId": 26176,
			...
        }
    ]
}
  • Example response - 0 item on the won list:

{
    "TotalCount": 0,
    "Page": 1,
    "PageSize": 0,
    "List": []
}

Business Presentation

  • Front-end page - Won list page - have items on

Login > My Trade Me > Won

  • Front-end page - Won list page - have no items on

  • Business scope selection:

Chained combination transactions

Retrieve your won items(I’m here) -> Remove a purchase from your won items list -> General search -> Retrieve the details of a single listing -> Buy an auction using Buy Now

  • Business verification points

Checking there are items on the won list.

API Testing Script Debugging

  • Choose the OAuth 1.0 in the Authorization label of Postman to authorize the request.

The OAuth 1.0 is for the transaction that needs to be authorized before sending. Template likes the below:

How to get Consumer Key, Consumer Secret, OAuth Token, and OAuth Token Secret, please refer to Preparation before API testing demo

Base on the API specification, parameter - All means return all won items in the last 45 days.

So the request should be GET https://api.tmsandbox.co.nz/v1/MyTradeMe/Won/All.JSON

  • API connectivity

The connectivity test passes and gets a response example.

{
    "TotalCount": 1,
    "Page": 1,
    "PageSize": 1,
    "List": [
        {
            "ListingId": 2149290179,
            "Title": "Samsung Galaxy BV Weaving S9 Case",
            "Category": "0344-0899-1135-5537-",
            "StartPrice": 0,
            "StartDate": "/Date(1625630212963)/",
            "EndDate": "/Date(1625648672660)/",
            "ListingLength": null,
            "AsAt": "/Date(1625649420456)/",
            "CategoryPath": "/Mobile-phones/Accessories/Cases-covers/Samsung",
            "PictureHref": "https://images.tmsandbox.co.nz/photoserver/thumb/4676325.jpg",
            "PhotoId": 4676325,
            "Seller": {
                "MemberId": 4000334,
                "Nickname": "paperclip4",
                "DateAddressVerified": "/Date(1338811200000)/",
                "DateJoined": "/Date(1338811200000)/",
                "Email": "owen4@snipesoft.net.nz",
                "UniqueNegative": 0,
                "UniquePositive": 3,
                "FeedbackCount": 3,
                "IsAddressVerified": true
            },
            "IsNew": true,
            "Note": "",
            "NoteDate": "/Date(0)/",
            "CategoryName": "Samsung",
            "ReserveState": 3,
            "IsBuyNowOnly": true,
            "Quantity": 1,
            "IsFlatShippingCharge": true,
            "Options": [
                {
                    "Name": "Colour",
                    "Value": "Blue"
                }
            ],
            "ListingGroupId": 73059,
            "StatusDate": "/Date(0)/",
            "AuctionAttribute": "",
            "BuyerFeedbackPlaced": 0,
            "SellerFeedbackPlaced": 0,
            "DeliveryId": 0,
            "FpoDecisionViaMobile": false,
            "HasPaidByCreditCard": false,
            "InvoiceId": 0,
            "OfferId": 0,
            "PaymentInfo": "NZ Bank Deposit",
            "Price": 12.99,
            "SelectedShipping": "rural",
            "ShippingPrice": 9.99,
            "ShippingType": 4,
            "SoldDate": "/Date(1625648672660)/",
            "SoldType": "BUYNOW",
            "PaymentInstructions": "",
            "PurchaseId": 26176,
            "ReferenceNumber": "P26176",
            "SubtotalPrice": 12.99,
            "TotalShippingPrice": 9.99,
            "TotalSalePrice": 22.98,
            "TrackedParcels": [],
            "TaxSubTotal": 0,
            "HasPaidByDeferredPayment": false
        }
    ]
}
  • API checkpoint

Check whether items exist on the won list.

And store the won items PurchaseId and their counts as two environment variables: {{WonPurchaseId}} and {{WonPurchaseIdCount}} for downstream API - Remove a purchase from your won items list ' use.

Then we get the checking code snippet below base on the example feature.

console.log("Post-Transaction: CheckingWonListHaveItems Start");

pm.test("CheckingWonListHasItems", function () {

    var jsonData = pm.response.json();

    var arr =[];

    var List = jsonData.List;

    if (List != ""){

        for (i in List){

            var PurchaseId = List[i].PurchaseId;

            arr.push(PurchaseId);

        }

        // Store WonPurchaseIdCount for later deleting usage
        postman.setEnvironmentVariable('WonPurchaseIdCount', arr.length);

        if(arr !== []){
            
            if(arr.length >=1){

                // Store WonItems for later deleting usage         
                postman.setEnvironmentVariable('WonPurchaseId', arr);

                console.log("WonPurchaseId counts to: " + arr.length + ", the purchaseId: " + arr);
                
                console.log("Post-Transaction: CheckingWonListHaveItems Pass");

            }

            else{

                postman.setEnvironmentVariable('WonPurchaseId', arr);
                
                console.log("WonPurchaseId counts to: " + arr.length + ". There are no items on the won list.");
                
                console.log("Post-Transaction: CheckingWonListHaveItems Pass");

            }

        }
    }

    else{

        console.log("Post-Transaction: CheckingWonListHaveItems Failed");
        
    }

});

Run script to verify the checkpoint works from console log.

It has no items on the won list page displaying on the console log.

It has items on the won list page displaying on the console log.

API Testing Script Enhancement

  • Enhance the script, such as to add the transactional function, exceptional verification, parameterization, etc.

  • Run the final script and to verify from front-end page or console log.

API Testing Script Negative Cases Extension

Using the ‘Equivalent Class Partitioning’ and ‘Boundary Value Analysis’ as we did in manual testing cases.

These API test scripts are doing the negative direction of the business, to be an extension to the above API positive case.

API Testing Script Publishment

Move script from debug folder to public folder when we finished API positive and negative cases.

Then wait to be published to the GitHub specific repo combining with other scripts using the CICD tool.

Copyright

This work is licensed under CC BY-NC-ND 4.0 .