Jump to content

Update an Order from Woocommerce using fetchRemote


MADD NØG

Recommended Posts

I'm managing to query values normally, but I can't change values, I'm trying something like this, I know it's possible, but I don't understand how to send information with fetchRemote

local apiKey = "..." 
local forumAddress = "..."

function testing(orderID, content)
  local sendOptions = {
    connectionAttempts = 5,
    connectTimeout = 7000,
	method = post
    headers = {
		["Content-Type"] = "application/json",
		-- i try this
		{
			"status": "completed"
		  }
		--
	},
  }
  fetchRemote( forumAddress.."/wp-json/wc/v3/"..postID.."?key="..apiKey, sendOptions, function()end)
end

 

Here how Woo API updates data with postman for example

 

curl -X PUT https://example.com/wp-json/wc/v3/orders/727 \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "status": "completed"
}'

I'm managing to query data from my database, but I don't understand how I can send this update in json to change the order data, I currently use change via MySQL, but I'm trying to migrate 100% to the API

Link to comment

u need to include the data you want to send as the third argument to the fetchRemote, also the method should be in string

local apiKey = "..."
local forumAddress = "..."

function testing(orderID, content)
    local sendOptions = {
        connectionAttempts = 5,
        connectTimeout = 7000,
        method = "POST",
        headers = {
            ["Content-Type"] = "application/json",
        },
    }

    local postData = toJSON({
        status = "completed",
    })

    fetchRemote(forumAddress.."/wp-json/wc/v3/orders/"..orderID.."?key="..apiKey, sendOptions, function(responseData, error)
        if error == 0 then
            outputChatBox("success" .. responseData)
        else
            outputChatBox("failed, " .. error)
        end
    end, postData)
end

 

  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...