JIRA expand = changelog not working - api

I'm trying to query jira for data with folowing jql:
$jql_options = array(
"jql" => $jql,
"startAt" => 0,
"maxResults" => 1,
"validateQuery" => false,
"fields" => array(
"summary",
"status",
"assignee"
),
"expand" => "changelog"
);
And i get this error:
string(282) "{"errorMessages":["Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token\n at [Source: org.apache.catalina.connector.CoyoteInputStream#464d8928; line: 1, column: 2] (through reference chain: com.atlassian.jira.rest.v2.search.SearchRequestBean[\"expand\"])"]}"
I understand it's an error with "expand" => "changelog" but on their site they present an requeste representation like mine.
Can u give me some advice? :)

It seems i was reading the rest api documentation wrong.
"expand" option was available only in get request.
I appended jql data in url + "&expand=changelog" and other options i send them in post!
$jql_options = array(
"startAt" => 0,
"maxResults" => 1,
"validateQuery" => false,
"fields" => array(
"key"
)
);
$data = json_encode($jql_options);
$options = array(
CURLOPT_URL => $this->jiraURL . "/rest/api/latest/search?jql=" .urlencode($jql) . "&expand=changelog",
CURLOPT_HTTPHEADER => array(
'Authorization: Basic ' . base64_encode($this->username.":".$this->password),
'Content-type: application/json') ,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data
);

Related

Issue with post API curl library codeigniter 3

I use this library:
https://github.com/php-curl-class/php-curl-class
Base on documentation I write function for post order:
public function create_order()
{
$curl = new Curl();
$curl->setHeader('CustomerId', 'xxxxxxx');
$curl->setHeader('UserName', 'xxxxxxxxxx');
$curl->setHeader('ActionApiKey', 'xxxxxxxxxxxxxxx');
$order = array(
"createEmpty" => false,
"header" => array(
"comment" => "string",
"country" => "Polska",
"currency" => "PLN",
"isFileRequired" => true,
"actionCustomerId" => "81790",
"payer" => "EndCustomer",
"paymentType" => "CashOnDelivery",
"partnerOrderId" => "81790",
"deliveryAddresType" => "EndCustomer",
"cashOnDeliveryType" => "FullRate",
"cashOnDelivery" => 155,
"deliveryCompanyName" => "TEST API ORDER DO NOT SHIP",
"deliveryCity" => "Poznań",
"deliveryPhone" => "xxxxxxx",
"deliveryStreet" => "xxxxxxxxxx",
"deliveryZipCode" => "xxxxxxx"
),
"items" => array(
array(
"actionProductId" => "MULLOGKAM0087",
"quantity" => 1,
"price" => 122,
"backOrderType" => "BackOrder"
)
)
);
$curl->setHeader('Content-Type', 'application/json');
$curl->post('xxxxxxxxxxxxxxxxxxxxx/v2/Order', json_encode($order));
if ($curl->error) {
echo 'Error: ' . $curl->error_code . ': ' . $curl->error_message;
} else {
echo 'Respone: ' . $curl->response;
}
}
After run controller, I get white page (I not get any error) but order not created. I test in Insomia API client and with this headers and data order created sucess.
Im not sure I correct post headers also with order data ?

Shopware - How to get products using App Credentials?

I created App in Shopware and able to get apiKey, secretKey, shopUrl and shopId. I want to get all my products using these credentials.
This is my code
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "http://shopware.example.com/store-api/product",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
"Accept: application/json",
"Content-Type: application/json",
"sw-access-key: SW234C1LVA010CWHDD34WK1TMW"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
$data = json_decode($response, true);
print_r($data);
}
and I am getting error like this
Array
(
[errors] => Array
(
[0] => Array
(
[status] => 412
[code] => FRAMEWORK__ROUTING_SALES_CHANNEL_NOT_FOUND
[title] => Precondition Failed
[detail] => No matching sales channel found.
[meta] => Array
(
[parameters] => Array
(
)
)
)
)
)
When I using API key from settings page API I am able to get products.
But how to use App credentials (App key, secret key, shop URL) and get products
You should have gotten the API key during App registration:
https://developer.shopware.com/docs/guides/plugins/apps/app-base-guide#confirmation-request
Did you try that one? If it does not work for the store API you might want to use the admin API.

