REST API: 403 Client Error: Forbidden for url after Create Request using Token

Hello Guys, 

I'm trying to use the M-Files REST API in my Python application. I was able to login and received a token.

After that I'm trying to create new objects in my Vault. This is the JSON-body contained in my request:

json_body = {
            "PropertyValues": [
                {
                    "PropertyDef": config.get("mfiles.properties.class_property_def"),
                    "TypedValue": {
                        "DataType": 9,
                        "Value": "null",
                        "Lookup": {
                            "Deleted": "false",
                            "DisplayValue": "null",
                            "Hidden": "false",
                            "Item": config.get(f"mfiles.classes.process_class_id"),
                            "Version": -1
                        },
                    }
                },
                {
                    "PropertyDef": config.get("mfiles.properties.customer_property_def"),
                    "TypedValue": {
                        "DataType": 9,
                        "Value": "null",
                        "Lookup": {
                            "Deleted": "false",
                            "DisplayValue": "null",
                            "Hidden": "false",
                            "Item": config.get(f"mfiles.property_values.customer_value_id"),
                            "Version": -1
                        },
                    }
                },
                {
                    "PropertyDef": config.get("mfiles.properties.interface_id_property_def"),
                    "TypedValue": {
                        "DataType": 1,
                        "Value": measuring_point['idnr']
                    }
                },
                {
                    "PropertyDef": config.get("mfiles.properties.energy_type_property_def"),
                    "TypedValue": {
                        "DataType": 9,
                        "Value": "null",
                        "Lookup": {
                            "Deleted": "false",
                            "DisplayValue": "null",
                            "Hidden": "false",
                            "Item": config.get(f"mfiles.property_values.energy_type_{medium}_value_id"),
                            "Version": -1
                        },
                    }
                },
                {
                    "PropertyDef": config.get("mfiles.properties.interface_property_def"),
                    "TypedValue": {
                        "DataType": 9,
                        "Value": "null",
                        "Value": "null",
                        "Lookup": {
                            "Deleted": "false",
                            "DisplayValue": "null",
                            "Hidden": "false",
                            "Item": config.get(f"mfiles.property_values.interface_enportal_value_id"),
                            "Version": -1
                        },
                    }
                },
                {
                    "PropertyDef": config.get("mfiles.properties.marklokation_property_def"),
                    "TypedValue": {
                        "DataType": 1,
                        "Value": measuring_point['marktlokation']
                    }
                }
            ]
        }

I send the request with 
"X-Authentication": token as the header to my.m-files/.../159.aspx. The 159 represents a real objecttype in my vault.

Then I receive the following response: requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://my.m-files/REST/objects/159.aspx

I don't really understand what's missing or what the issue is. As far is I understand there is an issue with the token that I passed to the new request. Also maybe my request body is not sufficent enough... I can also provide more source code if needed.

Help would be really appreciated. Note: This is my first time working with the REST API

Kind regards,
Danijel
Parents Reply
  • Here is the actual content of the authentication request:

    postman request POST 'ecb.enerprice.ch/.../authenticationtokens.aspx' \
    --header 'Content-Type: application/json' \
    --header 'Cookie: ASP.NET_SessionId=gnqbp50l2zpu0dhnzpf4z5wd; token=ag7bf6XOdtr9zE9_kgY_0WsijVgjNXGqD60Bt4wkgtt7bD3ZqbNx2dHuu1IegJqXdxknBx-gBf-_nhKpaelrMLoZzuIgcXcUT5p_WQNfIWIjyA402QnqwK0iDa0ZiSp3JW5JhRCi3tIt7jkZzh2uvHmR552EDccwZPbWZZzZtak6jW88nPOEUZK5-WrEopZz5hLDcZxdOHG-V8cKi8Xrn6GiXyBTC6vuO3C4EPkW2dqiYWD2rJcHQOQF6OhBfhgU-4TS3s-NaXt-UBk0RrSeEa454GMvnVmmA6SlwT4uAsMmWMiDejKCRyBJmAqn-b9PefevFh9JATiokJS-5Gi1zw' \
    --body '{
    "Username": "myUser",
    "Password": "myPassword",
    "VaultGuid": "{216DA69D-4595-408E-AD27-E98EDD13759A}"
    }'

Children