my php function to update jira issue is like this.i have hardcoded the issue id.it generates an error in if (property_exists($result, 'errors')). saying parameter is not an object.
function post_to($resource, $data) {
$jdata = json_encode($data);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_POST => 1,
CURLOPT_URL => JIRA_URL . '/rest/api/latest/' . $resource,
CURLOPT_USERPWD => USERNAME . ':' . PASSWORD,
CURLOPT_POSTFIELDS => $jdata,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_RETURNTRANSFER => true
));
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
}
function create_issue($issue) {
return post_to('issue/10224/editmeta', $issue);
}
$new_issue = array(
'update' =>array(
'fields' => array(
'project' => array('key' => 'DOTNET'),
'summary' => 'Test via REST',
'description' => 'Description of issue goes here.',
'issuetype' => array('name' => 'Task')
))
);
$result = create_issue($new_issue);
if (property_exists($result, 'errors')) {
echo "Error(s) creating issue:\n";
var_dump($result);
}
}
what am i doing wrong here? please answer.
editmeta should be used only to OBTAIN meta data from an issue.
To update an issue you must use the issue method.
You can check the Jira API details here:
https://docs.atlassian.com/jira/REST/cloud/#api/2/
Not really sure, let's try some thing:
change
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
to:
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/json'
);
and:
$new_issue = array(
'update' =>array(
'fields' => array(
'project' => array('key' => 'DOTNET'),
'summary' => 'Test via REST',
'description' => 'Description of issue goes here.',
'issuetype' => array('name' => 'Task')
))
);
to:
$new_issue = array(
'fields' => array(
'project' => array('key' => 'DOTNET'),
'summary' => 'Test via REST',
'description' => 'Description of issue goes here.',
'issuetype' => array('name' => 'Task')
)
);
lastly, change:
CURLOPT_URL => JIRA_URL . '/rest/api/latest/' . $resource,
to your real address, as well as writing 2 instead of latest, i.e.:
CURLOPT_URL=>'http://localhost/rest/api/2/issue/',
try this, and let me know how it's goes, good luck!
EDIT
try changing:
CURLOPT_POST => 1,
to:
CURL_POST=>true,
CURLOPT_VERBOSE=>1,
btw, where is your jira server? didn't you say it was hosted? localhost:8080 will work only if Jira is installed locally. If so, try opening it using a browser http://localhost:8084/rest/api/2/issue/
EDIT 2
Make sure the Allow Remote API Calls is turned ON under Administration > General Configuration.
to update an issue:
the URL should point to the soon-to-be-updated issue, i.e.:
http://localhost/rest/api/2/issue/TEST-31
and the data should be the same as before, meaning:
$new_issue = array(
'fields' => array(
'project' => array('key' => 'DOTNET'),
'summary' => 'Test via REST',
'description' => 'Description of issue goes here.',
'issuetype' => array('name' => 'Task')
)
);
just as you wrote when you tried to create an issue. you can find here some simple example of how to do so.
EDIT 3
Are you sure you have the right jira address? try again opening a browser and going to the URL and compare it to this example. If the page won't show, you will have to contact Jira's support and ask them how come you can't access the hosted Jira remote API.
Related
Did anyone used https://smsedge.com/ or https://telnyx.com
I am trying to use the PHP api, but no luck with smsedge .
Telnyx works like a charm but I could not find a way to send like a bulk sms.
Tryed the help section, they just posted me a link, but it doesnt work :(
<?php
require_once __DIR__.'/vendor/autoload.php';
\Telnyx\Telnyx::setApiKey('myapikey');
\Telnyx\Message::Create([
"from" => "TShop",
"to" => "+4473836955xx",
"text" => "Hello, World! visit www.google.com",
"messaging_profile_id" => "40017370-b28d-425f-8785-92a64f52ea60"
]);
Is there any way to send to multiple number all at once ?
Also : I am new to php and still reading trying to figure it out .
Thanks in advance .
I struggled many hours to find a service and found one service that does bulk sms :
https://www.infobip.com/
Here is an example(just replace the <api_key> with your key)
$curl = curl_init();
$fields = [
'messages' => [
array(
'from' => 'infoSMS',
'destinations' => ['to' => '1st_phone_number'],
'text' => 'This is first message.',
),
array(
'from' => 'infoSMS',
'destinations' => ['to' => '2nd_phone_number'],
'text' => 'This is second message.',
),
array(
'from' => 'infoSMS',
'destinations' => ['to' => '3rd_phone_number'],
'text' => 'This is third message.',
),
]
];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://qgdg2q.api.infobip.com/sms/2/text/advanced",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fields),
CURLOPT_HTTPHEADER => array(
"Authorization: App <api_key>",
"Content-Type: application/json",
"Accept: application/json",
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
There is also another service which is https://smsedge.com/
I'm using this code to push data to a custom post type of a remote website:
$api_response = wp_remote_post( 'https://example.com/wp-json/wp/v2/clothing_line', array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'admin:5mMcJGUGNFYq9PxU5P0ad0Np' )
),
'body' => array(
'title' => 'Pink Shirt',
'status' => 'publish',
'post_type' => 'clothes',
'categories' => 2,
'slug' => 'pink-shirt',
'meta' => array('amount' => '12.50', 'style' => 'petite', 'size' => 'small', 'gender' => 'ladies', 'author' => 1)
)
));
...and it works fine except for one issue.
'categories' => 2 will probably work fine for regular categories, but I have a custom taxonomy for it called 'clothing_line_cats'.
I need the post that is created on the remote site to have the category for the 'clothing_line_cats' taxonomy.
I tried adding this...
'taxonomy' => 'clothing_line_cats'
...but that did not work.
I can't find any documentation for achieving this.
Feel kind of stupid I didn't realise this before.
Change this...
'categories' => 2
...to this...
'clothing_line_cats' => 2
I've enabled push notifications in my app, added the build hints, registered the api on the play developer console, created and loaded the apple certificates on my server. When I test the app on a device it successfully registers for push notifications. However my issue comes in with trying to actually send a push notification. I want it to send through PHP. I use this code which is taken straight from the developer guide. However this does not work... Is it a problem with my code or did I do something wrong in the enabling push notifications process.
<?php
include("config.php");
$args = http_build_query(array( 'certPassword' => 'XXXXXXXX', 'cert'
=>
'http://kyven.co.za/mibrand/certificate/XXXX.p12',
'production' => false,
'device' => null, 'packageName' => 'za.co.bonyelo.mibrand', 'email'
=>
'kyri88#gmail.com', 'type' => 1,
'auth' => 'XXXXXXXXXXXXXXXXXXXXXXXXXX',
'body' => 'Test'));
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content'
=> $args
) );
$context = stream_context_create($opts);
$response = file_get_contents("https://codename-
one.appspot.com/sendPushMessage", false, $context);
die(json_encode($response));
?>
Got it. This is the code I used
<?php
include("config.php");
$args = http_build_query(array('token' => 'XXXXXXXXXXXXXXXXXXX',
'certPassword' => 'XXXXXXXX', 'cert' =>
'http://XXXXXXX/XXXXX/XXXXX/Certificates.p12',
'production' => false,
'device' => 'cn1-ios-XXXXXXXXXXXXXXXXXXXXXXXX',
'packageName' => 'za.co.bonyelo.mibrand', 'email' =>
'kyri88#gmail.com', 'type' => 1,
'auth' => 'XXXXXXXXXXX',
'body' => 'EAT MY BALLS'));
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $args
) );
$context = stream_context_create($opts);
$response =
file_get_contents("https://push.codenameone.com/push/push", false,
$context);
die(json_encode($response));
?>
I'm using a hipay wallet test account and used there webservices to integrate. Transaction is working fine but problem is that i'm not getting the response in the page, it is suppossed to get in $_POST['xml'] on the response page
$setUrlAck =show_page_link("payment/hipay_new/response.php",true);
Below is my code
if ($PaymentDetails['sel_payment_env'] == 1) {
$wsdl = 'https://ws.hipay.com/soap/subscription?wsdl'; //for live
} else {
$wsdl = 'https://test-ws.hipay.com/soap/subscription?wsdl';//for testing
}
// If the payment is accepted, the user will be redirected to this page
$setURLOk= show_page_link(FILE_THANKS."?add=success&OrderNo=".$orderid,true);
// If the payment is refused, the user will be redirected to this page
$setUrlNok=show_page_link(FILE_THANKS."?cancleMsg=true",true);
// If the user cancels the payment, he will be redirected to this page
$setUrlCancel=show_page_link(FILE_THANKS."?cancleMsg=true",true);
// The merchant?s site will be notified of the result of the payment by a call to the script
$setUrlAck =show_page_link("payment/hipay_new/response.php",true);
$initArray = array(
'wsLogin' => $wsLogin, // Your wsLogin
'wsPassword' => $wspassword, // Your wsPassword
'websiteId' => $txt_Merchant, // Your webSiteId
'categoryId' => $PaymentDetails['txt_category_id'], // Your website category ID (https://test-payment.hipay.com/order/list-categories/id/(websiteId))
'customerEmail' => $customer_email, // Your customers' email
);
$options = array(
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'cache_wsdl' => WSDL_CACHE_NONE,
);
$client = new SoapClient($wsdl, $options);
$data = array(
'currency' => $currency_code,
'rating' => 'ALL',
'locale' => 'fr_FR',
'manualCapture' =>1,
'label' => 'My label is a Manged Subscrption Test Service ',
'customerIpAddress' => $_SERVER["REMOTE_ADDR"],
'merchantReference' => 'AZERTY',
'urlCallback' => $setUrlAck, // Here in this page i'm suppossed to get the response in $_POST
'urlAccept' => $setURLOk,
'urlCancel' =>$setUrlCancel,
'payments' => array(
'initial' => array(
'name' => 'Payment',
'description' => 'Payment for printing products',
'amount' => $price,
'subscriptionId' => 'QWERTY',
'periodType' => 'normal',
'recurrence' => array(
'frequency' => 0,
'duration' => 'managed'
),
),
),
);
Kindly guide me if anyone got through the same issues
The issue is solved, problem was that my firewall setting was blocking the response
I'm currently using the Paypal REST Api for a mobile app.
Here's my code :
$paymentDatas = array(
"intent" => "sale",
"redirect_urls" => array(
"return_url" => "http://example.com/your_redirect_url/",
"cancel_url" => "http://example.com/your_cancel_url/"
),
"payer" => array("payment_method" => "paypal"),
"transactions" => array(
"transactions" => array(
"total" => ".99",
"currency" => "USD"
)
)
);
$paymentUrl = 'https://api.sandbox.paypal.com/v1/payments/payment';
$initCurl = curl_init();
curl_setopt_array(
$initCurl, array(
CURLOPT_URL => $paymentUrl,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false, //todo: For testing purpose, need tp be removed
CURLOPT_POST =>true,
CURLOPT_HTTPHEADER => array(
'Accept-Language: en_US',
'Accept: application/json',
'Authorization: Bearer '.$data['access_token']
),
CURLOPT_POSTFIELDS => json_encode($paymentDatas),
)
);
$initRet = curl_exec($initCurl);
dd($initRet);
curl_close($initCurl);
And the dd gives me this :
string '<ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring xmlns:ns1="http://cxf.apache.org/bindings/xformat">java.lang.NullPointerException</ns1:faultstring></ns1:XMLFault>' (length=196)
I've already made others functions for authentication but I'm pretty new with REST and Paypal Api.
I had the same problem.
When changing the POST request to GET everything worked fine. Hope this will help you.