I am using the sample code from -> https://gbshouse.uservoice.com/knowledgebase/articles/109834-rage4-dns-developers-api#create_regular_domain to create a basic domain in the Rage4 system for the very first time via API.
But following the call I get a NULL value returned.
I double checked my username and pass/api key and it is verified good.
I don't get any log errors in the rage4 system though.
code used:
<?php
$name = 'testdom4.com';
$email = 'admin#testdom4.com';
$username = 'user#testdom4.com';
$password = '4444444444444444444a1e42a';
$ch = curl_init("https://secure.rage4.com/RAPI/CreateRegularDomain/?name=" . $name . "&email=" . $email);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
$result = curl_exec($ch);
var_dump(json_decode($result, true));
?>
Did I miss something in the backend to initialize?
How do I create a basic domain via api in the rage4 system?
Related
I am working on a MemberMouse subscription Wordpress website. After a User signs up via a webform for a membership, I want to call a script that adds the User to a Mailchimp mailing list WITH a double opt-in. Membermouse offers an integration via Mailchimp, however only with a single opt-in. Therefore, due to government law, I am required to use a double opt-in.
I wrote the following script, that should be called under the condition that once the member is added it sends the following php sript:
<?php
require_once("wp-load.php");
require_once("wp-content/plugins/membermouse/includes/mm-constants.php");
require_once("wp-content/plugins/membermouse/includes/init.php");
// Your Membermouse API URL
$apiUrl = "MYDOMAIN/wp-content/plugins/membermouse/api/request.php";
// Your API key
$apiKey = "my API key";
// Your API secret
$apiSecret = "my API secret";
// ---- GET EVENT TYPE ----
if(!isset($_GET["mm_member_add"]))
{
// event type was not found, so exit
exit;
}
// ---- ACCESS DATA ----
// member data
$username = $_GET["username"];
$email = $_GET["email"];
$apiKey1 = 'my Mailchimp API key';
$listID1 = 'my Mailchimp list ID';
// MailChimp API URL
$memberID1 = md5(strtolower($email));
$dataCenter1 = substr($apiKey1,strpos($apiKey1,'-')+1);
$url1 = 'https://' . $dataCenter1 . '.api.mailchimp.com/3.0/lists/' . $listID1 . '/members/' . $memberID1;
// member information
$json = json_encode([
'email_address' => $email,
'status' => 'pending',
]);
// send a HTTP POST request with curl
$ch1 = curl_init($url1);
curl_setopt($ch1, CURLOPT_USERPWD, 'user:' . $apiKey1);
curl_setopt($ch1, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_TIMEOUT, 10);
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $json);
$result1 = curl_exec($ch1);
$httpCode = curl_getinfo($ch1, CURLINFO_HTTP_CODE);
curl_close($ch1);
break;
echo "<pre>".print_r($result1, true)."</pre>";
?>
However, it will not respond. The script will be executed.
So far so good. However, I am trying since a couple of days how to write this PHP to get this be working. Additionally, I am not sure if the PHP code is even correct. This was just an assumption.
For references I found this script from membermouse: https://dl.dropboxusercontent.com/u/265387542/files/member_notification_script.php
And this script for Mailchimp: https://www.codexworld.com/add-subscriber-to-list-mailchimp-api-php/
I tried to combine these two, however so far without success.
Thanks for the fast reply #scottcwilson, however I get not responds from this php file.
This is how it looks now:
<?php
require_once("wp-load.php");
require_once("wp-content/plugins/membermouse/includes/mm-constants.php");
require_once("wp-content/plugins/membermouse/includes/init.php");
// Your API URL
$apiUrl = "MYDOMAIN/wp-content/plugins/membermouse/api/request.php";
// Your API key
$apiKey = "My API key";
// Your API secret
$apiSecret = "My API secret";
// ---- GET EVENT TYPE ----
if(!isset($_GET["mm_member_add"]))
{
// event type was not found, so exit
exit;
}
// ---- ACCESS DATA ----
// member data
$username = $_GET["username"];
$email = $_GET["email"];
$apiKey1 = 'Mailchimp API';
$listID1 = 'Mailchimp List ID';
// MailChimp API URL
$memberID1 = md5(strtolower($email));
$dataCenter1 = substr($apiKey1,strpos($apiKey1,'-')+1);
$url1 = 'https://' . $dataCenter1 . '.api.mailchimp.com/3.0/lists/' . $listID1 . '/members/';
// member information
$json = json_encode([
'email_address' => $email,
'status' => 'pending',
]);
// send a HTTP POST request with curl
$ch1 = curl_init($url1);
curl_setopt($ch1, CURLOPT_USERPWD, 'api_v3:' . $apiKey1);
curl_setopt($ch1, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_TIMEOUT, 10);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $json);
$result1 = curl_exec($ch1);
$httpCode = curl_getinfo($ch1, CURLINFO_HTTP_CODE);
curl_close($ch1);
break;
echo "<pre>".print_r($result1, true)."</pre>";
?>
That is correct how you said, right?
The issues with your current code are:
1) You are supplying the memberid on the URL - this is not what you want for a POST to create a new user. So do
$url1 = 'https://' . $dataCenter1 . '.api.mailchimp.com/3.0/lists/' . $listID1 . '/members/';
instead.
2) Some of your cURL setup is wrong. For your POST fields you want
curl_setopt($ch1, CURLOPT_USERPWD, 'api_v3:' . $apiKey1);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, true);
get rid of
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
Trying to implement DELETE https://api.sendgrid.com/v3/contactdb/lists/{list_id}/recipients/{recipient_id} HTTP/1.1 in order to delete a single email recipient from a list, but I get this error message as the Result: {"errors":[{"message":"no valid recipients were provided"}]}.
Here is the code, which I modified from Sending DELETE to API using PHP:
<?php
$list = "971292";
$recipient = "joe#joeblowxyz.com";
$url = 'https://api.sendgrid.com/v3/contactdb/lists/' . $list . '/recipients/' . $recipient;
//this is the data you will send with the DELETE
**# DO I NEED THIS?**
$fields = array(
'field1' => 'field1',
'field2' => 'field2',
'field3' => 'field3'
);
/*ready the data in HTTP request format
*(like the querystring in an HTTP GET, after the '?') */
$fields_string = http_build_query($fields);
//open connection
$ch = curl_init();
/*if you need to do basic authentication use these lines,
*otherwise comment them out (like, if your authenticate to your API
*by sending information in the $fields, above. */
$username = 'myusername';
$password = 'mypassword';
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
/*end authentication*/
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
/*unless you have installed root CAs you can't verify the remote server's
*certificate. Disable checking if this is suitable for your application*/
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//perform the HTTP DELETE
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
The error message, "no valid recipients were provided" makes me think I am supposed to use a numeric recipient id, but I haven't been able to find it for the email address in question. Where is it?
In addition, is there anything else from the above code that is causing me problems?
I am trying to gain a token via the android paypal sdk. I created this cURL inside a php script, but I am unable to update my tkn column in my 000webhost database. The script is called from my app, but I think there might be something wrong with the script. Please let me know if you see anything wrong. Also, it might be that 000webhost does not allow cURL scripts. Please advise. On last minute, one thing that I noticed is that the variable "idclient" and "sekret" are not set as strings. Perhaps this is the problem. Please see if there are any other problems you might encounter.
Here's my script with the cURL:
<?php
require "quimasetup.php";
$name = $_POST["name"];
$email = $_POST["email"];
$phone_number= $_POST["phone_number"];
$subject= $_POST["subject"];
$grade= $_POST["grade"];
$payment_id = $_POST["payment_id"];
$idclient = AVe40dqVhDDmGDbLhNEkH6G9eWyvgrqPrkKAucGv;
$sekret = ELQ595K9VZyfQcJuj7pw1yPVVv7OnNw;
$ch = curl_init("https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch,CURLOPT_HEADER,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $idclient.":".$sekret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
curl_close($ch);
$json = json_encode($result);
$jsonn = json_decode($json);
$tkn = $jsonn->access_token;
$sql = "insert into craddle values('$name','$email','$phone_number','$subject','$grade','$payment_id','$tkn');";
if (isset($tkn)){
if(mysqli_query($connection,$sql)){
echo "<br><h3>one row inserted...</h3>";
}
else{
echo "Error in insertion...".mysqli_error($connection);
}
}
else{
var_dump($json);
var_dump($jsonn);
var_dump($tkn);
}
?>
There is all the relevant information present in broken form in the following links on owncloud related websites and from stackoverflow itself:
User Provisioning Api - Owncloud
PHP + curl, HTTP POST sample code
Create user on ownCloud using Ajax Jquery
User Provisioning - php Authentication error
I am trying to do something very simple :
I have setup an owncloud server in my localhost,
I have an html page that takes in string values of user name and password
I send the page request to be processed by the following php script.
<?php
echo "Begun processing credentials , first it will be stored in local variables" . "<br/>";
// Loading into local variables
$userName = $_POST['username'];
$RRpassword = $_POST['password'];
echo "Hello " . $userName . "<br/>";
echo "Your password is " . $RRpassword . "<br/>";
// Add data, to owncloud post array and then Send the http request for creating a new user
$ownCloudPOSTArray = array('username' => $userName, 'password' => $RRpassword );
$url = 'http://localhost/owncloud/ocs/v1.php/cloud/users';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ownCloudPOSTArray);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "<br/>Created a new user in owncloud";
?>
I get the output like:
Begun processing credentials , first it will be stored in local
variables Hello Frank Your password is frankspassword
failure 997 Unauthorised Created a new user in owncloud
I also tried to login to own cloud using following php script:
// Login As Admin
$ownAdminname = 'ownAdmin';
$ownAdminpassword = 'ownAdminPassword';
$ch = curl_init('http://localhost/owncloud');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$ownAdminname:$ownAdminpassword");
$output = curl_exec($ch);
curl_close($ch);
echo $output;
Even this one fails.
So in short it doesn't work. I am also unable to login via similar script to owncloud. What is the proper way to do this ? What settings am I missing ? Can someone help please ?
Since this question pertains to owncloud specifically, I created an account and posted a question linking this one to it in owncloud forum.
There I was suggested by the owncloud master #RealRancor, the following,
Just had another look, maybe its just easy to replace:
$url = 'http://localhost/owncloud/ocs/v1.php/cloud/users';
with
$url =
'http://adminuser:adminpass#localhost/owncloud/ocs/v1.php/cloud/users';
as shown in the documentation.
And amazingly it worked like a charm. So here is the entire modified php script:
<pre>
<?php
echo "Begun processing credentials , first it will be stored in local variables" . "<br/>";
// Loading into local variables
$userName = $_POST['username'];
$RRpassword = $_POST['password'];
echo "Hello " . $userName . "<br/>";
echo "Your password is " . $RRpassword . "<br/>";
// Login Credentials as Admin
$ownAdminname = 'ownAdmin';
$ownAdminpassword = 'ufi2016%%';
// Add data, to owncloud post array and then Send the http request for creating a new user
$url = 'http://' . $ownAdminname . ':' . $ownAdminpassword . '#localhost/owncloud/ocs/v1.php/cloud/users';
echo "Created URL is " . $url . "<br/>";
$ownCloudPOSTArray = array('userid' => $userName, 'password' => $RRpassword );
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ownCloudPOSTArray);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "Response from curl :" . $response;
echo "<br/>Created a new user in owncloud<br/>";
// Add to a group called 'Users'
$groupUrl = $url . '/' . $userName . '/' . 'groups';
echo "Created groups URL is " . $groupUrl . "<br/>";
$ownCloudPOSTArrayGroup = array('groupid' => 'Users');
$ch = curl_init($groupUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ownCloudPOSTArrayGroup);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "Response from curl :" . $response;
echo "<br/>Added the new user to default group in owncloud";
?>
</pre>
And here is the output:
Begun processing credentials , first it will be stored in local variables
Hello Frank
Your password is frankspassword
Created URL is http://ownAdmin:ufi2016%%#localhost/owncloud/ocs/v1.php/cloud/users
Response from curl : ok 100
Created a new user in owncloud
Created groups URL is http://ownAdmin:ufi2016%%#localhost/owncloud/ocs/v1.php/cloud/users/Frank/groups
Response from curl : ok 100
Added the new user to default group in owncloud
The owncloud documentation states that authentication is done by means of a basic HTTP Authentication header. What you are currently doing is sending the credentials as parameters to the API call. You need to add the following line:
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $RRpassword);
There's also a typo in CURLOPT_RETURNTRANSFER ($curl instead of $ch).
As your linked post (Create user on Owncloud) shows you need to an basic auth header with some credentials. You need to provide the admin credentials, afaict.
I am brand new to using an API outside of an API wrapper. I can access the API using
curl -u username:password https://company.c
om/api/v1/resources/xxxxxxx
That loads up all the information, but what I need to do is send a DELETE to the url based on an array of filenames; e.g. ['/js/jquery.js']. The name of the parameter is Files.
I already have in code the directory and file name variables.
$storageFilename = $directoryname . "/" . $asset->name;
Above returns the /directoryname/filename from the database.
To send an HTTP(S) DELETE using the cURL library in PHP:
$url = 'https://url_for_your_api';
//this is the data you will send with the DELETE
$fields = array(
'field1' => urlencode('data for field1'),
'field2' => urlencode('data for field2'),
'field3' => urlencode('data for field3')
);
/*ready the data in HTTP request format
*(like the querystring in an HTTP GET, after the '?') */
$fields_string = http_build_query($fields);
//open connection
$ch = curl_init();
/*if you need to do basic authentication use these lines,
*otherwise comment them out (like, if your authenticate to your API
*by sending information in the $fields, above. */
$username = 'your_username';
$password = 'your_password';
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
/*end authentication*/
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
/*unless you have installed root CAs you can't verify the remote server's
*certificate. Disable checking if this is suitable for your application*/
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//perform the HTTP DELETE
$result = curl_exec($ch);
//close connection
curl_close($ch);
/* this answer builds on David Walsh's very good HTTP POST example at:
* http://davidwalsh.name/curl-post
* modified here to make it work for HTTPS and DELETE and Authentication */