NCR counterpoint Create Product API End Point

NCR counterpoint Create Product API End Point

// Replace with your API endpoint URL and authentication credentials
$api_url = 'https://api.counterpoint.com/v1/products';
$username = 'your_username';
$password = 'your_password';

// Set up cURL to make the API request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, “$username:$password”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Make the API request and capture the response
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

// Check for errors and handle response
if ($http_status == 200) {
// Success! Parse the JSON response into a PHP array
$products = json_decode($response, true);
// Do something with the $products array here…
} else {
// There was an error. Handle it here…
echo “Error accessing API: HTTP status code $http_status”;
}

This code assumes that you’ve already obtained your API endpoint URL and authentication credentials from NCR Counterpoint. Replace the $api_url, $username, and $password variables with your own values.

The curl_setopt() function is used to set various options for the cURL request, such as the endpoint URL, authentication credentials, and whether to return the response as a string (CURLOPT_RETURNTRANSFER).

After making the API request with curl_exec(), the HTTP status code of the response is checked using curl_getinfo(). If the status code is 200 (indicating a successful response), the JSON response is parsed into a PHP array using json_decode(). You can then do whatever you need to do with the $products array.

If the HTTP status code is anything other than 200, an error message is displayed. You’ll need to handle errors in a more appropriate way for your specific use case.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments