The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unable to create object using REST API

I am making two M-files REST api calls, one to /REST/files, and then I use the returned FileID to call /REST/objects.

My call to first endpoint returns a FileID which increments by 1 every time I call it, so I'm confident that's working.

The call to the objects endpoint returns this error:

The value "104-253878" does not exist, or it is a conflict object.

The second part of the return code is the mandatory metadata field for JobID. In our vault this maps to PropertyDef 1026, and changing this JobID to different numbers has no effect on the error. There are several other Documents in the Vault that have this number as their JobID.

This is what my JSON payload looks like:

{
    "PropertyValues": [
        {
            "PropertyDef": 0,
            "TypedValue": {
                "DataType": 1,
                "Value": "test999.txt"
            }
        },
        {
            "PropertyDef": 22,
            "TypedValue": {
                "DataType": 8,
                "Value": true
            }
        },
        {
            "PropertyDef": 100,
            "TypedValue": {
                "DataType": 9,
                "Lookup": {
                    "Item": 0,
                    "Version": -1
                }
            }
        },
        {
            "PropertyDef": 1026,
            "TypedValue": {
                "DataType": 10,                                
                "Lookups": [
                    {
                        "Item": "253878"
                    }
                ]                                                                        
            }
        },                  
    ],
    "Files": [
        {
            "UploadID": 72,
            "Size": 83,
            "FileInformationType": 0,
            "Title": "test999",
            "Extension": ".txt",
            "TempFilePath": ""
        }
    ]
}

I get the above error if I POST it to the /REST/objects endpoint ( same result in Postman or in code ). 

Has anyone had any luck getting this to work? I am all out of things to try! 

 

Parents
  • The general approach you have is correct.

    Does there definitely exist an object with internal ID 253878?  If you are using external objects then the internal ID can be harder to find: Internal and External IDs (m-files.com)

    Regards,

    Craig.

  • Thanks for the reply. I'm not really getting how metadata works in relation to lookups, that seems to be the issue. I removed the PropertyDef:1026 part of the JSON, and the file then gets created. Following that, I tried applying that metadata to the file / object after it's created. If I do that, I then get exactly the same error (the conflict object one ).

    I then tried dumping the lookups for the "Job Number" metadata field ( Property Def 1026 in Object data), which maps to

    REST/valuelists/104/items

    I could not find any occurrence of the Job Number I was using ( 253878 ), so I randomly chose one that was in the lookup list. I still got the "confilct object" error. I tried about three other Job Numbers in the list with the same request through Postman, the result was identical every time.

    So, to summarize the problem:

    1. The vault is configured with a mandatory "Job Number" metadata field

    2. Objects exist in the vault that have been assigned a Job Number value 253878

    3. If I search in M-files admin on 253878 I can find these objects

    4. I can create a new file via the REST API, but if I try to assign the Job Number 253878 to it via a REST API call, I get the error shown above in red. Changing the job number makes no difference if I repeat the API call.

    5. Once the file exists, I am able to enter 253878 in the Job Number property field, and save it ( and find the file in searches ). 

    6. I need to be able to add the Job Number either when the object ( or file ) gets created, or immediately after. 



     

  • Show me a picture of the metadata card of a job.

    When you create the object you need to provide it with the internal M-Files ID of the job to relate it to.  I suspect that you're providing it with the name.

  • If you see the text file "test9199.txt" in the list, that's one I created via the REST API. I was unable to assign the Job Number to that file via the REST API, but once I added it manually ( through the M-files admin screen )  I could see the file listed under the job with the other documents.

  • Okay.

    In the screenshot you posted, item "253878" has a display ID - hopefully an internal ID - of 90052.  You can see this ID on the metadata card at the top left.  It is this value that you must provide in your property:

    {
        "PropertyDef": 1026,
        "TypedValue": {
            "DataType": 10,                                
            "Lookups": [
                {
                    "Item": 90052
                }
            ]                                                                        
        }
    }

    If you still get an error then it's possible that the displayed ID is an external ID.  You can confirm by looking at the vault configuration using M-Files Admin.  There's also some more information here: https://developer.m-files.com/Getting-Started/Vault-Structure/InternalAndExternalIDs/.

    Regards,

    Craig.

  • Thanks  That was the trick! 

    What I ended up doing was making a REST API call to get the DisplayID from the lookup, then using that to create the new asset. I was also able to add the metadata values ( Job Id and Site ID ) at the same time. Long story short... it works now. Thanks again. :) 

Reply Children
No Data