codeswholesale / codeswholesale-sdk-php

A PHP wrapper for CodesWholesale's API
Apache License 2.0
36 stars 21 forks source link

403 Forbidden #47

Open alisaleem252 opened 1 year ago

alisaleem252 commented 1 year ago

Getting Following ERROR. Client error: POST https://api.codeswholesale.com/oauth/token resulted in a 403 Forbidden response

<?php
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
    set_time_limit(0);

require_once '../vendor/autoload.php';
use CodesWholesale\ClientBuilder;
use CodesWholesale\CodesWholesale;
use CodesWholesale\Storage\TokenSessionStorage;

 $apiClientId = "MY VALID KEY";
        $apiClientSecret = "MY VALID SECRET";
        $params = [
            /**
             * API Keys
             * These are test api keys that can be used for testing your integration:
             */
             'cw.client_id' => $apiClientId,
             'cw.client_secret' => $apiClientSecret,
             /**
              * CodesWholesale ENDPOINT
              */
             'cw.endpoint_uri' => \CodesWholesale\CodesWholesale::LIVE_ENDPOINT,
             /**
              * Due to security reasons, you should use SessionStorage only while testing.
              * In order to go live, you should change it to database storage.
             */
             'cw.token_storage' => new \CodesWholesale\Storage\TokenSessionStorage()
         ];
 try {
         $clientBuilder = new ClientBuilder($params);
          $client = $clientBuilder->build();

            $products = $client->getProducts();
          }
             catch (\CodesWholesale\Resource\ResourceError $e) {
                  if ($e->isInvalidToken()) {
                    echo "if you are using SessionStorage refresh your session and try one more time.";
                }

                echo $e->getCode();
                echo $e->getErrorCode();
                echo $e->getMoreInfo();
                echo $e->getDeveloperMessage();
                echo $e->getMessage();

            } catch (Exception $exception) {
                echo $exception->getMessage();
            }