Product list JSON api

Support » Plugin: WooCommerce » GET products via api json

GET products via api json

  • Resolved unionwebdev

    [@unionwebdev]


    2 years, 5 months ago

    Im having a very difficult time finding any documentation on loading in products and custom information via an api GET [json]

    If I can be pointed in the right direction or told a better way to do this.

    My client wants to store some information outside of WooCommerce and the WP database and retrieve via an api GET returning json data. Is this a valid approach or is there a more appropriate way?

    Stored Externally
    User
    Product
    Price
    Image
    Desc

    All other site data to remain within WP database.

Viewing 7 replies - 1 through 7 [of 7 total]
  • ozbassplayer

    [@ozbassplayer]

    2 years, 5 months ago

    You need to set up the WC Rest API first and get your consumer key & secret.
    Then use those credentials in an API call like this:
    //yourdomain.com/wp-json/wc/v2/products/?consumer_key=yourconsumerkey123&consumer_secret=yourconsumersecret.
    Documentation is here: //woocommerce.github.io/woocommerce-rest-api-docs/

    ozbassplayer

    [@ozbassplayer]

    2 years, 5 months ago

    I just re-read your question and need clarification:
    Do you want to store all product info elsewhere, and call it INTO your wordpress site on the fly?
    Im scratching my head. do you want to create products in woocommerce without names, descriptions etc and have those automatically populate [somehow] on the fly, or do you want to have a CRM style of core control outside of your website which stores the original data and periodically populates your WC site as required? Once thats done the data would remain on your site until another update.
    Is that what you mean?

    Thread Starter unionwebdev

    [@unionwebdev]

    2 years, 5 months ago

    This is correct I want to store all product info elsewhere, and call it INTO the wordpress site

    ozbassplayer

    [@ozbassplayer]

    2 years, 5 months ago

    OK then you need to sent a POST request with a correctly formatted JSON in the body to create new product, and a PUT if you want to update an existing product. Try using Postman to help you with this.
    Understand that once youve done this, the data will reside in your wordpress site. but new products and updated products you can use the methods explained above.
    The rest endpoints are well explained in the documentation that I provided a link for above.

    Example of a PUT product update JSON:
    {
    name: First Test Product Title Change by REST,
    slug: first-product,
    description:

    This product was created in WordPress using the standard WordPress / WooCommerce Environment

    \n

    Its a simple product, with no variations.

    \n,
    short_description:First Test Product ,
    regular_price: 199.50
    }
    /* - */
    the URL would be something like this with the method set to PUT[product id is 18 in this case:
    //example.com/wp-json/wc/v2/products/18?consumer_key=insert_consumer_key&consumer_secret=insert_consumer_secret

    /* - */
    Example of a POST new product JSON
    {
    name: API-Generated Product,
    slug: api-generated,
    permalink: //example.com/product/api-generated/”,
    type: simple,
    status: publish,
    featured: false,
    catalog_visibility: visible,
    description:

    Created using WC REST API

    \n

    Create the JSON data without an id value.

    Use POST [not put]. Remember to include consumer key & secret.

    \n,
    short_description:

    REST API POST call

    \n,
    sku: wprestapi_1,
    price: 100.00,
    regular_price: 100.00,
    sale_price: ,
    date_on_sale_from: null,
    date_on_sale_from_gmt: null,
    date_on_sale_to: null,
    date_on_sale_to_gmt: null,
    price_html: $0.02,
    on_sale: false,
    purchasable: true,
    total_sales: 0,
    virtual: false,
    downloadable: false,
    downloads: [],
    download_limit: -1,
    download_expiry: -1,
    external_url: ,
    button_text: ,
    tax_status: taxable,
    tax_class: ,
    manage_stock: false,
    stock_quantity: null,
    in_stock: true,
    backorders: no,
    backorders_allowed: false,
    backordered: false,
    sold_individually: false,
    weight: ,
    dimensions: {
    length: ,
    width: ,
    height:
    },
    shipping_required: true,
    shipping_taxable: true,
    shipping_class: ,
    shipping_class_id: 0,
    reviews_allowed: false,
    average_rating: 0.00,
    rating_count: 0,
    related_ids: [],
    upsell_ids: [],
    cross_sell_ids: [],
    parent_id: 0,
    purchase_note: ,
    categories: [
    {
    id: 17,
    name: Main Category,
    slug: main-category
    },
    {
    id: 18,
    name: Sub Category,
    slug: sub-category
    }
    ],
    tags: [],
    images: [ ],
    attributes: [],
    default_attributes: [],
    variations: [],
    grouped_products: [],
    menu_order: 0,
    meta_data: [

    ],
    _links: {
    self: [],
    collection: []
    }
    }
    /* - */
    the URL would be something like this with the method set to POST:
    //example.com/wp-json/wc/v2/products/?consumer_key=insert_consumer_key&consumer_secret=insert_consumer_secret

    Plugin Support AW a11n

    [@slash2andy]

    Automattic Happiness Engineer

    2 years, 4 months ago

    Hey there!

    Since this is a few weeks old, and about customization, I am going to mark as resolved. A lot of people have found help in the Advanced WooCommerce group with things like this, so I would recommend checking there, or we highly recommend contacting one of the services on our Customizations page [//woocommerce.com/customizations/]

    Kevin Brent

    [@kevin-brent]

    1 year, 11 months ago

    Have you seen WP Data Sync? I think this is what you are looking for.

    //wpdatasync.com
    //wordpress.org/plugins/wp-data-sync/
    //wordpress.org/plugins/wp-data-sync-woocommerce/

    wotan6891

    [@wotan6891]

    1 year, 11 months ago

    Hi,

    Friend @ozbassplayer I would like to know how to use the Woocommerce REST API regarding: using a product providers PHP API. in that providers PHP API is the product prices, shipping prices, product description with images and other things.

    Thank you.

Viewing 7 replies - 1 through 7 [of 7 total]
  • The topic GET products via api json is closed to new replies.

Video liên quan

Chủ Đề