Getting expected object definitions from Magento 2 REST API

176 Views Asked by At

When calling the Magento 2 REST API to get the schema for working with products using:

..rest/all/schema?services=catalogProductRepositoryV1

The response back includes:

...
    "paths": {
      "/V1/products": {
       "post": {
         "tags": [
           "catalogProductRepositoryV1"
         ],
         "description": "Create product",
         "operationId": "catalogProductRepositoryV1SavePost",
         "parameters": [
            {
              "name": "$body",
              "in": "body",
              "schema": {
                 "required": [
                   "product"
                 ],
                 "properties": {
                   "product": {
                      "$ref": "#/definitions/catalog-data-product-interface"
                    },
                    "saveOptions": {
                      "type": "boolean"
                    }
                },
                "type": "object"
             }
          }
       ],...

How do you go about getting the definition/schema for the "product" object that it expects during a POST call? i.e. the following definition:

"properties": {
   "product": {
       "$ref": "#/definitions/catalog-data-product-interface"
   },
1

There are 1 best solutions below

0
On

Looks like its only possible using the swagger GUI. Essentially replicate these steps and change your search term for whatever you're searching for:

  1. Go to: http://devdocs.magento.com/swagger/index.html
  2. Ctrl + f >> search for whatever you're after. In the case of the above: catalogProductRepositoryV1
  3. Expand the API interface by clicking it
  4. Choose your REST Method
  5. Under "Parameters" there will be a Model/Model Schema showing you what payload it expects.

Welcome to Swagger! It's great when you know how to use it!