I want upload a file to JIRA with REST API.
My code :
$ch_api = curl_init('https://website.com/rest/api/2/issue/SI-10255/attachments');
curl_setopt($ch_api, CURLOPT_POST, true);
curl_setopt($ch_api, CURLOPT_POSTFIELDS, json_encode(["file" => "#t.txt"]));
curl_setopt($ch_api, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data','X-Atlassian-Token:no-check'));
curl_setopt($ch, CURLOPT_USERPWD, "login:password");
curl_setopt($ch_api, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch_api);
curl_close($ch_api);
And i have this error :
the request was rejected because no multipart boundary was found
And when i add a boundary, the file is not uploaded. The response from api was a blank array.
Please help.
Thanks.
For upload file to JIRA REST API, not use the header "Content-Type:multipart/form-data"
And for the file, use this code :
if (function_exists('curl_file_create')) {
$cFile = curl_file_create("file.txt");
} else {
$cFile = '#' . realpath("file.txt");
}
Related
I am trying to implement ipn in my system but shows error
SSL connect error
TLS version shows TLS 1.0
It is a client's system. I downloaded the code from paypal website. I am currently testing it.
but it throws error
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
$ch = curl_init('https://www.howsmyssl.com/a/check');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$json = json_decode($data);
echo $json->tls_version;
file_put_contents('NAB/paypal-ipn.txt', var_export($_POST, true));
echo "ipn processing";
// STEP 1: read POST data
// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.
// Instead, read raw POST data from the input stream.
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
echo "<br>1";
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if (function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
echo "<br>2";
foreach ($myPost as $key => $value) {
if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}
echo "<br>3";
// Step 2: POST IPN data back to PayPal to validate
$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
//$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
// In wamp-like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set
// the directory path of the certificate as shown below:
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
echo "<br>3";
if ( !($res = curl_exec($ch)) ) {
error_log("Got " . curl_error($ch) . " when processing IPN data");
echo curl_error($ch);
curl_close($ch);
//exit;
}
If 'howsmyssl' is reporting that the systems supports only TLS v 1.0, it is likely that an upgrade is necessary to support TLS v 1.2. The curl_setopt($ch, CURLOPT_SSLVERSION, 6); is requesting TLS v 1.2 (see list in PHP Curl (with NSS) is probably using SSLv3 insted of TLS when connecting to https).
Also, as of June 30,2017, PayPal will be requiring TLS v 1.2 (see https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US and Php curl set ssl version).
You may be able to test your integration using TLS v 1.0 (until 6/30/2017) by changing to curl_setopt($ch, CURLOPT_SSLVERSION, 4);.
I had a similar problem problem when implementing the paypal ipn listener code. The script would stop executing where step 2 starts in the code you've provided. I solved it by downloading cacert.pem from http://curl.haxx.se/docs/caextract.html. Then I copied the downloaded file to the same folder as paypalipnlistener.php and then uncommented the following code in paypalipnlistener.php // curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem'); to curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem'); and the script executed successfully.
I'm using this link in order to add new subsciption entry:
https://graph.facebook.com/XXX/subscriptions?access_token=YYY&object=payments&callback_url=http://xxx/rlcallback.php&fields=actions,disputes&verify_token=ZZZ
For some reason, I get error:
{
"error": {
"message": "(#100) Invalid object. object should be url or open graph object id.",
"type": "OAuthException",
"code": 100
}
}
But the object "payments" inside my link is clearly valid. What am I missing here?
Make sure you are using the correct parameters: object, callback_url, fields, verify_token...and of course the access_token.
Also (and that may be the problem in this case), you have to use POST, not GET. You can either use CURL with POST to subscribe to the Realtime API, or you just use one of the SDKs as explained in the Facebook docs: https://developers.facebook.com/docs/graph-api/reference/v2.1/app/subscriptions
Here is one example with CURL:
$appsecretProof = hash_hmac('sha256', FBAPPID . '|' . FBSECRET, FBSECRET);
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'facebook-php');
$postData = 'object=page' .
'&callback_url=' . urlencode('http://yourdomain.com/callback.php') .
'&fields=feed' .
'&verify_token=somethingfancy' .
'&access_token=' . FBAPPID . '|' . FBSECRET .
'&appsecret_proof=' . $appsecretProof;
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/' . FBAPPID . '/subscriptions');
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$curlResult = curl_exec($ch);
you need to specify object, callback_url, fields and verify_token parameters as your curl post parameters
example:
curl -F 'object=user' \
-F 'callback_url=' \
-F 'fields=checkins' \
-F 'verify_token=' \
"https://graph.facebook.com//subscriptions?access_token=
I'm trying to set up a credit card interface on a website using Intuit's QBMS and I've got the XML request set up per the specifications on the Intuit documentation. I've also got my AppID, Connection Ticket, and Application Login set up. But when I do a test, I'm getting the following error:
Unknown error returned by SAX parser. Exception from other package: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
Here is the XML Request:
$productionUrl = 'https://merchantaccount.quickbooks.com/j/AppGateway';
$connectionTicket = 'SDK-xxx-xxx-xxxxxxxxxxxxxxxxxxxxxxxx';
$applicationLogin = 'qbms.site.com';
$appID = "111111111";
$xml = rawurlencode('<?xml version="1.0"?>
<?qbmsxml version="4.1"?>
<QBMSXML>
<SignonMsgsRq>
<SignonDesktopRq>
<ClientDateTime>' . date('Y-m-d\TH:i:s') . '</ClientDateTime>
<ApplicationLogin>' . $applicationLogin . '</ApplicationLogin>
<ConnectionTicket>' . $connectionTicket . '</ConnectionTicket>
<Language>English</Language>
<AppID>' . $appID . '</AppID>
<AppVer>1.0</AppVer>
</SignonDesktopRq>
</SignonMsgsRq>
<QBMSXMLMsgsRq>
<CustomerCreditCardChargeRq>
<TransRequestID>' . $_transId . '</TransRequestID>
<CreditCardNumber>' . $_cc_number . '</CreditCardNumber>
<ExpirationMonth>' . $_cc_exp_month . '</ExpirationMonth>
<ExpirationYear>' . $_cc_exp_year . '</ExpirationYear>
<IsCardPresent>false</IsCardPresent>
<Amount>' . $_amount . '</Amount>
<NameOnCard>' . $_cc_name . '</NameOnCard>
<CreditCardAddress>' . $_cc_address . '</CreditCardAddress>
<CreditCardPostalCode>' . $_cc_zip . '</CreditCardPostalCode>
<SalesTaxAmount>' . $_tax . '</SalesTaxAmount>
</CustomerCreditCardChargeRq>
</QBMSXMLMsgsRq>
</QBMSXML>');
$header[] = "Content-type: application/x-qbmsxml";
$header[] = "Content-length: " . strlen($xml);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, $productionUrl);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$response = curl_exec($ch);
curl_close($ch);
print_r($response);
Since the documentation is still not available, in particular https://developer.intuit.com/qbsdk-current/Common/newOSR/index.html
This is speculation based on my testing. Check to see that the <TransRequestID>
contains a number, with only leading or following alpha characters (if any).
The response contains this xml: <TxnAuthorizationStamp>
which is your TransRequestID incremented by 1. I think if it can't figure out how to increment it will fail.
Please update any progress you have.
I know that this is an old question but I ran into similar problems and was able to get it working.
When I removed this phrase from the request xml packet:
<?xml version="1.0"?>
The SAX parser error went away and it works.
Could I get post back params if in scenario to a buyer click 'cancel and return to xxx store'? below code is how I tried to have post back params echo out after buyer click cancel during the palpal webscr process:
$req = 'cmd=_notify-synch';
$pp_hostname = "www.sandbox.paypal.com";
$tx_token = $_GET['tx'];
$auth_token = "Ti-bfX-sv-zNDXZS";
$req .= "&tx=".$tx_token."&at=".$auth_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://".$pp_hostname."/cgi-bin/webscr");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
//if your server does not bundled with default verisign certificates.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$pp_hostname));
$res = curl_exec($ch);
curl_close($ch);
if(!$res){
//HTTP ERROR
}else{
// parse the data
$lines = explode("\n", $res);
$keyarray = array();
if(strcmp($lines[0], "SUCCESS") == 0){
for($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
//process payment
}else if(strcmp($lines[0], "FAIL") == 0){
$lines = explode("\n", $res);
$keyarray = array();
for($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// echo post back params if FAIL
echo "<p><h3>Transaction ".$keyarray['payment_status']."!</h3></p>";
}
}
Is that possible to get post back params if response FAIL? I need some data to process in db if buyer cancel the transaction.
Thanks.
PayPal would not pass back any parameters to your cancel your, but you could pass back your own. You could dynamically populate the cancel URL that helps you to identify the user or order, and then read that on the cancel URL. For example, you could dynamically populate the cancel URL to something like https://www.mysite.com/cancel.php?orderid=483723 and then you would do your own look up in your system based on the order id, or what ever you pass over and back to your cancel URL.
paypal provide all things about transaction information for more information check below link info
reason_code
https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
So I am getting this error and I have no clue why. When I run it on the server it's on, I get a 404 error with a simple request like this.
$json = file_get_contents('https://graph.facebook.com/me?access_token='.LONGSTRING);
The error is:
function.file-get-contents: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
However, I can paste the URL that I am using with file_get_contents directly in the browser at the same time and it comes up. So it seems as if Facebook is blocking my server.
Also it works half the time.
Any ideas?
Try cURL, not sure why file_get_contents is unreliable but I have seen the same issue in the past. I use this geturl function to cURL a URL and pass the parameters in as a PHP array
function geturl($url, $params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params, null, '&'));
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
Which can then be called like so
$url = 'https://www.graph.facebook.com/me';
$params = array('access_token' => '*********************');
$graph_ret = geturl($url, $params);
$json = #file_get_contents('https://graph.facebook.com/me?access_token='.$access_token) or die("ERROR");
use this will help you alot