Create product with relationship not work correctly (via jsonadm)

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
malik_kat
Posts: 13
Joined: 09 Jan 2024, 09:20

Create product with relationship not work correctly (via jsonadm)

Post by malik_kat » 25 Apr 2024, 13:25

Hi,

I am working on added product with domians like text,media,catlog,price,stock by jsonadm. firstly i added the domains in database by jsonadm

1-Text Domian:
Send POST request to this resource

Code: Select all

http://127.0.0.1:8000/api/admin/default/jsonadm/text?_token=EK3LXeI0KN1ApZXHrNRu19WGyEJ75DUsXWOgbfjL
And get this response:

Code: Select all

{
    "meta": {
        "total": 1,
        "csrf": {
            "name": "_token",
            "value": "EK3LXeI0KN1ApZXHrNRu19WGyEJ75DUsXWOgbfjL"
        }
    },
    "data": [
        {
            "id": "394",
            "type": "text",
            "attributes": {
                "text.id": "394",
                "text.siteid": "1.",
                "text.ctime": ...,
                "text.mtime": ....,
                "text.editor":...,
                "text.type": "default"
            },
            "links": {
                "self": "http://127.0.0.1:8000/api/admin/default/jsonadm/text/44?locale=ar"
            },
            "relationships": []
        }
    ]
}
2- Media Domian:
Send POST request to this resource

Code: Select all

http://127.0.0.1:8000/api/admin/default/jsonadm/media?_token=EK3LXeI0KN1ApZXHrNRu19WGyEJ75DUsXWOgbfjL
And get this response:

Code: Select all

{
    "meta": {
        "total": 1,
        "csrf": {
            "name": "_token",
            "value": "EK3LXeI0KN1ApZXHrNRu19WGyEJ75DUsXWOgbfjL"
        }
    },
    "data": [
        {
            "id": "139",
            "type": "media",
            "attributes": {
                "media.id": "139",
                "media.siteid": "1.",
                "media.ctime":....,
                "media.mtime":....,
                "media.editor":....,
                "media.filesystem":....,
                "media.domain": .....,
                "media.label": .....,
                "media.languageid": null,
                "media.mimetype":....,
                "media.type": ....",
                "media.preview":.........,
                "media.previews": [],
                "media.url": ..,
                "media.status": 1
            },
            "links": {
                "self": "http://127.0.0.1:8000/api/admin/default/jsonadm/media/139?locale=ar"
            },
            "relationships": []
        }
    ]
}
3- Stock Domian:
Send POST request to this resource

Code: Select all

http://127.0.0.1:8000/api/admin/default/jsonadm/stock?_token=EK3LXeI0KN1ApZXHrNRu19WGyEJ75DUsXWOgbfjL
And get this response:

Code: Select all

{
    "meta": {
        "total": 1,
        "csrf": {
            "name": "_token",
            "value": "EK3LXeI0KN1ApZXHrNRu19WGyEJ75DUsXWOgbfjL"
        }
    },
    "data": [
        {
            "id": "44",
            "type": "stock",
            "attributes": {
                "stock.id": "44",
                "stock.siteid": "1.",
                "stock.ctime": .........,
                "stock.mtime": ........,
                "stock.editor": .,.........
                "stock.productid": "",
                "stock.stocklevel": 50,
                "stock.timeframe": "",
                "stock.dateback": null,
                "stock.type": "default"
            },
            "links": {
                "self": "http://127.0.0.1:8000/api/admin/default/jsonadm/stock/44?locale=ar"
            },
            "relationships": []
        }
    ]
}
4- Price Domian:

Send POST request to this resource

Code: Select all

http://127.0.0.1:8000/api/admin/default/jsonadm/price?_token=EK3LXeI0KN1ApZXHrNRu19WGyEJ75DUsXWOgbfjL
And get this response:

Code: Select all