Add Tracking API in Paypal - Authorization failed

I am trying to add tracking number and order status in my sandbox account through tracking API but getting "Authorization failed due to insufficient permissions" error. Anyone have any idea why this error happens? Below are my codes and response from paypal -
API request
$clientId = 'my client id';
$secretKey = 'my secret key';
$token = $this->getAccessToken($clientId, $secretKey);
$transaction = $this->_objectManager->create('\Magento\Sales\Api\Data\TransactionSearchResultInterfaceFactory')->create()->addOrderIdFilter($currentOrder->getId())->getFirstItem();
$transactionId = $transaction->getData('txn_id');
$postfields = [
'trackers' =>
[
0 =>
[
'transaction_id' => $transactionId,
'tracking_number' => $currentOrderTrackingNumber,
'status' => 'SHIPPED',
'carrier' => 'OTHER',
'carrier_name_other' => 'SCS Logistics'
]
]
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-m.sandbox.paypal.com/v1/shipping/trackers-batch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($postfields),
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Bearer " . $token
),
));
$response = curl_exec($curl);
curl_close($curl);
$response = json_decode($response, true);
Response from paypal
Array
(
[tracker_identifiers] => Array
(
)
[errors] => Array
(
[0] => Array
(
[name] => NOT_AUTHORIZED
[message] => Authorization failed due to insufficient permissions
[details] => Array
(
[0] => Array
(
[field] => /trackers/1/transaction_id
[value] => 42L93730906985049
[location] => body
[issue] => USER_NOT_AUTHORIZED
[description] => You are not authorized to add or modify tracking number for this transaction
)
)
[links] => Array
(
)
)
)
[links] => Array
(
[0] => Array
(
[href] => https://api-m.sandbox.paypal.com/v1/shipping/trackers-batch
[rel] => self
[method] => POST
[encType] => application/json
)
)
)
I already contacted support and they added required permission but it's not working. Please if anyone have any idea about it help me. Thanks in advance.

Prestashop filter date_add in webservice

