Create product using REST API programmatically in magento 2.

For Access Magento 2 REST API, you need to first generate an access token. Access token used for synchronization with Magento to other third-party platforms. Check the link for Generate Access Token Magento 2

Once you got the Access Token for Magento, You can call REST API for creating a product from a third-party system.

You can create a simple product from a third party platform by just calling Magento REST API without touching the Magento backend.

You can programmatically create a simple product by just below code,

Action Type: POST

Request URL:  <YOUR_SITE_URL>/rest/V1/products

Header:  For Header, You need to pass an array for headers,
‘Content-Type:application/json’,’Authorization:Bearer ‘.$accessToken’

Where $accessToken is your site Access Token.

<?php
$url = "http://127.0.0.1/magento2/index.php/rest";
$token_url= $url."/V1/integration/admin/token";

$username= "admin";
$password= "admin123";

//Authentication REST API magento 2,    
$ch = curl_init();
$data = array("username" => $username, "password" => $password);
$data_string = json_encode($data);

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json'
    ));
$token = curl_exec($ch);
$adminToken=  json_decode($token);
$headers = array('Content-Type:application/json','Authorization:Bearer '.$adminToken);

// Createt Product REST API URL
$apiUrl = $url."/V1/products";

$ch = curl_init();
$data = [
    "product" => [
        "sku" => "Test Product 1",
        "name" => "Test Product 1",
        "attribute_set_id" => 4,
        "price" => 99,
        "status" => 1,
        "visibility" => 2,
        "type_id" => "simple",
        "weight" => "1",
        "extension_attributes" => [
            "category_links" => [
                [
                    "position" => 0,
                    "category_id" => "5"
                ],
                [
                    "position" => 1,
                    "category_id" => "7"
                ]
            ],
            "stock_item" => [
                "qty" => "1000",
                "is_in_stock" => true
            ]
        ],
        "custom_attributes" => [
            [
                "attribute_code" => "description",
                "value" => "Description of product here"
            ],
            [
                "attribute_code" => "short_description",
                "value" => "short description of product"
            ]
        ]
    ]
];
$data_string = json_encode($data);

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);

$response = json_decode($response, TRUE);
curl_close($ch);

In the above Request, We have created a simple product in Magento 2, Pass the required data to create a simple product.  Using the above data, We can create a simple product with name equals to Test Product 1.

You can set price, SKU, visibility, weight, type_id, status, and all the other attribute and custom field using REST API.

When Run above script code, You can create a simple product in Magento 2 successfully.