Mar 8, 2022 11:19 AM
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.
Solved! Go to Solution.
Mar 9, 2022 2:05 PM
Hi @dennisedson and @Compounder ,
There is a paramter missing in the example for getting the data in the variable instead of the stdout..
https://www.php.net/manual/en/function.curl-setopt.php
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
Mar 9, 2022 2:05 PM
Hi @dennisedson and @Compounder ,
There is a paramter missing in the example for getting the data in the variable instead of the stdout..
https://www.php.net/manual/en/function.curl-setopt.php
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
Mar 10, 2022 3:28 AM
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 😄 cheers, Ronald!
Mar 9, 2022 11:29 AM
@RMones , curious if you have had a similar issue 👀