Zdeněk Tůma Posted January 15, 2020 Share Posted January 15, 2020 Hello, I now solving one problem with Database. I REALLY need database where I can adding new records via php script. But I have only Cloud platform so it is not possible via directly in Mysql. So I thought it would be possible via calling URL with data to database form for add new record. It is possible? I REALLY NEED THIS 😞 Example: <?php //The url you wish to send the POST request to $url = databse form url; //The data you want to send via POST $fields = [ '__VIEWSTATE ' => $state, '__EVENTVALIDATION' => $valid, 'btnSubmit' => 'Submit' ]; //url-ify the data for the POST $fields_string = http_build_query($fields); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, true); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); curl_exec($ch); curl_close($ch); ?> But need help with setup data-values for database form. Link to comment Share on other sites More sharing options...
Ryan Ashbrook Posted January 15, 2020 Share Posted January 15, 2020 You can use the REST API. https://invisioncommunity.com/developers/rest-api https://invisioncommunity.com/developers/rest-api?endpoint=cms/records/POSTindex Link to comment Share on other sites More sharing options...
Zdeněk Tůma Posted January 15, 2020 Author Share Posted January 15, 2020 Thank you, I want to ask is this correct? $communityUrl = 'https://www.example.com/'; $apiKey = 'hidden'; $endpoint = '/cms/records/5'; $fields = [ 'author ' => 1, 'fields' => [ 'Title' => 'record name', 'Content' => 'record content', 'my_custom_field1' => 'field value', 'my_custom_field2' => 'field value', 'my_custom_field3' => 'field value', 'my_custom_field4' => 'field value' ], 'date' => '2019-12-31', 'locked ' => 0, 'hidden ' => 0, 'pinned ' => 0, 'featured ' => 0 ]; $fields_string = http_build_query($fields); $curl = curl_init( $communityUrl . 'api' . $endpoint ); curl_setopt_array( $curl, array( CURLOPT_POST => true, CURLOPT_POSTFIELDS => $fields_string, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => "{$apiKey}:" ) ); $response = curl_exec( $curl ); EDIT: its working but idk how to add content and custom fields 😞 EDIT: 'fields' => [ '19' => 'record name', '20' => 'record content' ], done i must get ID fields via download database. better will be can see IDs in Admin ACP but thanks for help! Link to comment Share on other sites More sharing options...
bfarber Posted January 16, 2020 Share Posted January 16, 2020 19 hours ago, Zdeněk Tůma said: Thank you, I want to ask is this correct? $communityUrl = 'https://www.example.com/'; $apiKey = 'hidden'; $endpoint = '/cms/records/5'; $fields = [ 'author ' => 1, 'fields' => [ 'Title' => 'record name', 'Content' => 'record content', 'my_custom_field1' => 'field value', 'my_custom_field2' => 'field value', 'my_custom_field3' => 'field value', 'my_custom_field4' => 'field value' ], 'date' => '2019-12-31', 'locked ' => 0, 'hidden ' => 0, 'pinned ' => 0, 'featured ' => 0 ]; $fields_string = http_build_query($fields); $curl = curl_init( $communityUrl . 'api' . $endpoint ); curl_setopt_array( $curl, array( CURLOPT_POST => true, CURLOPT_POSTFIELDS => $fields_string, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => "{$apiKey}:" ) ); $response = curl_exec( $curl ); EDIT: its working but idk how to add content and custom fields 😞 EDIT: 'fields' => [ '19' => 'record name', '20' => 'record content' ], done i must get ID fields via download database. better will be can see IDs in Admin ACP but thanks for help! You can obtain the ids by mousing over the links in the list of fields (i.e. if you mouse over the link to edit a field, you'll see &do=form&id=[x]). Link to comment Share on other sites More sharing options...
Zdeněk Tůma Posted January 16, 2020 Author Share Posted January 16, 2020 Can I sending to API call strings with escape characters or I must frst string escaped? Link to comment Share on other sites More sharing options...
bfarber Posted January 17, 2020 Share Posted January 17, 2020 I'm afraid I'm unclear what you are asking. If you are asking if you have to manually escape the data you are sending the answer is no, we will escape anything that needs to be escaped. Link to comment Share on other sites More sharing options...
Zdeněk Tůma Posted January 20, 2020 Author Share Posted January 20, 2020 One question is possible add via API to record field 'Meta Keywords'? I now using tags becouse this have same effect (adding meta keywords in <head>) but then the records are displayed in related content and I don't want that. Is possible this? Or how remove listing database records from related content. And another one question why don't have Invoices POST method in REST API for edit invoice. I have custom payment methods and the payment is checked via third-party script and if script check payment as paid so I need send CURL request to IPB site for mark invoice as Paid. Link to comment Share on other sites More sharing options...
bfarber Posted January 20, 2020 Share Posted January 20, 2020 12 hours ago, Zdeněk Tůma said: One question is possible add via API to record field 'Meta Keywords'? I now using tags becouse this have same effect (adding meta keywords in <head>) but then the records are displayed in related content and I don't want that. Is possible this? Or how remove listing database records from related content. I'm afraid not. 12 hours ago, Zdeněk Tůma said: And another one question why don't have Invoices POST method in REST API for edit invoice. I have custom payment methods and the payment is checked via third-party script and if script check payment as paid so I need send CURL request to IPB site for mark invoice as Paid. I would have to assume it simply hasn't come up. We tend to focus on REST API changes we receive the most requests for. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.