i'm new, and i've a problem with webservice.
when i try to retrieve customers filtering by date_add i get this error:
<message><![CDATA[This filter does not exist. Did you mean: "deleted"? The full list is: "id", "id_default_group", "id_lang", "newsletter_date_add", "ip_registration_newsletter", "last_passwd_gen", "secure_key", "deleted", "passwd", "lastname", "firstname", "email", "id_gender", "birthday", "newsletter", "optin", "website", "company", "siret", "ape", "outstanding_allow_amount", "show_public_prices", "id_risk", "max_payment_days", "active", "note", "is_guest", "id_shop", "id_shop_group"]]></message>
this is my code:
$yesterday = date("Y-m-d H:i:s", time() - 60 * 60 * 24);
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
// Qui imposto le opzion dell'array per il Webservice: in questo caso i clienti e setto che il formato è json
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$yesterday.']&date=1',
'display' => 'full',
'output_format' => 'JSON'
);
// faccio la chiamata
$xml = $webService->get($opt);
I'm stuck, I do not know what to do !!! any help is appreciated
Looking at the Customer class webservice parameters, there is no date_add:
protected $webserviceParameters = array(
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
'id_lang' => array('xlink_resource' => 'languages'),
'newsletter_date_add' => array(),
'ip_registration_newsletter' => array(),
'last_passwd_gen' => array('setter' => null),
'secure_key' => array('setter' => null),
'deleted' => array(),
'passwd' => array('setter' => 'setWsPasswd'),
),
'associations' => array(
'groups' => array('resource' => 'group'),
)
);
If you have access to the server installation, you could add the date_add field to the webserviceParameters.
Or the function getWebserviceObjectList to change the behavour.
If you don't have access to the server installation, you can use the sort to get the latest customers until you reach the one you already have. You can use with limit to use in a foreach or while loop.
EDIT After some testing and inspecting what was going on:
First, it's we don't need to add the field date_add to the $webserviceParameters.
The request should be:
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$begin.','.$finish.']',
'date' => 1,
'display' => 'full',
'output_format' => 'JSON'
);
If you only add one date to the filter it will try to match only that date.
Then you need to change the PSWebServiceLibrary.php in line 284 and add the field 'date':
$params = array('filter', 'display', 'sort', 'limit', 'id_shop', 'id_group_shop', 'date');
Now it should work. I tested myself.
EDIT 2:
This is my full test, after changing the the line i mentioned in PSWebserviceLibrary.php, this retrieves my customers with date_add in the interval date.
<?php
require_once( 'PSWebServiceLibrary.php' );
echo 'starting<br />'.PHP_EOL;
try {
// creating web service access
$webService = new PrestaShopWebservice(MY_BASE_URL, WS_KEY, true);
$yesterday = date("Y-m-d", time() - 60 * 60 * 24);
$begin = date("Y-m-d", time() - 60 * 60 * 24 * 30);
$opt = array( 'resource' => 'customers',
'filter[date_add]' => '['.$begin.','.$yesterday.']',
'date' => 1,
'display' => 'full',
'output_format' => 'JSON'
);
//Retrieving the XML data
$xml = $webService->get($opt);
}
catch (PrestaShopWebserviceException $ex) {
// Shows a message related to the error
echo 'Other error: <br />' . $ex->getMessage();
}
?>
first of all: thanks
I modified as your indication, but the result does not change, still gives me the same error.
protected $webserviceParameters = array(
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
'id_lang' => array('xlink_resource' => 'languages'),
'newsletter_date_add' => array(),
'ip_registration_newsletter' => array(),
'last_passwd_gen' => array('setter' => null),
'secure_key' => array('setter' => null),
'deleted' => array(),
'passwd' => array('setter' => 'setWsPasswd'),
/** inizio modifica aggiunta per il webservice */
'date_add' => array(),
/** fine della modifica */
),
'associations' => array(
'groups' => array('resource' => 'group'),
)
);
I can not understand

Create Podio App Workflows using API - PHP

I'm using Flows API to create new workflows.
API: https://developers.podio.com/doc/flows/add-new-flow-26309928
I've prepared the attributes properly (by referring the API documentation). It is not working as expected and returning an error while creating flows with effects. I was able to create a flow without any effects, ie. a null flow which does nothing. But when I tried to create flow with effects, it shows error as below.
PodioServerError: An unexpected error occurred during execution.
Below given is my code part,
$attributes = array(
'config' => array(
'conditions' => array()
),
"effects" => array(array(
"values" => array(
'attribute_id' => "comment.value",
'label' => "Comment",
'required' => true,
'substitutions' => array(),
'type' => "text",
'value' => "This is a test comment from flow"
),
'type' => "comment.create",
)),
'name' => 'Test Flow via API',
'type' => 'item.create'
);
PodioFlow::create('app', $appID, $attrib);
Any idea what could be the error or how to properly debug this?
Can you please try:
$attributes = array(
'config' => array(
'conditions' => array()
),
"effects" => array(array(
"attributes" => array(array(
'attribute_id' => "comment.value",
'label' => "Comment",
'required' => true,
'substitutions' => array(),
'type' => "text",
'value' => "This is a test comment from flow"
)),
'type' => "comment.create",
)),
'name' => 'Test Flow via API',
'type' => 'item.create'
);
The only difference is values were replaced with attributes inside effects. That was mistype in docs, sorry, it's fixed now.