I got this below code from a wocoommerce rest API where it says that a product can be added from curl so after lot of research i have enabled the Curl in my PHP and tested a code which says the curl is enabled on my Machine But i have zero clue how to run the below API code in
Curl Test code:
<?php
// Script to test if the CURL extension is installed on this server
// Define function to test
function _is_curl_installed() {
if (in_array ('curl', get_loaded_extensions())) {
return true;
}
else {
return false;
}
}
// Ouput text to user based on test
if (_is_curl_installed()) {
echo "cURL is <span style=\"color:blue\">installed</span> on this server";
} else {
echo "cURL is NOT <span style=\"color:red\">installed</span> on this server";
}
?>
Api Found that uploads the Products to the store
curl -X POST https://example.com/wc-api/v3/products \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"product": {
"title": "Premium Quality",
"type": "simple",
"regular_price": "21.99",
"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": [
9,
14
],
"images": [
{
"src": "http://example.com/wp-content/uploads/2015/01/premium-quality-front.jpg",
"position": 0
},
{
"src": "http://example.com/wp-content/uploads/2015/01/premium-quality-back.jpg",
"position": 1
}
]
}
}'
you can run curl by using the following code
Firstly you'll need to create a PHP array that can be encoded to that JSON string
Then use json_encode to convert it to JSON
Then use the following PHP code