Okay
  Public Ticket #3078530
API Documentation
Closed

Comments

  •  1
    wecommercedigital started the conversation

    Hi there, Could you please send a link to the API documentation?

    It would be very important for us as we are trying to integrate with Sage.

    Thanks

  •  1,906
    WebWizards replied

    Hi Zoltan,

    Thank you for purchasing our plugin. 

    B2BKing does not have its own API, as all of its data is stored as user/product metadata. Per our previous emails, user and product data can be accessed by using the WordPress or WooCommerce APIs. It's best to use the WooCommerce API where possible.

    For that API's documentation, please see https://woocommerce.github.io/woocommerce-rest-api-docs/


    Generally to integrate with Sage, it may be best to start with an existing solution such as https://www.woosage.com/ or https://www.codelessplatforms.com/solutions/woocommerce-sage-integration/


    Kind regards,

    Stefan

  •   wecommercedigital replied privately
  •  1,906
    WebWizards replied

    Hi there,


    1) A group is a wordpress post, of the custom post type named b2bking_group. You would need to insert a post of this type to create a group.


    2) To assign a customer to a customer group, the following 2 user meta keys need to be set for the customer:

    -> b2bking_b2buser must have the value yes

    -> b2bking_customergroup must have the value of the group ID (the POST ID of the group), for example 1234

    3) This is a bit unclear, as the plugin does not have a feature to change the price based on the link used. The way it works is that when a user views a product, if they are logged in as a user part of group X, they will simply see the price of group X. It depends on the user they are logged in as. The product link is always the same normal link.


    Kind regards,

    Stefan

  •   wecommercedigital replied privately
  •  1,906
    WebWizards replied

    Hi there,

    It would be a JSON body type.

    You would use the following endpoint:

    https://yoursite.com/wp-json/wp/v2/b2bking_group


     A simple request like this would work:

    8314732779.png


    I suggest you see our guide here on point 2.1: https://woocommerce-b2b-plugin.com/docs/import-or-setup-dynamic-rules-programatically/

    It is for creating dynamic rules via REST API, but the same principles apply for creating groups via REST API.

  •   wecommercedigital replied privately
  •  1,906
    WebWizards replied

    Hi there,

    1) You can simply access the http://yoursite.com/wp-json/wp/v2/b2bking_group URL and you will get a JSON list of all group posts:

    5970129574.png

    Or with something else by making a GET request to that URL.

    I am not sure if there's any way to get only the names of the groups (titles) unfortunately. 

    2)

    Sorry, can you explain that or give an example? What do you mean by property responses?


    Kind regards,

    Stefan

  •  1
    wecommercedigital replied

    Hi Stefan, thanks.

    The integration developer would join this conversation if that's ok. Its easier if he asks questions directly than me.

  •  1
    Anton replied

    Hi Stefan,

    Please confirm what is the POST request json body to create Group? The json body you provided earlier doesn't have group name which means that we will create a noname group?

    Best regards, Anton.

  •  1,906
    WebWizards replied

    Hi Anton,

    To configure a specific group name, you can enter it like this:

    {
        "status": "publish",
        "type": "b2bking_group",
        "title": "My New Group"
    }
    


    1341535543.png


    Then I can see it here:

    6555379233.png


    Kind regards,

    Stefan


  •  1
    Anton replied

    Hi Stefan,

    thx, for your reply. Unfortunately, it says that the creation failed

    see the request and response in attach

    Best regards, Anton.

    Attached files:  POST new group.png

  •  1,906
    WebWizards replied

    Hi Anton,

    The URL of the request there seems incorrect. I see you are using a URL ending in wc/v3/create_user_group.

    The URL should be  https://yoursite.com/wp-json/wp/v2/b2bking_group , replacing yoursite.com 

  •  1
    Anton replied

    Hi,

    thx, sorry, got cross-referenced emails and used the wrong url.

    anyway I tried but it failed with a strange error:

    {
      "code": "rest_cannot_create",
      "message": "Sorry, you are not allowed to create posts as this user.",
      "data": {
        "status": 401
      }
    }

    I, as a user in the admin, can create a group. API has full permissions(read/write)

    Best regards, Anton.

  •  1,906
    WebWizards replied

    You need to use a plugin like this one:

    https://wordpress.org/plugins/wp-rest-api-authentication/


    You can configure it like this:

    5148697095.png


  •  1
    Anton replied

    Hi,

    thx for your reply but, why do I need 3rd party app to be authorized in WooCommerce if it already has an authentication process?

    Best regards, Anton.

  •  1,906
    WebWizards replied

    Hi Anton,

    This is not specific to our plugin. Our groups are simply custom post types in WordPress. 

    You can try to create another custom post type, for example try to use this URL

    http://yoursite.local/wp-json/wp/v2/product

    and create a WooCommerce product with this input

    {
        "status": "publish",
        "type": "product",
        "title": "My New Product"
    }
    


    You will have the same authentication error.


    So it has something to do with the Wordpress authentication process for APIs. I don't know exactly how this works, we are not experts in this and it is not our field of expertise.

  •  1
    Anton replied

    Hi,

    There are no issues with the creation of products, customers or orders in the woocommerce using standard woocommerce API
    the issue is only that I can't create a group using your plugin, that's all :)

    Best regards, Anton.

  •  1,906
    WebWizards replied

    Creating items via wp/v2/product is using the WordPress API, not the WooCommerce API.


    This is not a feature of our plugin, it is a feature of WordPress, we did not write this API.


    I don't know the details of how its authentication works. You would need to look into the documentation of the WordPress V2 API.


    B2BKing does not have its own API.

    Since this is custom coding, this is not something we can support or handle directly for you. 


  •  1
    Anton replied

    Hi,

    ok, then it makes sense, thx
    I will ask website devs to install those API plugins

    Best regards, Anton.