Crowd RESTful API cannot connect - php

I'm trying to use Crowd authentication into my website but I keep getting 401 Application failed to authenticate. I don't know why because I am passing in the application username and password correctly. What I have:
$data = array("value" => "APP_PASS");
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://PATH:8095/crowd/rest/usermanagement/2/authentication?username=APP_NAME');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'Accept: application/json'
)
);
$output = curl_exec($ch);
echo $output;
curl_close($ch);

You need to use CURLOPT_HTTPAUTH and CURLOPT_USERPWD for your application user:password. Crowd uses ACLs for the requesting application as well as the user authentication you're requesting.
curl -i -u 'APP_USER:APP_PASS' --data '{"value": "USER_PASS"}' https://SERVER_URL/crowd/rest/usermanagement/1/authentication?username=USER_ID --header 'Content-Type: application/json' --header 'Accept: application/json'

Related

How to cURL to PHP Curl PayQuicker

How can I transfer this cURL into php? It's not returning anything
Trying all the ways and not working. Do you know a library for codeigniter that not requires composer?
curl --location --request POST 'https://identity.mypayquicker.build/core/connect/token' \\\
--header 'Authorization: Basic {token}'
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=modify'
--data-urlencode 'scope=readonly'",
"language": "curl",
"name": " "
Doing this way
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Basic {token}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://identity.mypayquicker.com/core/connect/token");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, TRUE);
// This option is set to TRUE so that the response
// doesnot get printed and is stored directly in
// the variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'grant_type' => 'client_credentials'
));
$data = curl_exec($ch);
var_dump($data);
Not Returning Anything

Using PHP CURL how to post json data with basic authentication

I want to post data using PHP curl with basic authentication. Here is my code but I am not able to post using API. But it's working with postman.
$urlp = "URL/sap/opu/odata/sap/ZOSA_UPLOAD_SRV/AccountOrderSet?sap-client=900";
$username = '*****';
$password = '********';
$ch = curl_init ();
curl_setopt($ch,CURLOPT_URL,$urlp);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_MUTE,1);
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
curl_setopt($ch,CURLOPT_USERAGENT,"Proventum Proxy/1.0 (Linux)");
curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10s
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($chp, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json',
'X-Requested-With: application/json')
);
if ($HTTP_REFERER) {
curl_setopt($ch,CURLOPT_REFERER, $HTTP_REFERER);
}
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$datap_string);
$result = curl_exec ($ch);
print $result;
curl_close($ch);
Here you are,
add to the HTTPHEADER option:
Authorization: Basic base64encode(username:password)
for example:
curl_setopt($chp, CURLOPT_HTTPHEADER, array(
'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=',
'Content-Type: application/json',
'Accept: application/json',
'X-Requested-With: application/json')
);

Clickatell Get Balance

I want to withdraw the amount in my account, but the account is not found error. I'm successfully sending sms with the same api.
<?php
$authToken = "myapi";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.clickatell.com/public-client/balance");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-Version: 1",
"Accept: application/json",
"Authorization: Bearer $authToken"
));
echo $result = curl_exec ($ch);
?>
They want like this
curl -X GET --header 'Accept: application/json' --header 'Authorization: Your API key' 'https://platform.clickatell.com/public-client/balance'
Clickatell is not using OAuth2 for authorization, so just remove the "Bearer" from the Authorization. So it should look like this:
<?php
$authToken = "myapi";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.clickatell.com/public-client/balance");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-Version: 1",
"Accept: application/json",
"Authorization: $authToken"
));
echo $result = curl_exec ($ch);
?>

Trying to use PayPal's api and need help converting Curl to PHP

This is PayPal's basic sandbox request to get an access token.
$curl = "curl -v https://api.sandbox.paypal.com/v1/oauth2/token
-H 'Accept: application/json' \
-H 'Accept-Language: en_US' \
-u 'EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp'
-d 'grant_type=client_credentials'";
This is what I've got so far as a conversion but it's failing.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
'Connection: Keep-Alive',
'Accept-Language: en_US',
'Accept: applictaion/json'
));
curl_setopt($ch, CURLOPT_USERPWD, 'EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
print 'Running curl';
$res = curl_exec($ch);
echo $res;
curl_close($ch);
Try removing
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
'Connection: Keep-Alive',
'Accept-Language: en_US',
'Accept: applictaion/json'
));
I copied and pasted your code and just removed the CURLOPT_HTTPHEADER option and it worked!

Curl function to get zone from pointhq.com

curl -u "user#example.com:f9eca287-5346-1cc7-8529-68eb9db7cd5e" -H 'Accept: application/json' -H "Content-type: application/json" https://pointhq.com/zones
How can I call this in php
I assume you are using basic authentication and you can use following;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://pointhq.com/zones");
curl_setopt($s,CURLOPT_HTTPHEADER,array('Accept: application/json', 'Content-type: application/json'));
curl_setopt($ch, CURLOPT_USERPWD, "user#example.com:f9eca287-5346-1cc7-8529-68eb9db7cd5e");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
For more detail refer here

Categories