OroCommerce Forums

Covering OroCommerce topics, including community updates and company announcements.

Forums Forums OroCommerce Product Create through API

This topic contains 4 replies, has 3 voices, and was last updated by  Yurii Muratov 5 years, 11 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #32927

    indranil.s
    Participant

    Hi,

    I am trying to create a product through API. The endpoint I am using is:- “/admin/api/products” and the request body structure is:-
    {
    “data”:
    {
    “type”: “products”,
    “attributes”: {
    “availability_date”: null,
    “sku”: “Bajaj”,
    “status”: “enabled”,
    “variantFields”: [],
    “productType”: “simple”,
    “featured”: false,
    “newArrival”: false
    },
    “unitPrecisions”: {
    “data”: [
    {
    “type”: “productunitprecisions”
    }
    ]
    },
    “primaryUnitPrecision”: {
    “data”: {
    “type”: “productunitprecisions”
    }
    },
    “names”: {
    “data”:
    {
    “type”: “localizedfallbackvalues”
    }
    },
    “inventory_status”: {
    “data”: {
    “type”: “prodinventorystatuses”,
    “id”: “in_stock”
    }
    }
    }
    }
    The response is:-
    {
    “errors”: [
    {
    “status”: “400”,
    “title”: “count constraint”,
    “detail”: “Please add one or more product units.”,
    “source”: {
    “pointer”: “/data/relationships/unitPrecisions/data”
    }
    },
    {
    “status”: “400”,
    “title”: “not blank constraint”,
    “detail”: “This value should not be blank.”,
    “source”: {
    “pointer”: “/data/relationships/primaryUnitPrecision/data”
    }
    },
    {
    “status”: “400”,
    “title”: “count constraint”,
    “detail”: “This collection should contain 1 element or more.”,
    “source”: {
    “pointer”: “/data/relationships/names/data”
    }
    },
    {
    “status”: “400”,
    “title”: “not blank constraint”,
    “detail”: “This value should not be blank.”,
    “source”: {
    “pointer”: “/data/relationships/attributeFamily/data”
    }
    },
    {
    “status”: “400”,
    “title”: “not blank constraint”,
    “detail”: “This value should not be blank.”,
    “source”: {
    “pointer”: “/data/relationships/inventory_status/data”
    }
    }
    ]
    }
    So, can you tell me what should be minimum fields needed to create a product is OroCommerce?

    Regards,
    Indranil Saha

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #32928

    Dmitriy Pasechnik
    Participant

    Hi indranil.s

    The best way to discover of how to use API correctly is via our api`s sandbox
    Check this document:
    https://oroinc.com/orocrm/doc/1.10/book/data-api#api-sandbox

    Alternatevily, you can get some exapmples from our functional tests for product`s api:
    https://github.com/oroinc/orocommerce/blob/master/src/Oro/Bundle/ProductBundle/Tests/Functional/Api/ProductApiTest.php
    You can take a good example of request from this file:
    https://github.com/oroinc/orocommerce/blob/master/src/Oro/Bundle/ProductBundle/Tests/Functional/Api/requests/create_product_1.yml

    You need to add an ‘includes’ section with details for ‘unitPrecisions’, ‘primaryUnitPrecision’, ‘names’, ‘attributeFamily’.
    Try to take them from this example`s file

    #32929

    indranil.s
    Participant

    Hi Dmitri,

    Thank you for the links, I tried the same but didn’t work. I am getting the same error.
    Request Body:-
    {
    “data”:
    {
    “type”: “products”,
    “attributes”: {
    “availability_date”: null,
    “sku”: “Balaji”,
    “status”: “enabled”,
    “variantFields”: [],
    “productType”: “simple”,
    “featured”: false,
    “newArrival”: false
    },
    “names”:
    {
    “data”:
    {
    “type”: “localizedfallbackvalues”,
    “id”: “names-1”
    }
    },
    “unitPrecisions”:
    {
    “data”:
    {
    “type”: “productunitprecisions”,
    “id”: “product-unit-precision-id-1”
    }
    },
    “primaryUnitPrecision”:
    {
    “data”:{
    “type”: “productunitprecisions”,
    “id”: “product-unit-precision-id-3”
    }
    },
    “inventory_status”: {
    “data”: {
    “type”: “prodinventorystatuses”,
    “id”: “in_stock”
    }
    },
    “included” :
    [
    {
    “type”: “productunitprecisions”,
    “id”: “product-unit-precision-id-1”,
    “attributes”:
    {
    “precision”: “0”,
    “conversionRate”: “5”,
    “sell”: “1”
    }
    },
    {
    “type”: “localizedfallbackvalues”,
    “id”: “names-1”,
    “attributes”:
    {
    “fallback”: null,
    “string”: “Test product name”,
    “text”: null
    }
    },
    {
    “type”: “productunitprecisions”,
    “id”: “product-unit-precision-id-3”,
    “attributes”:
    {
    “precision”: “0”,
    “conversionRate”: “5”,
    “sell”: “1”
    }
    }
    ]
    }
    }
    Response :-
    {
    “errors”: [
    {
    “status”: “400”,
    “title”: “count constraint”,
    “detail”: “Please add one or more product units.”,
    “source”: {
    “pointer”: “/data/relationships/unitPrecisions/data”
    }
    },
    {
    “status”: “400”,
    “title”: “not blank constraint”,
    “detail”: “This value should not be blank.”,
    “source”: {
    “pointer”: “/data/relationships/primaryUnitPrecision/data”
    }
    },
    {
    “status”: “400”,
    “title”: “count constraint”,
    “detail”: “This collection should contain 1 element or more.”,
    “source”: {
    “pointer”: “/data/relationships/names/data”
    }
    },
    {
    “status”: “400”,
    “title”: “not blank constraint”,
    “detail”: “This value should not be blank.”,
    “source”: {
    “pointer”: “/data/relationships/attributeFamily/data”
    }
    },
    {
    “status”: “400”,
    “title”: “not blank constraint”,
    “detail”: “This value should not be blank.”,
    “source”: {
    “pointer”: “/data/relationships/inventory_status/data”
    }
    }
    ]
    }

    #32930

    indranil.s
    Participant

    Hi,

    The example mentioned in the sandbox API doesn’t work. So, I want a proper structure or the minimum fields required to post a product.

    #32931

    Yurii Muratov
    Participant

    Hello, @indranil.s.

    I have check the example from sandbox and for my instance it works. What error do you have?

    Please read documentation documentation for this API resource in sandbox, how to work with our JAON API https://oroinc.com/orocrm/doc/current/dev-guide/web-api and JSON API specification to better understand format of data http://jsonapi.org/format/.

Viewing 4 replies - 1 through 4 (of 4 total)

The forum ‘OroCommerce’ is closed to new topics and replies.

Back to top