How to set Affects Version field via JIRA REST API - PHP - php

I would like to update the affects versions field via JIRA REST API. But I'm getting an error:
{"errorMessages":[],"errors":{"versions":"Affects Version/s is required."}}
I have the following code:
public function requestBug($summary, $components, $affectsVersions, $fixVersions, $assignee, $environment, $description)
{
$json = Array ( "fields" => Array (
"project" => Array( "id" => 10051),
"summary" => $summary,
"issuetype" => Array ( "name" => "Bug" ),
"components" =>Array(0 => Array("id" => $components)),
"versions" =>Array(0 =>Array("affectsVersion" => $affectsVersions)),
"versions" =>Array(0 =>Array("fixVersion" =>$fixVersions)),
"assignee" => Array("name" => "$assignee"),
"environment" => "$environment",
"description" =>$description
)
);
return $json;
}
Please assist. I came across this link, but doesnt work for me

I had the same problem and the given answer (even with links provided) did not help me much. I played around with all sorts of variations and finally this piece of JSON worked to change the affected version of an item to "Version 2.0.0":
"versions":
[
{ "Affects Version/s" : "Version 2.0.0"
},
{ "name": "Version 2.0.0"
}
]
Meta data looks like this:
"versions":{"required":true,"schema":
{"type":"array","items":"version","system":"versions"},"name":"Affects Version/s",....
Especially irritating and inconsistent is the fact that the very same field is exported by JIRA as <version>Version 2.0.0</version> in XML and for queries affectedVersion is to be used.

There are a few example of "edit issue" requests here.
You want to send a json that includes something like this:
{
"fields":
{
"versions":["1.0.0","1.1.0"],
"fixVersions":["2.0.0"]
}
}
In your code you use the key "versions" both for "Fix version(s)" and "Affected version(s)", which won't work. Also, you don't have to use additional "affectsVersion" or "fixVersion" keys.
You can also get more info about which fields you can edit and which values they allow using this REST call:
GET /rest/api/2/issue/{issueIdOrKey}/editmeta
Try it out for an issue you want to edit and it should put you on the right track. The output will also show that the "versions" key corresponds to the "Affected version(s)" field.

from jira import JIRA
auth_jira = JIRA('jira.your-oraganizsation.com', auth=('username', 'password'))
new_issue = auth_jira.create_issue(project='project_name', summary='jira_summary', description='jira_description', issuetype={'name': 'Defect'}, fields={'versions': [{'name': '1.0.0'}, {'name': '18.8.0'}] })

Related

Elasticsearch - Want to sort by field in all indices where that particular field available or not if not then avoid it

Currently, Getting result based on scoring but what i want to do is i want a result based on scoring + Field Status with value true/false.
If value is true then needed that results in priority but there is possibility that status field is not exist in all indices.
"query" => [
'bool' => [
'filter' => $filter,
'must' => [
"multi_match" => [
'query' => "$string",
"type" => "cross_fields",
'fields' => ['field1','field2','field3'],
"minimum_should_match" => "80%"
]
]
]
],
"sort" => [
"_score",
[ "status" => ["order" => "desc","unmapped_type" => "boolean"] ]
],
But getting error below :
[type] => illegal_argument_exception
[reason] => Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [status] in order to load field data by uninverting the inverted index. Note that this can use significant memory.
Anyone help me out to ignore for indices where that field not available or any other solution with this problem?
As discussed in the chat, the issue happened due to #jilesh
forget to delete the old index mapping and only upate the data that's what this thing was occurring.
Below answer is relevant when you get below error with proper setup
Text fields are not optimised for operations that require
per-document field data like aggregations and sorting, so these
operations are disabled by default. Please use a keyword field
instead. Alternatively, set fielddata=true on [status] in order to
load field data by uninverting the inverted index. Note that this can
use significant memory.
In that case, please enable the field data on the field if you want to get rid of the error but beware it can cause performance issues.
Read more about the field data on official site.
You can enable it in your order field in your mapping as shown.
{
"properties": {
"order": {
"type": "text",
"fielddata": true
}
}
}
works for me
curl -X PUT -H "Content-Type: application/json" \
-d '{"properties": {"format": { "type":"text","fielddata": true}}}' \
<your_host>:9200/<your_index>/_mapping
In my case, I had to use the aggregatable {fieldname}.keyword field. Here's an example using Nest .NET.
.Sort(s => s
.Ascending(f => f.Field1.Suffix("keyword"))
.Ascending(f => f.Field2.Suffix("keyword"))
.Ascending(f => f.Field3.Suffix("keyword")))

Passing Form-data Array from one function to another function in same controller

I have a multidimensional array containing data from a form and I need this array in another Controller in the same controller to continue working with it, but I don't know how I do that.
The array can look like this example:
array [
"absender" => "Maxim Ivan",
"email" => "maximivan#example.com",
"telefon" => "1234567890",
"fax" => null,
"grund" => "Gehaltserhöhung",
"termin" => [
0 => [
"person" => "Some Name",
"meeting" => "10.05"
],
1 => [
"person" => "Another Name",
"meeting" => "18.05"
],
2 => [
"person" => "Again another name",
"next-possible-meeting" => "1"
],
3 => [
"person" => "And again",
"next-possible-meeting" => "1"
],
],
"bemerkung" => "some notes by Maxim"
]
This array is created(and the input data validated) in the store-method of the 'TerminController'.
This method will return a view where all of this data gets displayed again, to let the user check the info and can then add a document.
When the document is added and the data gets submitted with an input-button the upload-method in the same Controller gets called.
And there's where I need the array with the form-data to go on working with it.
But how do I achieve passing the array through to the next function that is only called with an input-button.
First approach was to save the array into the session, which did even work even though it was hard due to the multidimensional; but it's a really ugly solution.
Should I save the input data into a database in the store-method and fetch it again in the upload-method?
Or is it somehow possible to pass the array through the Controllers/ make it accessible in the upload-Controller even though it gets created in another one?
I have also heard something about using serialize()and unserialize(), but I'm not exactly sure how this could help me..
Or maybe there's another and even better solution I just don't think of?
I'd appreciate all the help I can get.
The array varies, it can be 17 arrays nested in 'termin' but I can also be just one.
You can store it in the cache:
Cache::put('multiArray', $multiArray); //put array in cache
$array = Cache::get('multiArray'); //retreive from cache

How To Add Additional Field Mappings To Code Pulling from Third Party API

I am working with the Church Community Builder API (official docs, search for "group profile" to see relevant code) and with CCB Core WordPress Plugin to sync groups data from the API into custom post types (fields, taxonomies).
CCB Core maps a lot of this data automatically, but it doesn't map the group ID value CCB uses to distinguish one group from another and I'd like to sync it.
The relevant code is kept in the functions get_groups_custom_fields_map() and get_groups_taxonomy_map().
I've tried adding something like the following to get_groups_taxonomy_map():
'group_id' => array (
'api_mapping' => 'group',
'data_type' => 'integer',
),
But this doesn't work. Any suggestions on writing code to pull in this field?
UPDATE 9/10/16 7:25 PM:
I think I am wicked close.
I took the XML from the API documentation under Group Profile and ran it through simplexml and generated this output.
I then compared the output with how the get_groups_custom_fields_map and get_groups_custom_taxonomy_map was organized, which led me to believe the following should work:
'group' => array (
'api_mapping' => 'group',
'data_type' => 'object',
'child_object' => array(
'api_mapping' => '#attributes',
'data_type' => 'object',
'child_object' => array(
'group_id' => array(
'api_mapping' => 'id',
'data_type' => 'integer'
)
)
)
),
But it doesn't. What am I missing?
The SimpleXML representation of the response that comes back from CCB just so happens to have a really frustrating way of deserializing the IDs for the entities (Groups, Events, Individuals, etc) that come out of the API. (And it only happens on the IDs).
Even though Group ID looks like a property in the XML response string, it's actually an attribute which is slightly different. In your object response, notice that # symbol in the [#attributes] node. PHP will not allow direct access to that.
See "At sign" # in SimpleXML object?
As a workaround I actually obtain the Group ID like so right here:
https://github.com/jaredcobb/ccb-core/blob/1a6e88b47ad7d5293e88bac277e72cbc4e33a602/admin/class-ccb-core-sync.php#L589-L595
Code snippet of the above reference:
$group_id = 0;
foreach( $group->attributes() as $key => $value ) {
if ( $key == 'id' ) {
$group_id = (int) $value;
break;
}
}
So in general, we do have access to that group id, we just need to now save it as post meta. I'll update the plugin to take advantage of these IDs, but in the mean time you can use the $group_id variable directly and save the post meta in this function.

Store and retrieve nested JSON in DynamoDB with PHP SDK

I have created the following table in DynamoDB:
Field1: messageId / Type: String / Example value: 4873dd28-190a-4363-8299-403c535e160f
Field2: microtime / Type: Number / Example value: 14143960092414
Field3: data / Type: nested JSON-Array / Example value: {"foo":"bar","other":{"nested":1}}
I am performing the following request using PHP SDK for DynamoDB to create an entry
$raw = '{"foo":"bar","other":{"nested":1}}';
$result = $client->putItem(array(
'TableName' => 'requests2',
'Item' => array(
'messageId' => array('S' => '4873dd28-190a-4363-8299-403c535e160f'),
'microtime' => array('N' => microtime(true)*10000),
'data' => array('S' => $raw),
)
));
I want then to query the table and filter using variables within the JSON-array data field. Is my above solution to entering the data the right approach? The JSON-array gets stored as string, as to my understanding. Do we need another datatype? Basically, I can already query the table like below to retrieve messages that were added within the last minute:
$iterator = $client->getIterator('Query', array(
'TableName' => 'requests2',
'KeyConditions' => array(
'messageId' => array(
'AttributeValueList' => array(
array('S' => '4873dd28-190a-4363-8299-403c535e160f')
),
'ComparisonOperator' => 'EQ'
),
'microtime' => array(
'AttributeValueList' => array(
array('N' => strtotime("-1 minutes")*10000)
),
'ComparisonOperator' => 'GT'
)
)
));
foreach ($iterator as $item) {
echo $item['messageId']['S']." ";
}
But how can I modify my request to allow querying by ANY value within the data-field? For example, filter by only those who have [data][other][nested]=1
I've spent the past hours on this issue and I can't get it to work... I am very grateful for any tips, thanks in advance!
I know this was posted in 2014, but I was looking exactly for this answer and so I'd like to share the result in my search to anyone that will land on this question in the future.
Best practice is to store a JSON as a string, but use a Marshaler object to turn the JSON into something that DynamoDB can digest, and that you will be able to query too:
Using marshalJSON method you turn a JSON, as you can see described in this amazon link
For the ones that are looking for a quick example, I add here below the key parts of the procedure:
If you have a JSON like the following
{
"id": "5432c69300594",
"name": {
"first": "Jeremy",
"middle": "C",
"last": "Lindblom"
},
"age": 30,
"phone_numbers": [
{
"type": "mobile",
"number": "5555555555",
"preferred": true
},
{
"type": "home",
"number": "5555555556",
"preferred": false
}
]
}
stored in a string variable $json, you can simply do
use AwsDynamoDbDynamoDbClient;
use AwsDynamoDbMarshaler;
$client = DynamoDbClient::factory(/* your config */);
$marshaler = new Marshaler();
$client->putItem([
'TableName' => 'YourTable',
'Item' => $marshaler->marshalJson($json)
]);
I don't think AWS PHP SDK for DynamoDB has yet implemented the support for JSON based document storage. Their recent notification published on their blog on 8th October 2014, mentions about the support of this new feature only in Java, .NET, Ruby and JS SDK.

ChargeBee - PHP create subscription breaks PHP loading the page

Working on a Chargebee integration, using their suggest PHP library.
I have the include statement at the top of the page, to include the library.
And I set the environment variables with test server information copy-pasted from the control panel.
No matter what I try, when I use their sample code, my page load breaks and I get a white screen. Without this block of code, the page loads fine and all dbase calls works perfectly.
Is there more to know about the Chargebee library that I'm not catching?
(in the top of the php)
include("/app/includes/chargebee-php-master/lib/ChargeBee.php");
ChargeBee_Environment::configure("SERVERNAME-test",
"test_KEYFROMCONTROLPANEL");
(inline code in a function)
$result = ChargeBee_Subscription::create(array(
"planId" => "pond_ripple",
"customer" => array(
"email" => "john#user.com",
"firstName" => "John",
"lastName" => "Doe",
"phone" => "+1-949-999-9999"
),
"billing_address" => array(
"firstName" => "John",
"lastName" => "Doe",
"line1" => "PO Box 9999",
"city" => "Walnut",
"state" => "CA",
"zip" => "91789",
"country" => "US"
)
));
$subscription = $result->subscription();
$customer = $result->customer();
$card = $result->card();
$invoice = $result->invoice();
$sampleString = $customer["id"];
Is your include path correct?
include("/app/includes/chargebee-php-master/lib/ChargeBee.php");
Can you crosscheck whether it starts from a base directory? ie. /app/includes/chargebee-php-master/lib/ChargeBee.php or is it relative? i.e app/includes/chargebee-php-master/lib/ChargeBee.php
If your path is right (full path), can you provide the error log to debug further? Also you need to access ChargeBee customer object as $customer->id and not as an array.

Categories