Jump to content
UBot Underground

Using Http Post Plugin With Woocommerce Restful Api


Recommended Posts

I am at an absolute total loss on how to make this work... I am trying to make a ubot that can post products to a woocommerce website using the rest api v2... Here is the page that has the documentation

http://woothemes.github.io/woocommerce-rest-api-docs/#create-a-product

Tried some basic queries to pull a record out by ID just to test the connection before I get into posting things... But all I ever get is a 404 error using the http get command, and saying the token is wrong or something... but its because of some kind of encoding thing I guess... After googling around I found a way to add the key/secret right in the url, but that does not seem fiesable for creating products... All the examples are using curl, and SOMETHING about it is different than a regular browser request type thing (I am clueless I guess)... So anyway, I am just wondering how I would submit this gigantic datapacket to this api in order to create a product using UBOT instead of this curl command.  I am (obviously) a total novice at anything to do with API's, so I don't even know for sure how I'm going to create this json for sure. I just have a bunch of ubot variables and need to send it over there somehow. My idea would be to just create some kind of giant variable with all this stuff in there replacing with my variables I guess, but my thought is there is probably some other way hahaha. Anybody care to get me started here? I just need a nudge.  I do have the wordpress plugin from pash if it were at all helpful to use that somehow to do this, I dont think it will work tho, but I dunno...

Example of how to create a variable product:

curl -X POST https://example.com/wc-api/v2/products \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "product": {
    "title": "Ship Your Idea",
    "type": "variable",
    "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. 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": [
      "Clothing",
      "T-shirts"
    ],
    "images": [
      {
        "src": "http://example.com/wp-content/uploads/2015/01/ship-your-idea-black-front.jpg",
        "position": 0
      },
      {
        "src": "http://example.com/wp-content/uploads/2015/01/ship-your-idea-black-back.jpg",
        "position": 1
      },
      {
        "src": "http://example.com/wp-content/uploads/2015/01/ship-your-idea-green-front.jpg",
        "position": 2
      },
      {
        "src": "http://example.com/wp-content/uploads/2015/01/ship-your-idea-green-back.jpg",
        "position": 3
      }
    ],
    "attributes": [
      {
        "name": "Color",
        "slug": "color",
        "position": "0",
        "visible": false,
        "variation": true,
        "options": [
          "Black",
          "Green"
        ]
      }
    ],
    "default_attributes": [
      {
        "name": "Color",
        "slug": "color",
        "option": "Black"
      }
    ],
    "variations": [
      {
        "regular_price": "19.99",
        "image": [
          {
            "src": "http://example.com/wp-content/uploads/2015/01/ship-your-idea-black-front.jpg",
            "position": 0
          }
        ],
        "attributes": [
          {
            "name": "Color",
            "slug": "color",
            "option": "black"
          }
        ]
      },
      {
        "regular_price": "19.99",
        "image": [
          {
            "src": "http://example.com/wp-content/uploads/2015/01/ship-your-idea-green-front.jpg",
            "position": 0
          }
        ],
        "attributes": [
          {
            "name": "Color",
            "slug": "color",
            "option": "green"
          }
        ]
      }
    ]
  }
}'

Link to post
Share on other sites

Hello.

 

Sending a application/json  http post request is definitively possible with http plugin. 

If the headers are set correctly and you use the correct consumer_secret, then I can't see why this should not work. 

 

You should definitely trace the http request with fiddler to see the full reply from the webserver. 

The response with ubot studio and http plugin is very limited. You don't see the full response there!

 

And you have to enable the API within the woocommerce plugin, but I think you probably did that already :-)

 

Dan

Link to post
Share on other sites

Thanks alot Dan, I had not even thought about using fiddler to see the response. Doing that allowed me to see the error... Apparently a simple thing like an image url not existing was enough to just barf the whole thing, and fiddler allowed me to see the more detailed error response and fix it.  So YEEA! I Got it working... Now to just figure out the far more complex task of all the other things I need to create a "real" json packet with alot more info in it with variations and things than this example had in it... but I was able to do a get request to return an existing record so I sorta have a template to go by of what everything is and what it should look like in the json data so it should be fairly straight forward now.

 

This was just the nudge I needed, thank you my friend:)

 

Hello.

 

Sending a application/json  http post request is definitively possible with http plugin. 

If the headers are set correctly and you use the correct consumer_secret, then I can't see why this should not work. 

 

You should definitely trace the http request with fiddler to see the full reply from the webserver. 

The response with ubot studio and http plugin is very limited. You don't see the full response there!

 

And you have to enable the API within the woocommerce plugin, but I think you probably did that already :-)

 

Dan

  • Like 1
Link to post
Share on other sites

Thanks alot Dan, I had not even thought about using fiddler to see the response. Doing that allowed me to see the error... Apparently a simple thing like an image url not existing was enough to just barf the whole thing, and fiddler allowed me to see the more detailed error response and fix it.  So YEEA! I Got it working... Now to just figure out the far more complex task of all the other things I need to create a "real" json packet with alot more info in it with variations and things than this example had in it... but I was able to do a get request to return an existing record so I sorta have a template to go by of what everything is and what it should look like in the json data so it should be fairly straight forward now.

 

This was just the nudge I needed, thank you my friend:)

 

Great! Anytime :-)

