I need to make one API request to AWS Route53 to create a reusable delegation set. You can't do this through the console web interface, it has to be through the API.
Here is the documentation for making this API request: http://docs.aws.amazon.com/Route53/latest/APIReference/api-create-reusable-delegation-set.html
<?php
$baseurl = "route53.amazonaws.com/2013-04-01/delegationset";
$body = '<?xml version="1.0" encoding="UTF-8"?>
<CreateReusableDelegationSetRequest xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<CallerReference>whitelabel DNS</CallerReference>
</CreateReusableDelegationSetRequest>';
$ch = curl_init();
// Set query data here with the URL
curl_setopt($ch, CURLOPT_URL, $baseurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $body );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: route53.amazonaws.com','X-Amzn-Authorization: '));
curl_setopt($ch, CURLOPT_TIMEOUT, '3');
$rest = curl_exec($ch);
if ($rest === false)
{
// throw new Exception('Curl error: ' . curl_error($crl));
print_r('Curl error: ' . curl_error($ch));
}
curl_close($ch);
print_r($rest);
?>
I know the request isn't signed/authenticated, but I'm not even able to connect to the server. I would at least like to get an error message that says I'm not authenticated before I continue. Instead all I get is "connection refused".
I'm sure I'm doing something completely wrong here. But Google has been of no use.
scrowler was right. I changed:
$baseurl = "route53.amazonaws.com/2013-04-01/delegationset";
to
$baseurl = "https://route53.amazonaws.com/2013-04-01/delegationset";
I got the error message I was expecting and now I can work on the next step.
Related
Trying to add some kind of value to each data point so I can send the response (numbers only) to an existing table . I've been searching online and no CURL API response seems to be this simple so I can find an answer. (sorry new to this, don't know the "lingo")
This is the response I've been able to echo on screen.
"{"price": 2049.27, "change_point": -5.76, "change_percentage": -0.28, "total_vol": "1.27M"}"
rest of php below
<html>
<?php
$url = 'https://realstonks.p.rapidapi.com/';
$collection_name = $_REQUEST["stock_name"];
$request_url = $url . '/' . $collection_name;
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'X-RapidAPI-Host: www.xyz.com',
'X-RapidAPI-Key: xxxxxxxxxxxxxxxxxxx',
'Content-Type: application/json']);
$response = curl_exec($curl);
curl_close($curl);
//Uncomment bellow to show data on screen
echo $response . PHP_EOL;
enter code here
//var_dump(json_decode($json));
//var_dump(json_decode($json, true));
// Initiate curl
$ch = curl_init();
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
?>
I'm not much into PHP but here to here. If I'm not mistaken it, I think you want to store $response in <td> element. This resource can help https://www.daniweb.com/programming/web-development/threads/428730/how-to-display-php-variable-in-html
Im trying to connect to the API services of 2ba. Somehow I just can't connect. I get the error: error: "invalid_client"
I dont know what to try, it feels like I need to hash my cliend_secret or complete url but I dont see that in the documentation.
This is my code (PHP):
<?php
// ---- GET TOKEN ----
// Base url for all api calls.
$baseURL = 'https://authorize.2ba.nl';
// Specified url endpoint. This comes after the baseUrl.
$endPoint = '/OAuth/Token';
// Parameters that are required or/and optianal for the endPoint its request.
$parameters = 'grant_type=password&username=abc#abc.com&password=123abc&client_id=myClientID&client_secret=myClientSecret';
// All parts together.
$url = $baseURL . $endPoint . '?' . $parameters;
//Init session for CURL.
$ch = curl_init();
// Options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
// Init headers for access to the binance API signed data.
$headers = array();
$headers[] = 'Content-type: application/x-www-form-urlencoded';
$headers[] = 'Content-Length: 0';
// Setting headers
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute request.
$data = curl_exec($ch);
// If there is an error. Show whats wrong.
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
// Ends the CURL session, frees all resources and deletes the curl (ch).
curl_close($ch);
$result = json_encode($data);
echo($data);
exit();
?>
The authentication is oauth2 and I want to use the "Password Grant" flow since I can login automaticly this way. Also I see in the example code in C# that they encode the url, something im not doing yet but did try. It did not work.
// Using $encodedUrl like this: curl_setopt($ch, CURLOPT_URL, $encodedUrl); but does not work.
$encodedUrl = urlencode($url);
Alright so I fixed it. I now got my access token and am able to recieve data from the API. This is what I did:
// ---- GET TOKEN - FLOW: USER PSW ----
// No changes
$baseURL = 'https://authorize.2ba.nl';
// No changes
$endPoint = '/OAuth/Token';
// $parameters is now an array.
$parameters = array(
'grant_type' => 'password',
'username' => 'myUsername',
'password' => 'myPassword',
'client_id' => 'myClientID',
'client_secret' => 'myClientSecret'
);
// Removed the $parameter part
$url = $baseURL . $endPoint;
//Init session for CURL.
$ch = curl_init();
// Init headers for access to the binance API signed data.
$headers = array();
$headers['Content-Type'] = "application/x-www-form-urlencoded";
// NOTE: http_build_query fixed it.
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($parameters)); // Automaticly encodes parameters like client_secret and id.
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute request.
$data = curl_exec($ch);
// If there is an error. Show whats wrong.
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
// Ends the CURL session, frees all resources and deletes the curl (ch).
curl_close($ch);
$result = json_encode($data);
echo($data);
exit();
Receiving 401 Authentication Access error when trying to request Hosted Payment Field access token via PHP. I have followed this tutorial -> Easy start with BlueSnap hosted payment fields; read about these similar issues -> 1. BlueSnap integration with node js and angular 2. Error getting payment_field_token in Bluesnap API as well as read through the basic auth info http://developers.bluesnap.com/docs/authentication with no luck. Can anyone figure this out?
<?php
$TokenRequest=curl_init();
curl_setopt($TokenRequest, CURLOPT_URL, "https://sandbox.bluesnap.com/services/2/payment-fields-tokens");
curl_setopt($TokenRequest, CURLOPT_HEADER, 1);
curl_setopt($TokenRequest, CURLOPT_HTTPHEADER, array("Authorization: Basic CREDENTIALS_HERE", "Content-type: application/json"));
curl_setopt($TokenRequest, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($TokenRequest, CURLOPT_RETURNTRANSFER, true);
$TokenResponse=curl_exec($TokenRequest);
list($Headers, $Response)=explode("\r\n\r\n", $TokenResponse, 2);
$Headers=explode("\n", $Headers);
foreach($Headers as $Header)
{
if (stripos($Header, "Location")!==false)
{
$Token=trim(str_replace("Location: ", "", $Header));
}
}
?>
I work for BlueSnap.
A 401 error usually means a permission issue. Did you white list your IP in the BlueSnap console. Docs on how to do that can be found here: https://developers.bluesnap.com/docs/api-credentials . If you can provide me the actual JSON object (or XML) you are sending I can try to trace the exact error and try to determine root cause.
I found your API calls and you are doing a GET instead of a POST. The create a token you need to call a POST.
In the following URL you will find how to create the credentials to be able to generate the token: https://developers.bluesnap.com/docs/api-credentials
once you have the username and password, substitute the data of the variables: $username, $password:
the following code works for me
$host = 'https://sandbox.bluesnap.com/services/2/payment-fields-tokens';
$username = 'API_1644786117605226907536';
$password = '654321Pm!';
$TokenRequest=curl_init();
curl_setopt($TokenRequest, CURLOPT_URL, $host);
curl_setopt($TokenRequest, CURLOPT_HEADER, 1);
curl_setopt($TokenRequest, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($TokenRequest, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($TokenRequest, CURLOPT_RETURNTRANSFER, true);
$TokenResponse=curl_exec($TokenRequest);
list($Headers, $Response)=explode("\r\n\r\n", $TokenResponse, 2);
$Headers=explode("\n", $Headers);
foreach($Headers as $Header)
{
if (stripos($Header, "Location")!==false)
{
$Token=trim(str_replace("Location: ", "", $Header));
}
}
print_r($Token);
$HOSTEDFIELDTOKENID = str_replace("https://sandbox.bluesnap.com/services/2/payment-fields-tokens/", "", $Token);
echo '<br><br><br><br>';
print_r($HOSTEDFIELDTOKENID);
I am building my first ever project from scratch on a lamp stack. I decided to try out the slim api framework. Below you can see i start building a helper function for my api. However I am getting this
error: undefined constant CURLOPT_GET - assumed 'CURLOPT_GET'
and then this
error: curl_setopt() expects parameter 2 to be long, string given
// Main Gospel Blocks API Call Function
Function gbCall($gbRoute) {
// JSON Headers
$gblCallHeaders[] = "Content-Type: application/json;charset=utf-8";
// Call the API
$gblCall = curl_init();
curl_setopt($gblCall, CURLOPT_URL, $GLOBALS['gbApiUrl'] . $gbRoute);
curl_setopt($gblCall, CURLOPT_GET, TRUE);
curl_setopt($gblCall, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($gblCall, CURLOPT_HTTPHEADER, $gblCallHeaders);
// Get the response
$response = curl_exec($gblCall);
// Close cURL connection
curl_close($gblCall);
// Decode the response (Transform it to an Array)
$response = json_decode($response, true);
// Return response
return $response;
}
The api I am hitting is just json encoded objects, not quite sure why this isn't returning the json...
Try using CURLOPT_HTTPGET though I am not sure if it serves your purpose.
More detail can be found here
It happens when phpxxx-curl was not installed in your machine
There is nothing like CURLOPT_GET in the options for cURL that's why that error occured. Take a look at CURL options
For the GET Request in the Curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "URL");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$headers = array();
$headers[] = "Key: Value";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
I am trying to connect to the Marketo.com REST API using curl.
I can't get a response from the identity service. I only get an error message
"[curl] 6: Couldn't resolve host 'MY_CLIENT_ENDPOINT.mktorest.com'
,
but I can print the constructed url and paste it into a browser address bar and this will provide the expected response with the access_token element.
I can use curl in php and in a terminal to access my gmail account so curl is able to access an https service.
I have tried sending the parameters in the curl url as a get request and also by declaring them with curl's -F option as a post request
My application uses dchesterton/marketo-rest-api available on github, but I have also tried a simple php curl request just to get the access token.
private function getToken() {
$url = "$this->client_url/identity/oauth/token?grant_type=client_credentials&client_id=$this->client_id&client_secret=$this->client_secret";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$errors = curl_error($ch);
curl_close($ch);
file_put_contents($this->logDir . 'access_token_response' . date('Y-m-d') . '.txt', $url . "\n" . $response . "\n", FILE_APPEND);
if ($errors) {
file_put_contents($this->logDir . 'access_token_errors' . date('Y-m-d') . '.txt', $errors . "\n", FILE_APPEND);
}
return $response['access_token'];
}
Again, this fails with the same error but produces a perfectly formed url that I can paste into the browser and get a valid response.
I have also tried this using post instead of get as I have for every other test mentioned, and these have been tried on my localhost and on a test server.
Can anyone explain to me why this would fail?
Does Marketo block curl on a per account basis?
I was trying to implement something similar but my code wasn't working. I'm not sure exactly what is failing but I tried your code and it seems to work perfectly after some slight modifications:
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($request_data));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($curl);
$errors = curl_error($curl);
curl_close($curl);
I hope this helps.