Extra attributes JS API problem


(Talk) #1

Hi all, just tested a simple JS API createAsset function which works in 4.16-18 in Matrix 5.1.2 (eval)

 

The issue is that it does not set the comment [extra] attribute.

j.createAsset({
"parent_id":parent,
"type_code":"comment",
"asset_name":postName,

    “link_type”:2,
    “link_value”:“test”,
    “sort_order”:0,
    “is_dependent”:0,
    “is_exclusive”:0,
    “extra_attributes”:1,
    “attributes”:“comment=Testing 123”,
    “dataCallback”: function(data){
    console.log(data);
        }
    });

The comment attribute then does not appear on the details screen of the created asset in the backend until the locks are acquired - it can then be populated. The API asset is configured to create, and set extra attributes on create.

 

There is no trouble setting metadata on the created asset with the API, seems to just be a problem with the extra attributes variables.

 

OS: Mac OSX 10.9.4

Browsers Tested: Chrome, Safari, Firefox

Matrix version 5.1.2

 

Thanks :-)


(Nic Hubbard) #2

Did you try encoding that string so there are no spaces?


(Talk) #3

Hey Nic, I tested by wrapping encodeURIComponent() around the comment value today, and still no good. I'm suspecting a bug but I hope I'm wrong! The exact same js works in all versions of 4.x it's been run on, failing only to set the comment attribute on create in 5.1.

 

Thanks,

Jeremy Screen Shot 2014-09-25 at 9.48.19 am.png (9.67 KB) Screen Shot 2014-09-25 at 9.48.27 am.png (9.48 KB)


(Nic Hubbard) #4

And no errors?


(Talk) #5

Nothing at all. Error log is clear, and callback data is clean.


(Nic Hubbard) #6

If you have time, I would log out what data is actually getting to that PHP function to verify if it is even getting as far as Matrix.

 

Also, I would use a tool like Charles to look at your POST data to see if it is getting sent correctly.

 

Another thing to try is, I think you can actually just set a field for comment rather than sending it through the attributes:

j.createAsset({

“parent_id”:parent,
“type_code”:“comment”,
“asset_name”:postName,
    “link_type”:2,
    “link_value”:“test”,
    “sort_order”:0,
    “is_dependent”:0,
    “is_exclusive”:0,
    “extra_attributes”:1,
“comment”: “Testing 123”,
    “dataCallback”: function(data){
    console.log(data);
        }
    });


(Talk) #7

Hmmm, using the 'comment' field didn't work either. I'll get onto testing as per your advice.


(Talk) #8

HI again,

 

I've looked at the post data and there is a difference between 4.x and 5.1

 

Taken from Matrix 4.16 test:

key: XXXX
id: http://www.holmesglen.edu.au/_hoogle/content/posts/2014/9/25
type_code: comment
asset_name: 1411608144689
link_type: 2
link_value: post_folder
sort_order: 0
is_dependant: 0
is_exclusive: 0
extra_attributes: 1
comment: Test
type: createAsset
nonce_token: 8b6bbc52d941276ba733d2b085274024dc831dba

Taken from 5.1.2 test:

asset_name: 1411607926113
extra_attributes: "1&comment=Test"
id: "http://matrixdemo.squiz.net/_hoogle/content/posts/2014/9/25"
is_dependant: 0
is_exclusive: 0
link_type: 2
link_value: "post_folder"
nonce_token: "c2988e0dec039cce39db80b3a40d2d84b4dddb87
"sort_order: 0
type: "createAsset"
type_code: "comment"

Both tests run in Chrome. Both tests used an identical JS API call.


(Luke Wright) #9

Hi Jeremy,

 

Some under-the-hood changes in JS API for 5.1 might have broken how the extra attributes were sent (which to me appeared rather fragile to begin with).

 

It's been lodged as https://squizmap.squiz.net/matrix/6181.