{
    "meta": {
        "total": 1,
        "csrf": {
            "name": "_token",
            "value": "EK3LXeI0KN1ApZXHrNRu19WGyEJ75DUsXWOgbfjL"
        }
    },
    "data": [
        {
            "id": "82",
            "type": "price",
            "attributes": {
                "price.id": "82",
                "price.siteid": "1.",
                "price.ctime":.......,
                "price.mtime": ......,
                "price.editor": .......,
                "price.type": "default",
                "price.currencyid": "USD",
                "price.domain": "product",
                "price.quantity": 1,
                "price.value": "25.00",
                "price.costs": "0.00",
                "price.rebate": "0.00",
                "price.taxvalue": "0.0000",
                "price.taxrates": [],
                "price.taxrate": "0.00",
                "price.taxflag": true,
                "price.status": 1,
                "price.label": "USD 25"
            },
            "links": {
                "self": "http://127.0.0.1:8000/api/admin/default/jsonadm/price/82?locale=ar"
            },
            "relationships": []
        }
    ]
}
After that i collected the data that took from the all responses and send it to product resource to create a product with this relationships or domains.

5- Product Resource:

Send POST request to this resource

Code: Select all

http://127.0.0.1:8000/api/admin/default/jsonadm/product?_token=EK3LXeI0KN1ApZXHrNRu19WGyEJ75DUsXWOgbfjL
This data sent with request:

Code: Select all

{
    "data":{        
        "type": "product",
        "attributes": {
            "product.code": "test-api-p123",
            "product.label": "Test product api",
            "product.url": "test-api-p123",
            "product.type": "default",
            "product.status": "1"
        }
    },
    "relationships":{        
        "catalog": {
            "data": [
                {
                    "id": "18",
                    "type": "catalog"
                }
            ]
        },
        "price": {
            "data": [
                {
                    "id": "82",
                    "type": "price"
                }
            ]
        },
        "media": {
            "data": [
                {
                    "id": "139",
                    "type": "media"
                }
            ]
        },
        "text": {
            "data": [
                {
                    "id": "394",
                    "type": "text"
                }
            ]
        },
        "stock": {
            "data": [
                {
                    "id": "44",
                    "type": "stock"
                }
            ]
        }
    }    
}
i get this response but the relationships is empty and in admin dashboard added product don't have a price ,text,media,catalog,stock.

Code: Select all

{
    "meta": {
        "total": 1,
        "csrf": {
            "name": "_token",
            "value": "EK3LXeI0KN1ApZXHrNRu19WGyEJ75DUsXWOgbfjL"
        }
    },
    "data": {
        "id": "116",
        "type": "product",
        "attributes": {
            "product.id": "114",
            "product.siteid": "1.",
            "product.ctime": "2024-04-25 11:43:50",
            "product.mtime": "2024-04-25 11:43:50",
            "product.editor": ......,
            "product.url": "test-api-p123",
            "product.type": "default",
            "product.code": "test-api-p123",
            "product.label": "Test product api",
            "product.status": 1,
            "product.dataset": "",
            "product.datestart": null,
            "product.dateend": null,
            "product.config": [],
            "product.scale": 1,
            "product.target": "",
            "product.ratings": 0,
            "product.rating": "0.00",
            "product.instock": 0,
            "product.boost": 1
        },
        "links": {
            "self": "http://127.0.0.1:8000/api/admin/default/jsonadm/product/114?locale=ar"
        },
        "relationships": []
    }
}
Image
Image
Image
Image
Image
Image


PHP Version 8.2.12
Laravel version: 10
Aimeos version: 2023.10
Environment: windows (XAMPP cross-platform web server).

User avatar
aimeos
Administrator
Posts: 8009
Joined: 01 Jan 1970, 00:00

Re: Create product with relationship not work correctly (via jsonadm)

Post by aimeos » 26 Apr 2024, 12:09

In APIs following the JSON API standard, you can't assign other records in the relationship section. Instead, they are own resources where you have to do separate POST requests to the */lists resource, e.g. product/lists for assigning categories, prices, texts, etc.

Please note, that the JsonAdm API will be deprecated next year in favor of the GraphQL admin API, which is much simpler to use for creating and updating items. If possible, you should use the GraphQL admin API:
https://aimeos.org/docs/latest/admin/graphql/
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply