Jump to content

Featured Replies

Posted

Troubleshooting a script to create records and running into an exception.

 

Calling via API:

POST /cms/records/{database_id}

Returns: 

{'errorCode': '1S306/E', 'errorMessage': 'UPLOAD_FIELD_NOT_OBJECT'}

 

Does this error apply to the image object (Record Image)?

I only have one other multi-image upload field in the fields object that is optional and I'm not sending it in the POST request at all for my test, so I'm assuming this error is being returned from the image field, but want to confirm before I go down a rabbit hole. 

P.S.  My script is written in Python, not PHP.

Solved by Clover13

Go to solution
  • Author

Well now I'm baffled.  I set up a simple Pages DB locally with just a title and content and submitted an API POST to create a record.  It did create it but with odd results.

You can see the request has the field ids and values.  Yet in the response, field_12 (the Title field) shows "o", as does the "title" key's value.  Not sure what's going on there, but will keep digging.

 

POST /cms/records/3/

REQUEST DATA
{
    "\/cms\/records\/3\/": "",
    "key": "xxxxxxxxxx",
    "category": "5",
    "author": "1",
    "fields": "{\"12\": \"Hello Title\", \"13\": \"Hello Content\"}"
}
RESPONSE
{
    "id": 2,
    "title": "o",
    "category": {
        "id": 5,
        "name": "Records",
        "url": "",
        "class": "IPS\\cms\\Categories3",
        "parentId": 0,
        "permissions": {
            "perm_id": 97,
            "perm_view": "*",
            "perm_2": "*",
            "perm_3": "4,3,6",
            "perm_4": "4,3,6",
            "perm_5": "4,3,6",
            "perm_6": "4,3,6",
            "perm_7": "4,3,6"
        }
    },
    "fields": {
        "field_12": "o",
        "field_13": " "
    },
...
...
...

 

  • Author
  • Solution

I figured it out now.

Successful POST

{
    "\/cms\/records\/3\/": "",
    "key": "xxxxxxx",
    "category": "5",
    "author": "1",
    "fields": {
        "12": "Hello",
        "13": "Content"
    }
}
RESPONSE
{
    "id": 11,
    "title": "Hello",
    "category": {
        "id": 5,
        "name": "Records",
        "url": "",
        "class": "IPS\\cms\\Categories3",
        "parentId": 0,
        "permissions": {
            "perm_id": 97,
            "perm_view": "*",
            "perm_2": "*",
            "perm_3": "4,3,6",
            "perm_4": "4,3,6",
            "perm_5": "4,3,6",
            "perm_6": "4,3,6",
            "perm_7": "4,3,6"
        }
    },
    "fields": {
        "field_12": "Hello",
        "field_13": "Content"
    },

 

Python code in terms of post data:

post_data = {
	"category": "5",
	"author": "1",
	"fields[12]": "Hello",
	"fields[13]": "Content",
}

 

I was creating a dict for fields as follows that was failing, as it wasn't in the expected format:

fields = {
	"12": "Hello",
	"13": "Content"
}

And then dumping it to JSON as an object and POSTing as

post_data = {
	"category": "5",
	"author": "1",
	"fields": fields_json,
}

 

  • Author

Alright, another issue discovered is even though I have the Content field marked as optional (this is intentional based on my DB and templating design goals as no one field is the content), it is still required in the POST otherwise you'll get a TITLE_CONTENT_REQUIRED exception.  So I had to add the Content field to the request, which I can default to an empty string and hide from all member groups, then it works.

Now back to the original troubleshooting of whatever it is deeming as an upload field.

  • Author

Alright all good now once I set all the params correctly.

Final one for image was just the image[name] and image[contents] as base64 encoded contents as the docs state.

 

Recently Browsing 0

  • No registered users viewing this page.