APIs & Integrations

Compounder
Participant

FileManager API: curl_exec displays objects

SOLVE

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:

 

Bildschirmfoto 2022-03-08 um 17.17.52.png

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.

0 Upvotes
1 Accepted solution
RMones
Solution
Contributor | Platinum Partner
Contributor | Platinum Partner

FileManager API: curl_exec displays objects

SOLVE

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

View solution in original post

3 Replies 3
RMones
Solution
Contributor | Platinum Partner
Contributor | Platinum Partner

FileManager API: curl_exec displays objects

SOLVE

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

Compounder
Participant

FileManager API: curl_exec displays objects

SOLVE

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!

dennisedson
HubSpot Product Team
HubSpot Product Team

FileManager API: curl_exec displays objects

SOLVE

@RMones , curious if you have had a similar issue 👀