Include does not work on Product?

curl

#1

Hello,

I’m trying to use the include feature in order to get the category name on a list of products:

GET /v2/products?include=categories

The problem is that the response does not contain the category name. For each product I only have the type and id of the category:

{
  "relationships": {
    "categories": {
      "data": [
        {
          "type": "category",
          "id": "8550c943-85c2-4239-a8a4-bfa255a38f08"
        }
      ]
  }
}

Am I missing something ?
Also is it possible to chain include (similar to filter) something like ?include=categories:main_image ?

Thanks


#2

Hi @ggrossetie

You should see included in the response that contains the category name.

You can see an example below that gets a category by ID and includes products.

{
	"data": {
		"id": "521e6029-0e0e-4704-b9a5-9777047ada04",
		"type": "category",
		"status": "live",
		"name": "Bright",
		"slug": "bright",
		"description": "Bright Category",
		"meta": {
			"timestamps": {
				"created_at": "2018-02-05T11:19:08+00:00",
				"updated_at": "2018-03-29T10:34:13+00:00"
			}
		},
		"relationships": {
			"products": {
				"data": [
					{
						"type": "product",
						"id": "41c84c63-4d5e-4135-979f-e4b681b83dcc"
					}
				]
			}
		},
		"background_colour": "#ded7cb",
		"background_image": "https://s3-eu-west-1.amazonaws.com/bkt-svc-files-cmty-api-moltin-com/e8c53cb0-120d-4ea5-8941-ce74dec06038/61118f21-14a2-466c-a84b-c30b1f900cf9.png"
	},
	"included": {
		"products": [
			{
				"type": "product",
				"id": "41c84c63-4d5e-4135-979f-e4b681b83dcc",
				"name": "Orb",
				"slug": "orb",
				"sku": "ORLP100WHI",
				"manage_stock": false,
				"description": "Abstract, sculptural, refined and edgy with a modern twist. Its symmetrical, spoked structure generates a clever geometric presence, which works well in a contemporary environment.",
				"price": [
					{
						"amount": 45000,
						"currency": "USD",
						"includes_tax": true
					}
				],
				"status": "live",
				"commodity_type": "physical",
				"meta": {
					"timestamps": {
						"created_at": "2017-06-19T13:26:03+00:00",
						"updated_at": "2018-03-13T13:43:57+00:00"
					},
					"display_price": {
						"with_tax": {
							"amount": 45000,
							"currency": "USD",
							"formatted": "$450.00"
						},
						"without_tax": {
							"amount": 45000,
							"currency": "USD",
							"formatted": "$450.00"
						}
					},
					"stock": {
						"level": 500,
						"availability": "in-stock"
					}
				},
				"relationships": {
					"files": {
						"data": [
							{
								"type": "file",
								"id": "61118f21-14a2-466c-a84b-c30b1f900cf9"
							}
						]
					},
					"categories": {
						"data": [
							{
								"type": "category",
								"id": "521e6029-0e0e-4704-b9a5-9777047ada04"
							}
						]
					},
					"main_image": {
						"data": {
							"type": "main_image",
							"id": "61118f21-14a2-466c-a84b-c30b1f900cf9"
						}
					}
				}
			}
		]
	}
}

I hope this helps :smile:


#3

Hello @notrab

OH I see! Thanks :+1:
I thought that the data would have been available on each product. But I guess there would have been duplication. Anyway, its working, thanks again :smile:

Guillaume


#4

No worries - We try to adhere to the JSONAPI spec to provide a consistent and performant API, which as you pointed out would reduce the response data by only including data once.

Have fun building with moltin :tada:


#5

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.