Can anyone help to get access token by using Flipkart app id and app secret.
We have tried with the code below:
<?php
$username='appid';
$password='appsecret';
$url='https://api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
$output = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$info = curl_getinfo($ch);
curl_close($ch);
if(curl_errno($ch)){
echo 'Curl error: ' . curl_error($ch);
}
print_r($output);
echo $status_code;
But we get the error:
{"error":"invalid_grant","error_description":"Unauthorized grant type: client_credentials"} 400
I ran through the same issue and after struggling for a couple of hours I went to my seller account and recreated my "Application Id" and "Application Secret". The only difference I made was I selected "self_access_application" instead of "third_party_application" this time and I was good to go.
Please refer: https://nimb.ws/sziWmA
Hope this helps
Thanks
You can try this code, i also faced the same issue.
$url = "https://api.flipkart.net/oauth-service/oauth/token?grant_type=client_credentials&scope=Seller_Api";
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, config('constants.flipkart.application_id').":".config('constants.flipkart.secret_key'));
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
$token = json_decode($result,true);
if(isset($token['access_token'])){
$this->access_token = $token['access_token'];
}
you can try this it will be helpful python/odoo developer
def flipkart_token_generation(self):
if not self.flipkart_sandbox_app_id or not self.flipkart_sandbox_cert_id:
raise UserError(_("Flipkart: cannot fetch OAuth token without credentials."))
else:
url = "https://sandbox-api.flipkart.net/oauth-service/oauth/token"
data = {'grant_type': 'client_credentials', 'scope': 'Seller_Api'}
response_json = requests.get(url, params=data, auth=(self.flipkart_sandbox_app_id, self.flipkart_sandbox_cert_id)).json()
self.env['ir.config_parameter'].sudo().set_param('flipkart_sandbox_token', response_json["access_token"])
Related
Google chatbot has a webhook where users can automate chat there is a small python script to make it work but I want to do the same using php. I am using curl to hit the post method
$apiUrl = 'https://chat.googleapis.com/v1/spaces/AAAAbvoeZ0w/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=h2OIcCLB6_f_XxhPX6lugnGizE88ZBBpJURFHtPfh_0%253D';
$ch = curl_init($apiUrl);
//$kid_userid = "IXM_".session('user_data')['userID'];
$data = '{"text": "All Mock Test are Free "}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
after hitting this code I am getting errors.
{
error: {
code: 400,
message: "Invalid request token h2OIcCLB6_f_XxhPX6lugnGizE88ZBBpJURFHtPfh_0%3D",
status: "INVALID_ARGUMENT"
}
}
but same code when I am running on python it is working perfectly. Any Help will be very helpful. Thanks for the help in advance and I tried my best to explain .Sorry If I have made any mistake.
This code works for me. I have it from another SO answer, maybe the issue is the missing CURLOPT_POST...
$uri = "https://chat.googleapis.com/v1/spaces/AAAAgcWhzwk/messages?key=MY_KEYI&token=MY_TOKEN";
$msg = '*Testing Curl PHP message to Google Chat*\n\n Description';
$params = '{"text": "'.$msg.'"}';
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
The above code which I have shared is correct actually I just added the new bot URI and it worked. THanks, everyone for your help.
I am trying to update a LEAD using this URL
$lead_url = ‘https://’.$company_domain.’.pipedrive.com/api/v1/leads/’ . $leadID . ‘?api_token=’ . $PD_API_KEY;
But it returns 404 Not Found. When I check this URL in the browser it returns the complete information of that lead.
Here is my Curl Code:
function pipedrive_update_curl($arr , $endpoint)
{
$response = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arr));
//***//
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//**//
$response_result = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errors = curl_error($ch);
curl_close($ch);
$response['error'] = $curl_errors;
$response['status'] = $status_code;
$response['response'] = $response_result;
return $response;
}
Can somebody please explain where I am going wrong?
PUT method for updating leads is not supported.
see docs and pipedrive community posts:
https://developers.pipedrive.com/docs/api/v1/Leads#updateLead
https://devcommunity.pipedrive.com/t/put-not-working-when-updating-a-lead/3629
I deployed a Flask application to AWS lambda
#bp_google_routes.route('/is_authorized', methods=('POST', ))
def google_is_authorized():
data = json.loads(request.data)
flask.session['user_email'] = data['email']
authorized = aws_handler.already_authorized(data['email'])
return jsonify({'authorized': authorized})
#bp_google_routes.route('/authorize', methods=('GET', ))
def google_authorize():
if 'user_email' not in flask.session:
abort(404)
return 'All good'
I'm accessing the application via an PHP backend to first check the authorization is_authorized which is a POST request and will store the email in the session.
Then right after I'll perform a second call to authorize which always aborts since apparently there's no email in the session. But there should be from the first request:
<?php
$data = array("email" => "test#test.com");
$data_string = json_encode($data);
$aws_endpoint = "https://.../is_authorized";
$aws_endpoint_auth = "https://.../authorize";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $aws_endpoint);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close ($ch);
if ($err) {
echo "There was an error accessing the requested information!";
} else {
$result = json_decode($response);
if (!$result->authorized) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $aws_endpoint_auth);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo $result;
print_r('False');
} else {
print_r('True');
}
}
?>
Why is the the session not persistent between the two calls?
You need to tell curl to persist the cookies using a cookiejar.
Add the line below to the top of your file:
$cookieFileName = tempnam('/tmp','cookies.txt');
Then add the curl_setopt calls below to each of your calls:
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFileName);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFileName);
This way, curl will store & re-use the cookies between requests.
I'm playing around with integrating Jira into our current PHP based website and I am wondering if their is anyway I can authenticate users using something other than a plaintext password. I don't really want to store the plaintext passwords in the website database. The script below is a script I found and I've been playing around with querying and such. I would like to authenticate the user as soon as they log into the backend of our website. Is it possible to authenticate someone without a plaintext password?
<?php
$username = '******';
$password = '*****';
$url = "https://jira.*****/rest/api/2/search?jql=****";
$ch = curl_init();
$headers = array(
'Accept: application/json',
'Content-Type: application/json'
);
$test = "This is the content of the custom field.";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
$phpData = json_decode($result);
foreach($phpData->issues as $issue){
print_r($issue)
}
}
curl_close($ch);
?>
You should be able to use OAuth to perform the initial authentication of the user to JIRA then store their oauth token in their session and use it for future requests.
Here is the link to the PHP OAuth Example they have in Bit Bucket:
https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples/src/d625161454d1ca97b4515c6147b093fac9a68f7e/php/?at=default
I am trying to access the Toggl Reporting API.
I tried following in PHP with cURL, which connects to the API but gives the following error message: 'This method may not be used.' Any light on why this is the case would be useful as I'm very new to webservices. I may be missing something obvious or totally going the wrong way about it, so apologies if this is the case.
<?php
$userAgent = 'xxx';//username
$token = 'xxx';//token
$returned_content = get_data('https://toggl.com/reports/api/v2/summary?&workspace_id=[workspaceid]&since=2013-05-19&until=2013-05-20&user_agent=[username here]');
print_r($returned_content);
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERPWD, $token.':api_token');
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
Edit: I tried a different approach. If I run the following code, I no longer receive any error messages, so the code seems to be executing but I can't print the response to the screen. Is there something specific I need to do to view the output other than print_r?(Toggl API returns JSON). Thanks.
$json = curl%20-v%20-u%[myapitoken]:api_token%20https://toggl.com/reports/api/v2/weekly?workspace_id=[id]&wsid=282507&since=2012-08-19&until=2013-09-20&user_agent=[user].json;
print_r($json);
Edit: Finally resolved! Code is as follows:
$workspace_id = '[id here]';
$user_agent = '[user agent here]'; // no spaces
$api_token = '[token here]';
$report_url = 'https://toggl.com/reports/api/v2/weekly?user_agent='.$user_agent.'&since=2013-08-01&until=2013-09-01';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_USERPWD, $api_token . ':api_token');
curl_setopt($ch, CURLOPT_URL, $report_url . '&workspace_id=' . $workspace_id);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$result = curl_exec($ch);
$result = json_encode($result);
Hope this helps someone in the future!
As I understand, you are receiving this message because of CURLOPT_SSL_VERIFYPEER == FALSE.
Try to remove this string from the code:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
Maybe I wrong, but I think with this option you are receiving "HTTP 501 Not Implemented" error from the Toggl server, which contains exactly the same message, "This method may not be used."