<style>
  .textordercolor {
    color: #1F02F1;
  }
  .scrollsection {
    overflow-y: auto;
    overflow-x: visible;
    max-height: 600px;
    background-color: WhiteSmoke;
  }
  .scrollsectiontablesingle {
    overflow-y: auto;
    overflow-x: visible;
    max-height: 600px;
  }
</style>

# Taxonomy(Site Hierarchy)

- [Overview](#overview)
- [API](#api)
  * [OAuth API](#oauth-api)
  * [Taxonomy API](#taxonomy-api)
- [Taxonomy API CURL Call](#taxonomy-api-curl-call)

## Overview
Taxonomy API exposes the category taxonomy used by walmart.com to categorize items. It specifies three levels. It is possible to specify the exact categoryId as a parameter when using feed apis of product snapshot and pricing and availability snapshot. This api can be used with OAuth based authentication. 

## API
As a first step, the client would use api proxy service' OAuth API to get the auth token using  wm\_consumer.id, client\_id, client\_secret. Second step would be to call taxonomy with relevant wm_consumer.id and auth token.

### OAuth API

<details>
  <summary>
    <span class="textordercolor">Details OAuth API:</span>
  </summary>
  <br/>
  <div class="scrollsection">

**API Endpoint Info**

| 						            |                                                     |
| ----------------------- | --------------------------------------------------- |
| Endpoint                | https://developer.api.walmart.com/api-proxy/service |
| Request/Response format | JSON                                                |
| Method                  | POST                                                |
| URI                     | /identity/oauth/v1/token                            |
| Authentication          | Client Id, Client Secret                            |


**Request Header Parameters**

| Header Parameter | Description                       | Mandatory |
| ---------------- | --------------------------------- | --------- |
| cache-control    | no-cache                          | Yes       |
| WM_CONSUMER.ID   | Walmart Consumer Id               | Yes       |
| Content-Type     | application/x-www.form-urlencoded | Yes       |

**Request Payload Parameters**

| Payload Parameter | Description          | Mandatory |
| ----------------- | -------------------- | --------- |
| grant_type        | Client credentials   | Yes       |
| client_id         | Walmart Consumer Id   | Yes       |
| client_secret     | IAM Generated Secret | Yes       |

  </div>
</details>

### Taxonomy API

Using the API token received from OAuth API, a call is made to the taxonomy along with relevant wm_consumer.id 

**API Endpoint Info**

|  						            |                                                     |
| ----------------------- | -----------------------------------------           |
| Endpoint                | https://developer.api.walmart.com/api-proxy/service |
| Response format         | JSON                                                |
| Method                  | GET                                                 |
| URI                     | /affil/catalog-api/v2/taxonomy             |
| Authentication          | OAuth based API token                               |

***Temporary taxonomy endpoint until GLASS launch:*** https://developer.api.walmart.com/api-proxy/service/affil/catalog-api/v2/glass/taxonomy


**Request Header Parameters**

| Header Parameter | Description                       | Mandatory |
| ---------------- | --------------------------------- | --------- |
| WM_CONSUMER.ID   | Walmart Consumer Id               | Yes       |
| AUTHORIZATION	   | Bearer <oauth_token>              | Yes       |
| Content-Type     | application/json                  | Yes       |

**Request Query Parameters**

By default, the API would return the entire taxonomy json. But, if gcs signed URL is required the query parameter to be passed is rt=gcsSignedURL.

| Query/Path Parameter     | Description                                                |     Mandatory     |               
| ------------------------ | ---------------------------------------------------------- | --------------------   
| rt=gcsSignedURL         | If rt=gcsSignedURL is specified, it will return gcs signed URL.       |          No.       |


## Taxonomy API CURL Call

**API Request**

1. To Get OAuth Token

    ```
    curl -X POST \
      https://developer.api.walmart.com/api-proxy/service/identity/oauth/v1/token \
      -H 'wm_consumer.id: <client id>' \
      -d 'grant_type=client_credentials&client_id=<client id>&client_secret=<client secret>'
    
    ```
    
    Successful response of the IAM Call Above:
    
    
    ```
    HTTP/1.1 200 OK
    {
        "access_token": "2YotnFZFEjr1zCsicMWpAA",
        "token_type": "Bearer",
        "expires_in": 3600
    }
    ```
2. From the response, external client can get access_token along with token TTL, pass the token along with api call to the taxonomy API

```
 curl -X GET \
  https://developer.api.walmart.com/api-proxy/service/affil/catalog-api/v2/taxonomy \
  -H 'content-type: application/json'\
  -H 'wm_consumer.id: <>'\
  -H 'authorization: Bearer <>'
```

Note: If the token expires after TTL or any other Authorization error occurs, then external client needs to make another call to IAM to get another token and perform the service call.

Example response when token expires:

response status: 401

```
{
    "details": {
        "Description": "Access token : *********** validation failed with error : expired token"
    }
}

```

**API Response**

The api with query parameter rt=gcsSignedURL returns a gcs signed url which has the  taxonomy information. Following is an example of how the response would look. 

```
{
  "site_hierarchy_data": ["https://storage.googleapis.com/<bucket_name>/taxonomy_data/site_hier_data.json?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=svc-affil-dev%40wmt-affil-partnerships-stg.iam.gserviceaccount.com%2F20200508%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20200508T200304Z&X-Goog-Expires=21600&X-Goog-SignedHeaders=host&X-Goog-Signature=17304da4a3889d243c08b6163f4a92b81f45f524ba9bc9b4027e1a89d07a07171d294db22a10e6b96a2c4161e9b0ad0bc5d9a21f2ff3ab05aa32b57757482a0eea4382878598da147a3f6beb0250bc1a8d2a7a694987dc294e9adc0d2a351e6e9b01380ffd7f343774b0f6f31b16186d4e338630a4aca3a92dc9b982824b60f04d0932717cb6f0191a0e639313e9189feb3de92b98a313fd903913b3b9c8ed8fa8ea1632dfa42ef85f0dc5328d3e042bdcd9b042da8b26dcfde615576511d18630e066cd2aaa710a8f18be70a3e76c8e8d6d72abafdedd4a37b11300c00d310bb2809a2fac6425c57af4bfc2c89e1c1b474a641578a057d99ee283b13cb87d6d"]
}
```

**Contents of the gcs signed url and the default taxonomy json**

The signed url and the default Json response returned by api would have taxonomy information as shown below.

```
{
  "categories": [
    {
      "id": "1256653760036",
      "name": "Garden & Tools",
      "path": "Garden & Tools",
      "children": [
        {
          "id": "1256653760036_1255142220713",
          "name": "Automotive",
          "path": "Garden & Tools/Automotive",
          "children": [
            {
              "id": "1256653760036_1255142220713_6822594436",
              "name": "Auto Accessories",
              "path": "Garden & Tools/Automotive/Auto Accessories"
            },
            {
              "id": "1256653760036_1255142220713_1255142223500",
              "name": "Auto Care & Cleaning",
              "path": "Garden & Tools/Automotive/Auto Care & Cleaning"
            },
            {
              "id": "1256653760036_1255142220713_1255142223550",
              "name": "Auto Lighting",
              "path": "Garden & Tools/Automotive/Auto Lighting"
            },
            {
              "id": "1256653760036_1255142220713_1255142223575",
              "name": "Auto Paint & Body",
              "path": "Garden & Tools/Automotive/Auto Paint & Body"
            },
            {
              "id": "1256653760036_1255142220713_1255142223600",
              "name": "Auto Safety Accessories",
              "path": "Garden & Tools/Automotive/Auto Safety Accessories"
            },
            {
              "id": "1256653760036_1255142220713_1255142223625",
              "name": "Automotive Electrical",
              "path": "Garden & Tools/Automotive/Automotive Electrical"
            },
            {
              "id": "1256653760036_1255142220713_1255142223650",
              "name": "Automotive Repair",
              "path": "Garden & Tools/Automotive/Automotive Repair"
            },
            {
              "id": "1256653760036_1255142220713_1255142226103",
              "name": "Cargo Management",
              "path": "Garden & Tools/Automotive/Cargo Management"
            },
            {
              "id": "1256653760036_1255142220713_1255142227109",
              "name": "Coverings & Protection",
              "path": "Garden & Tools/Automotive/Coverings & Protection"
            },
            {
              "id": "1256653760036_1255142220713_1255142229577",
              "name": "Floor & Cargo Mats",
              "path": "Garden & Tools/Automotive/Floor & Cargo Mats"
            },
            {
              "id": "1256653760036_1255142220713_1255142229627",
              "name": "Fluid Management",
              "path": "Garden & Tools/Automotive/Fluid Management"
            },
            {
              "id": "1256653760036_1255142220713_1255142229652",
              "name": "Fluids & Lubricants",
              "path": "Garden & Tools/Automotive/Fluids & Lubricants"
            },
            {
              "id": "1256653760036_1255142220713_1255152089798",
              "name": "Fuel Storage & Transfer",
              "path": "Garden & Tools/Automotive/Fuel Storage & Transfer"
            },
            {
              "id": "1256653760036_1255142220713_1255142232354",
              "name": "Interior Accessories",
              "path": "Garden & Tools/Automotive/Interior Accessories"
            },
            {
              "id": "1256653760036_1255142220713_9884281317",
              "name": "Key Accessories",
              "path": "Garden & Tools/Automotive/Key Accessories"
            },
            {
              "id": "1256653760036_1255142220713_1255142234460",
              "name": "Motorcycle Accessories",
              "path": "Garden & Tools/Automotive/Motorcycle Accessories"
            },
            {
              "id": "1256653760036_1255142220713_1255142234710",
              "name": "Oils and Air Filters",
              "path": "Garden & Tools/Automotive/Oils and Air Filters"
            },
            {
              "id": "1256653760036_1255142220713_1255142236750",
              "name": "RV Accessories",
              "path": "Garden & Tools/Automotive/RV Accessories"
            },
            {
              "id": "1256653760036_1255142220713_1255142238077",
              "name": "Seat Accessories",
              "path": "Garden & Tools/Automotive/Seat Accessories"
            },
            {
              "id": "1256653760036_1255142220713_1255142239480",
              "name": "Steering Wheel",
              "path": "Garden & Tools/Automotive/Steering Wheel"
            },
            {
              "id": "1256653760036_1255142220713_1255142239555",
              "name": "Storage & Organization",
              "path": "Garden & Tools/Automotive/Storage & Organization"
            },
            {
              "id": "1256653760036_1255142220713_1255142239680",
              "name": "Sun Protection",
              "path": "Garden & Tools/Automotive/Sun Protection"
            },
            {
              "id": "1256653760036_1255142220713_1255142240205",
              "name": "Tires Accessories",
              "path": "Garden & Tools/Automotive/Tires Accessories"
            },
            {
              "id": "1256653760036_1255142220713_1255142241892",
              "name": "Windshield",
              "path": "Garden & Tools/Automotive/Windshield"
            }
          ]
        }
      ]
    }
  ]
}
```

**Some top level categories to try out for the feeds**

Following are some categories that can be used to try out the product snapshot and pricing and availability snapshot feeds.

```
{
  "allOffers": {
    "categories": [
      "2636",
      "1229749",
      "91083",
      "5428",
      "3891",
      "4096",
      "4044",
      "4104",
      "2637",
      "3944",
      "4125",
      "4171",
      "3920",
      "1072864",
      "1334134",
      "5440",
      "5427",
      "1094765",
      "5434",
      "5431",
      "1005862",
      "976760",
      "14503",
      "5426",
      "5438",
      "7796869",
      "5433",
      "5436",
      "1085666",
      "1105910",
      "1085632",
      "976759",
      "1115193",
      "6163033",
      "5920738",
      "8932632",
      "6735581",
      "6197502",
      "7924299",
      "3734780",
      "5939293",
      "5324366",
      "5984018",
      "6984709",
      "6914230",
      "5967908",
      "9748312",
      "3625709"
    ]
  },
  "perishableOffers": {
    "categories": [
      "976759"
    ]
  }
}
```

