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
  • Sorry for the late answer:


    The headers look like this: 

    mfiles_headers = {
          'Content-Type': 'application/json',
          'X-Username': config.get("mfiles.username"),
          'X-Password': config.get("mfiles.password"),
          'X-Vault': config.get("mfiles.vault_id")
          }
    When I use the headers for the requests everything works fine. 

    The request contains a simple json body like this:

    json_body={
            "PropertyDef": interface_id_property_def,
                        "TypedValue": {
                            "DataType": 1,
                            "Value": interface_id
                        }
        }

    I'm save the token like this: token = result.get("Value")

Children