I get a 403 error when I use the pricehubble api

81 Views Asked by At

I work with the priceHubble api. When I make a request I get a 403 error with the following result:

{
    "message": "Forbidden"
}

Here's my php code: (address taken at random in France)

 $accessToken = "#######";

    // Making the PriceHubble API request for property valuation
    $apiUrl = 'https://api.pricehubble.com/api/v1/valuation/property_value_light';
    $requestData = [
    'dealType' => 'rent',
    'property' => [
        'location' => [
            'address' => [
                'city' => 'Le Mans',
                'houseNumber' => '11B',
                'postCode' => '72000',
                'street' => 'Rue Dubignon'
            ]
        ],
        'propertyType' => [
            'code' => 'house'
        ],
        'buildingYear' => 2000,
        'livingArea' => 200.00,
        'landArea' => 100.00,
        'condition' => 'well_maintained'
    ],
    'countryCode' => 'FR'
];

    $chApi = curl_init($apiUrl);
    curl_setopt($chApi, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($chApi, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($chApi, CURLOPT_POSTFIELDS, json_encode($requestData));
    curl_setopt($chApi, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $accessToken
    ]);

    $apiResponse = curl_exec($chApi);

    if (curl_errno($chApi)) {
        echo 'API Request Error: ' . curl_error($chApi);
    } else {
      $httpCode = curl_getinfo($chApi, CURLINFO_HTTP_CODE);
      if ($httpCode === 403) {
      //I'm stuck here
      echo '403 Forbidden';
      } else {
        $responseData = json_decode($apiResponse, true);
        echo 'API Response: ';
        print_r($responseData);
      }
    }

    curl_close($chApi);

Here is the link to the documentation: https://docs.pricehubble.com/international/valuation_light/

0

There are 0 best solutions below