Search code examples
phpmime-typestrufflenft

API gives 406 code with Accept application/json request : Bluehost


This is the result I get when I try to validate my API.

Content-Type: application/json
Vary: Accept

{
    "valid": false,
    "token_uri": "https://mining4btc.com/NFT/rinkeby/CKE/1",
    "errors": [
        "InvalidTokenUrlResponseException: Invalid response, expected 200 but got 406 for URL: https://mining4btc.com/NFT/rinkeby/CKE/1"
    ]
}

I'm using this to validate my API: https://testnets-api.opensea.io/asset/0xe8dD349E3B0F0FA0eE063a2D99541155aFEf14B9/1/validate/

As you can see, it's getting a 406 code.

This is the API:

<?php
header('Content-Type: application/json');

$output = '{
  "attributes": [
    {
      "trait_type": "Eyes", 
      "value": "cute"
    }, 
    {
      "trait_type": "Nose", 
      "value": "cute"
    }, 
    {
      "trait_type": "Cheeks", 
      "value": "cute"
    }, 
    {
      "trait_type": "Toes", 
      "value": "cute"
    }, 
    {
      "trait_type": "Ability", 
      "value": "chairs"
    }, 
    {
      "display_type": "boost_number", 
      "trait_type": "Cuteness", 
      "value": 5000
    }, 
    {
      "display_type": "number", 
      "trait_type": "Age", 
      "value": 1
    }
  ], 
  "description": "Thinking about my Mommy.", 
  "external_url": "https://mining4btc.com/NFT/rinkeby/CKE/external", 
  "image": "https://mining4btc.com/NFT/rinkeby/CKE/proof/1.jpg", 
  "name": "Chillin"
}';

$decoded = json_decode($output);
echo json_encode($decoded);

?>

This is a contract API for a NFT following the OpenSea documents; deployed with Truffle to rinkeby.


Solution

  • I have confirmed that this is because Bluehost actively blocks (by returning this code) requests with Accept:application/json headers. You have to contact Bluehost and ask them to whitelist the IP addresses that you want to be able to access the metadata.

    As far as I can tell, they do this because they want to push people to pay for a VPS, because they are assuming this kind of request would go to some kind of robust API that requires significant backend processing.