Okay
  Public Ticket #2965100
Not able to generate Dynamic Rules using REST API
Closed

Comments

  •  6
    Nicolai started the conversation

    Hi,

    I cant create DYnamic Rules using REST / Postman. I'm trying to send this JSON:

    {
        "status": "publish",
        "type": "b2bking_rule",
        "slug": "36_11892_auto",
        "meta":
        {
            "b2bking_rule_what": [
                    "fixed_price"
                ],
            "b2bking_rule_howmuch": [
                    "333.22"
                ],
           "b2bking_rule_applies": [
                    "product_11892"
                ],
            "b2bking_rule_who": [
                    "user_36"
                ],
                "b2bking_rule_quantity_value": [
                "quantity"
            ],
             "b2bking_rule_requires": [
                "nothing"
            ]
        }
    }

    But I get the following result:

    {
        "code": "rest_cannot_create",
        "message": "Du har desværre ikke tilladelse til at oprette indlæg som denne bruger.",
        "data": {
            "status": 401
        }
    }

    Translation of message: "You have no rights to create posts as this user".

    My API is hooked up to my administrator account in Woo, so I guess rights isn't the issue :)


  •  2,218
    WebWizards replied

    Hi Nicolai,

    For me it works if I do this:

    1) Install and activate this plugin: https://wordpress.org/plugins/wp-rest-api-authentication/

    In the plugin, I believe these are the default settings:

    6166225200.png


    2) Then in Postman it is set like this:

    7005566085.png


    Step 1) seems to be needed as well - otherwise if I do step 2) alone, I get the same error as you "rest_cannot_create". 

    Please try with the above plugin and let me know if that did it for you,

  •  6
    Nicolai replied

    Hi,

    It "worked". I can now update/create Dynamic Rules. Unfortunately with the cost that all of my other REST API connections doesn't work. I can't access any "v3" via postman... :(

    Error for all wp/v3 enquiries via postman: 

    https://mysiteaddress/wp-json/wc/v3/customers/34 gives this:

    {
        "status": "error",
        "error": "Restricted",
        "error_description": "Sorry, you are not allowed to access REST API."
    }

    Can't find anything on their website in this relation. I can access wp/v2/posts, but not anything from wc/v3/products, customer etc.


  •  2,218
    WebWizards replied

    I don't have any info on this unfortunately. We only very rarely use REST API, so I'm far from an expert in it. 

    I'd look at trying some other different authentication plugins, or some other auth methods.


    I will search more about that error to see if I can find anything.


    Possibly the miniorange basic authentication is too simple / not accepted by the v3 API?

    This may be relevant: http://woocommerce.github.io/woocommerce-rest-api-docs/#authentication

    I see it says:

    "You may use HTTP Basic Auth by providing the REST API Consumer Key as the username and the REST API Consumer Secret as the password."

    Possibly you need to use a different login when working with the WC api