Skip to Content Skip to Menu

403 Error when trying to save php code in auto action

  • timstohr
  • timstohr
  • OFFLINE
  • Posts: 1091
  • Thanks: 56
  • Karma: 9
7 years 1 month ago #296903 by timstohr
Hi Kyle,

we have the following problem. When we try to save some php code which executes a curl request, the interface fails to save the code when we include the "Content-Type: application/json" Header.
Code:
$ch = curl_init(); $post_data = json_encode(array( "title"=>"Title", "body"=>"Body", )); curl_setopt($ch, CURLOPT_URL, "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Origin: http://xx.xxx.x.xxx:yyyy', 'Accept-Encoding: gzip, deflate', 'Accept-Language: en-US,en;q=0.8', 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', 'Content-Type: application/json', 'Accept: application/json, text/plain, */*', 'Referer: http://xx.xxx.x.xxx:yyyy/', 'Connection: keep-alive', 'Dnt: 1'); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close ($ch);

More specifically, we get a 403 error saying "You are not authorized to view this page".

Any ideas?

Thanks in advance.

Tim

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
7 years 1 month ago - 7 years 1 month ago #296905 by krileon
The PHP method for a Code action is for simple code operations (think 1 to 10 lines of code). Not for creating full usages like that. It has to store the code and to do that it's ran through json_encode and stored to the params. For complex usages it probably won't save right as some code just doesn't encode well. Your best option in those cases is just create a PHP file and include that file in your code action for a much cleaner usage. The include won't have access to substitutions, but will have access to all defined variables so you could define a variable that's a substitution value and your include will be able to use it. There's also a Request action for sending HTTP requests.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
Last edit: 7 years 1 month ago by krileon.

Please Log in or Create an account to join the conversation.

  • timstohr
  • timstohr
  • OFFLINE
  • Posts: 1091
  • Thanks: 56
  • Karma: 9
7 years 1 month ago #296909 by timstohr
Ah yes, that solution with the substitution and defining the variables and then putting them into the include file would be the best I think. Also gives me a nice way to structure it if we have something like a hundred different push.
However, what do you mean with HTTP Requests in CODE action? or do you mean that Auto Actions can initiate HTTP requests directly? If so how do we do it?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48444
  • Thanks: 8279
  • Karma: 1443
7 years 1 month ago #296929 by krileon

However, what do you mean with HTTP Requests in CODE action? or do you mean that Auto Actions can initiate HTTP requests directly? If so how do we do it?

There's a Request action specifically for sending HTTP requests. You don't need a code action for that. Simply select Request as the Type for the auto action.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum