Set Custom Metadata on Upload API2

I’ve created a new Custom Field (ingredients) and am trying to populate it with data on my initial asset upload using Upload API2. I have successfully set other metadata fields (meta_file_name, meta_description, etc) but cannot figure out how to get my data to go into my custom field. I’ve tried meta_ingredients, ingredients, and even the long field ID, with no success.

Since this is a custom field, you need to set it with the custom field ID.
See for bulk updating
http://wiki.razuna.com/display/ecp/Custom+Fields+API2#CustomFieldsAPI2-Setcustomfieldvalueinbulk
or single file update
http://wiki.razuna.com/display/ecp/Custom+Fields+API2#CustomFieldsAPI2-Setcustomfieldvalue

That documentation looks like it is for updating existing assets. Does this mean I have to run the curl upload, then run a REST request after the upload on the newly uploaded asset? I apologize if I’m missing how do this all in one curl command.

Thanks for the reply!

On the assumption that the Custom Fields update has to happen after I get the Upload response back, I’ve been trying to get this to work. Here is my URL variable ({values} are obviously replaced with real values):

$meta_upd_url = 'http://{mysubdomain}.razuna.com/global/api2/customfield.cfc?method=setfieldvaluebulk&api_key={myapikeyhere}&field_values=[["{assetidfromupload}",[["{customfieldID1}","Custom Value 1"],["{customfieldID2","Custom Value 2"]]]]';
echo( "$meta_upd_url\n" );

I’ve tried two different approaches:

PHP/cURL:

// Get cURL resource
$meta_upd = curl_init( $meta_upd_url );
curl_setopt( $meta_upd, CURLOPT_RETURNTRANSFER, true );

// Send the request & save response to $meta_upd_resp
$meta_upd_resp = curl_exec( $meta_upd );
print_r( $meta_upd_resp );

PHP/file_get_contents:

$meta_upd_resp = file_get_contents( $meta_upd_url );
print_r( $meta_upd_resp );

Both get responses of:

{"responsecode":0,"message":"Custom field values successfully added"}

However, the Custom Fields don’t update on our hosted site.

Now when I copy my $meta_upd_resp variable and paste it into my web browser, I get the same response but the Custom Fields DO update… so confused.

I tried adding a 5 second pause in between the Upload and Update calls thinking there was some rate limitation but that didn’t help.

Since they are the same call int he browser and in the cmd, I believe this is an issue on your end.

Maybe try a POST instead of a GET? Also, try the single update first to see if that works.

I switched to a curl call using POST:

// Get cURL resource
$meta_upd = curl_init();

curl_setopt_array( $meta_upd, array(
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_HTTPHEADER => array( 'Expect: ' ),
	CURLOPT_URL => 'http://{mysite}.razuna.com/global/api2/customfield.cfc',
	CURLOPT_POST => 1,
	CURLOPT_POSTFIELDS => array(
		api_key => '{my_api_key}',
		method => "setfieldvaluebulk",
		field_values => '{custom_data_array}'
	)
));

// Send the request & save response to $meta_upd_resp
$meta_upd_resp = curl_exec( $meta_upd );

And that works.

So now that I am going through setting custom field data, I’ve not found what value the Radio Button Yes/No fields want. I’ve tried Yes/No, On/Off, 1/0 - they are not setting a default value when I check my asset after the update. Text fields are updating correctly.

Thanks!

Pass it as a string and the value has to be “T” (true) or “F” (false).

Got it, thanks! Sorry if I missed that in the documentation. If it’s not there tho, it should be.