Forums

PlayFab post not working

I have a function that sends a post to playfab which works perfectly on my hardware, but when I put run it on here, it raises a status code 400. Here is the code:

import requests
import json

def checkIfModding(id): 
    headers = {
        "X-SecretKey": Key,
        "Content-Type": "application/json"
    }
    payload = {
        "PlayFabId": id
    }

    try:
        response = requests.post(
            'https://'+TitleID+'.playfabapi.com/Server/GetUserInventory',
            headers=headers,
            json=payload
        )

        if response.status_code != 200:
            raise Exception(f"Failed to fetch inventory, status code: {response.status_code}")

        response_data = response.json()

        if 'data' not in response_data:
            raise KeyError("'data' key not found in the response")

        items = response_data['data'].get('Inventory', [])

        for item in items:
            if item.get('ItemId') == "Admin":
                return False
        return True

    except requests.RequestException as e:
       raise Exception(f"Request failed: {str(e)}")
    except json.JSONDecodeError as e:
        raise Exception(f"Error decoding JSON response: {str(e)}")

print(checkIfModding("839A38007CC74D72"))

Check what you are actually sending to the endpoint and make sure that it is correct for what the service you're accessing requires. There may also be clues in the content of the response.