Jump to content

Send URL call via PHP script to database for add new record.


Zdeněk Tůma

Recommended Posts

Posted

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.

Posted

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!

Posted
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]).

Posted

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.

Posted

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.

Posted
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.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...