I have current instaled the ‘WP REST API – OAuth 1.0a Server’ in my wordpress, i want to make some api request inside the wordpress to generate dinamic content with woocommerce – so woocommerce has generated a consumer key and consumer secret for me to access this informations…

When i do my request in POSTMAN with consumer key and consumer secret the request works fine, but when i try to apply this in the jquery the request don’t work! My question is where i put the consumer secret?

my js code :

$.ajax({
        method: 'GET',
        url: product_request.product_url,
        crossDomain: true,
        beforeSend: function ( xhr ) {
          xhr.setRequestHeader( 'Authorization', ({oauth_consumer_key:ck_42699deb096b38350a1fb7db3545e00644fb486d}) );
        },
        success: function(products){
            console.log(products);

        }
    })

the php code

// Ajax Request Product Script
    wp_enqueue_script('product_request_js', get_template_directory_uri() . '/js/product-request.js', true );

    wp_localize_script('product_request_js', 'product_request', array(
        'product_url' => rest_url('/wc/v2/products'),
        'nonce' => wp_create_nonce( 'wp_rest' )
        )
    );

Read more here: How to send a Oauth 1.0a to wordpress – jquery with Consumer key and Consumer Secret?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: