how to pass parameters in xmlhttp

  • I have a program that I would like to integrate with WooCommerce. I am running into an issue when attempting to add a new product. Specifically the category and image fields. The following code works properly: (I changed to put instead of post so I would update the same product rather than continuing to add incomplete items)

    myurl = ‘https://url.com/wp-json/wc/v3/products?sku=’ & UPC & ‘&name=’ & title & ‘&regular_price=’ & price &consumer_key=’ & rs!woocomkey & ‘&consumer_secret=’ & rs!woocomsecret
    xmlhttp.Open ‘put’, myurl, False
    xmlhttp.setRequestHeader ‘accept’, ‘application/json’
    xmlhttp.send
    It works but sets the category to id 174 uncategorized

    when I try to add the addition parts below and mess with the formatting slightly I either get the same result or the error message Below it

    myurl = ‘https://url.com/wp-json/wc/v3/products?sku=’ & UPC & ‘&name=’ & title & ‘&regular_price=’ & price & ‘&categories=[{id=’ & cat2 & ‘}]&images=[{src=http://url.com/pos/default.jpg}]&consumer_key=’ & rs!woocomkey & ‘&consumer_secret=’ & rs!woocomsecret

    {‘code’:’rest_invalid_param’,’message’:’Invalid parameter(s): categories’,’data’: {‘status’:400,’params’:{‘categories’:’categories[0] is not of type object.’}}}
    I believe the issue is that I don’t know the proper syntax when there is a subcategory. Here is the related api document from Woocommerce. I don’t know PHP, Curl or the other options they list.

    curl -X POST https://example.com/wp-json/wc/v3/products
    -u consumer_key:consumer_secret
    -H ‘Content-Type: application/json’
    -d ‘{
    ‘name’: ‘Premium Quality’,
    ‘type’: ‘simple’,
    ‘regular_price’: ‘21.99’,
    ‘description’: ‘Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpisegestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.’,
    ‘short_description’: ‘Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.’,
    ‘categories’: [
    {
    ‘id’: 9
    },
    {
    ‘id’: 14
    }
    ],
    ‘images’: [
    {
    ‘src’: ‘http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg’
    },
    {
    ‘src’: ‘http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg’
    }
    ]
    Any Help would be greatly appreciated!

  • I apologize, the window I posted in did not have a code post funtion. this one does. here is the corrected post that will show the code correctly please help if you can.

    I have a program that I would like to integrate with WooCommerce. I am running into an issue when attempting to add a new product. Specifically the category and image fields. The following code works properly: (I changed to put instead of post so I would update the same product rather than continuing to add incomplete items)

    myurl = "https://url.com/wp-json/wc/v3/products?sku=" & UPC & "&name=" & title & "&regular_price=" & price &consumer_key=" & rs!woocomkey & "&consumer_secret=" & rs!woocomsecret
    xmlhttp.Open "put", myurl, False
    xmlhttp.setRequestHeader "accept", "application/json"
    xmlhttp.send

    It works but sets the category to id 174 uncategorized

    when I try to add the addition parts below and mess with the formatting slightly I either get the same result or the error message Below it

    myurl = "https://url.com/wp-json/wc/v3/products?sku=" & UPC & "&name=" & title & "&regular_price=" & price & "&categories=[{id=" & cat2 & "}]&images=[{src=http://url.com/pos/default.jpg}]&consumer_key=" & rs!woocomkey & "&consumer_secret=" & rs!woocomsecret
    
    {"code":"rest_invalid_param","message":"Invalid parameter(s): categories","data":    {"status":400,"params":{"categories":"categories[0] is not of type object."}}}
    I believe the issue is that I don't know the proper syntax when there is a subcategory. Here is the related api document from Woocommerce. I don't know PHP, Curl or the other options they list.
    
    curl -X POST https://example.com/wp-json/wc/v3/products \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
    "name": "Premium Quality",
    "type": "simple",
    "regular_price": "21.99",
    "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac    turpisegestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",
    "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.",
    "categories": [
    {
      "id": 9
    },
    {
      "id": 14
    }
    ],
    "images": [
    {
      "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
    },
    {
      "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg"
    }
    ]

    Any Help would be greatly appreciated!

  • Hi there,

    It looks like you’re in the wrong forum. It appears that you’re using the open-source WordPress software and the WooCommerce plugin. Therefore you need to seek help at these forums:

    https://wordpress.org/support/plugin/woocommerce

    https://wordpress.org/support/forums/

    These forums are for WordPress.com hosted sites only. If you want to know more about the differences between WordPress.com and the WordPress software you can read this document:

    WordPress.com vs. WordPress.org

  • The topic ‘how to pass parameters in xmlhttp’ is closed to new replies.