Link to post
Share on other sites
  • 1 month later...

Well, I had everything with this working fantastic on a site that happened to have an SSL cert... which made it much easier... but now I am simpy trying to overcome the oauth 1.0 stuff to be able to authenticate... with an https request it was simple matter of passing the woocommerce consumer key and secret in a url parameter... but I cant do that with my other sites that dont have ssl certs and I have to use oauth... But, I dont seem to be understand what this is saying or something, even though it seems to make sense...although very detailed, I think I understand it completely... but cant understand what could be wrong here...  Here's the docs.

http://woothemes.github.io/woocommerce-rest-api-docs/#authentication

the part under "Over HTTP" is what I am looking at... I have messed with this most of the day, and all I ever seem to get is a 401 error (looking at it in fiddler) that says "{"errors":[{"code":"woocommerce_api_authentication_error","message":"Invalid Signature - provided signature does not match"}]}"  

 

here's my code snippet

define teststuff {
    set(#thisrequesttype,"GET","Global")
    set(#thisrequestpart1,"{#thiswebsiteurl}/wc-api/v2/orders","Global")
    set(#req1encoded,$plugin function("URI Encode Decode.dll", "$uri encode", #thisrequestpart1, "decodeURIComponent"),"Global")
    set(#thisoauth_nonce,$random text(32),"Global")
    set(#thisoauth_timestamp,$plugin function("DateTime Manipulation.dll", "$datetime manipulation", $date, "UBOT", "UNIX", "en-US", "en-US"),"Global")
    set(#thisrequestpart2,"oauth_consumer_key={#wcapikey}&oauth_signature_method=HMAC-SHA1&oauth_timestamp={#thisoauth_timestamp}&oauth_nonce={#thisoauth_nonce}","Global")
    set(#req2encoded,$plugin function("URI Encode Decode.dll", "$uri encode", #thisrequestpart2, "decodeURIComponent"),"Global")
    set(#thisauthsigencoded,"{#thisrequesttype}&{#req1encoded}&{#req2encoded}","Global")
    set(#thisoauthsig,$plugin function("HMAC-SHA11.dll", "HMAC SHA1 base64 hex", #thisauthsigencoded, #wcapisecret),"Global")
    set(#thisrequest,"{#thisrequestpart1}?oauth_signature={#thisoauthsig}&{#thisrequestpart2}","Global")
    set(#oauthtestpost,$plugin function("HTTP post.dll", "$http get", #thisrequest, "", "", "", ""),"Global")
    load html(#oauthtestpost)
}

Any ideas?

Link to post
Share on other sites

Hello.

 

That's not easy to troubleshoot. The error could be in the string you create before signing, or in the signing (hash) itself. 
I didn't test it with "HMAC SHA1 base64 hex" so far. So I don't know if that creates the correct hash or not.

I would take a look at:

https://oauth.googlecode.com/svn/code/javascript/example/signature.html

 

You can use that to create a signature for your request. And then compare all the different values with the values you get from your code. 
That should give you some ideas on how this works and where the error might be.

 

Cheers

Dan

Link to post
Share on other sites

Hello.

 

That's not easy to troubleshoot. The error could be in the string you create before signing, or in the signing (hash) itself. 

I didn't test it with "HMAC SHA1 base64 hex" so far. So I don't know if that creates the correct hash or not.

 

I would take a look at:

https://oauth.googlecode.com/svn/code/javascript/example/signature.html

 

You can use that to create a signature for your request. And then compare all the different values with the values you get from your code. 

That should give you some ideas on how this works and where the error might be.

 

Cheers

Dan

Thanks for the reply dan... I am unable to click anything on the form you referenced... nothing seems to happen for me at all. I tried it in firefox and chrome both. Wierd...  I tried the HMAC SHA1 plugin without the base64 hex also and it did not work either. they referenced a link to a twitter api doc on being helpful with generating a signiture, and the one they showed there looked much closer to the HMAC SHA1 base64 hex one than the regular one... I really have no idea if maybe this is the issue, and might look into trying something else to create the hash, any suggestions?

Link to post
Share on other sites

if anyone wants to make a quick $50 by writing me a couple quicky defines like the one above (but actually works), with a GET example as well as a POST example, let me know asap. I am tired of screwing with this. PM me if you want to do it and I'll set you up with api keys and the url to the endpoint. I do need this to work with variables as I am looping through a list of sites and I'll be needing to generate lots of requests, so a define that I can simply pass in api keys and root url for the site and some params or whatever would be great. a simple snippet that can pull in the json for a list of orders, and another that can simply do something simple like update a status on an order will be all I need to get back to work.

 

Thanks

Link to post
Share on other sites

if anyone wants to make a quick $50 by writing me a couple quicky defines like the one above (but actually works), with a GET example as well as a POST example, let me know asap. I am tired of screwing with this. PM me if you want to do it and I'll set you up with api keys and the url to the endpoint. I do need this to work with variables as I am looping through a list of sites and I'll be needing to generate lots of requests, so a define that I can simply pass in api keys and root url for the site and some params or whatever would be great. a simple snippet that can pull in the json for a list of orders, and another that can simply do something simple like update a status on an order will be all I need to get back to work.

 

Thanks

Send me the details via PM please. I can take a look during the next days if that's ok.

 

Dan

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...