FileManager API: curl_exec displays objects

Hey guys!

I just ran into the following problem: I am using the FileManager API in order to upload documents which ultimately will be connected to a contact (https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file). For this, I am using PHP 7.4, following precisely the instructions given in the above-mentioned page. For whatever reason, the $response = @curl_exec($ch); leads to the object being displayed on the screen, instead of being stored in the variable:

Hence, I cannot json_decode the response and also not use the information at all; in the end, I just require the friendly URL to attach it to contact.

Does anybody know why this is the case? As far as I know, it worked fine beforehand (I used the same code some time last year). Thank you very much in advance for your help!

All the best,

Mino.

@RMones , curious if you have had a similar issue :eyes:

Hi @dennisedson and @Compounder ,

There is a paramter missing in the example for getting the data in the variable instead of the stdout..

CURLOPT_RETURNTRANSFER
true to return the transfer as a string of the return value of curl_exec() instead of outputting it directly.
So if you add the following line:

@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

after

@curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

The data will be passed to the variable!
Good luck.

Regards Ronald

Oh my, could have found that on my own when just scrolling down within my own script, where I am doing the cURL for the ContactAPI :grinning_face_with_smiling_eyes: cheers, Ronald!