I'm trying to set a custom field of type Multiselect via JIRA rest API using php. For reason I'm getting the following error:
{"errorMessages":[],"errors":{"Functionality Impacted":"expected 'value' property to be a string"}}
I have the following code for setting the custom field:
public function requestRemedy($summary, $description, $priority, $goliveDate,$startTime,
$endTime,$clientImpact,$impactedFunctionality,$fundTransfers ,$fieldAffected, $remedyChangeType,
$changeReason,$remedyImpact, $urgency,$riskLevel,$nameRequestor,$emailRequestor)
{
$json = Array ( "fields" => Array (
"project" => Array
( "id" => 10051 ),
"summary" => $summary,
"description" =>$description,
"issuetype" => Array ( "name" => "Remedy Change Management" ),
"priority" => Array("id" => $priority),
"customfield_13774" => $goliveDate,
"customfield_14408" => "$startTime",
"customfield_14409" => "$endTime",
"customfield_14412" => "$clientImpact",
"customfield_14908" =>Array ( 0 => Array(
"value" => ($impactedFunctionality),
)),
"customfield_14414" => Array("id" =>$fundTransfers),
// "customfield_14415" =>Array("id" => $businessOnline,"child" =>Array("id" => $businessDependency) ),
"customfield_14602" => Array("id" =>$fieldAffected),
"customfield_14422" => Array("id" =>$remedyChangeType),
"customfield_14423" => Array("id" =>$changeReason),
"customfield_14424" => Array("id" =>$remedyImpact),
"customfield_14425" => Array("id" =>$urgency),
"customfield_14426" => Array("id" =>$riskLevel),
"customfield_14700"=>$nameRequestor,
"customfield_14702"=>$emailRequestor
)
);
return $json;
}
After adding some dummy data to test the final structure of json, I get the following result:
{
"fields": {
"project": {
"id": 10051
},
"summary": "Test",
"description": "Human DeSC",
"issuetype": {
"name": "Remedy Change Management"
},
"priority": {
"id": "2"
},
"customfield_13774": "2016-11-08",
"customfield_14408": "2016-11-01T07:35:00.000+0200",
"customfield_14409": "2016-11-01T08:35:00.000+0200",
"customfield_14412": "cLIENT iMPACT",
"customfield_14908": [{
"value": ["Savings Accounts", "Current Accounts", "Call Deposits"]
}],
"customfield_14414": {
"id": "13647"
},
"customfield_14602": {
"id": "14022"
},
"customfield_14422": {
"id": "13712"
},
"customfield_14423": {
"id": "13718"
},
"customfield_14424": {
"id": "13722"
},
"customfield_14425": {
"id": "13726"
},
"customfield_14426": {
"id": "13730"
},
"customfield_14700": "Pastor Dan",
"customfield_14702": "email#time.com"
}
}
Which means the issue is here:
"customfield_14908": [{
"value": ["Savings Accounts", "Current Accounts", "Call Deposits"]
}],
the expected structure is:
"customfield_10008": [ {"value": "Savings Accounts" }, {"value": "Current Accounts" }, {"value": "Call Deposits" }]
Now I'm not sure how to build this using an associative array
The custom field I'm trying to set is customfield_14908. What I'm finding weird is that I used similar code for setting a multiselect field on JIRA version 7.2.1 and it works well, but not working on JIRA version 7.0.
Related
Im integrating with authorize.net and process credit card transactions. I have the charge working fine for processing direct credit card payment :
$authnet_info = array(
'createTransactionRequest' => array(
'merchantAuthentication' => array(
'name' => ######,
'transactionKey' => #######
),
'refId' => $data['reference_id'],
'transactionRequest' => array(
'transactionType' => 'authCaptureTransaction',
'amount' => $data['charge_amount'],
'payment' => array(
'creditCard' => array(
'cardNumber' => $data['cc_number'],
'expirationDate' => $data['cc_expiration'],
"cardCode" => $data['cvc']
)
),
'customer' => array(
'type' => 'business',
'id' => $data['id_company']
),
'billTo' => array(
"firstName" => $data['first_name'],
"lastName" => $data['last_name'],
'company' => $data['company_name'],
"address" => $data['address'],
"city" => $data['city'],
"state" => $data['state'],
"zip" => $data['zipcode']
),
"transactionSettings" => array (
"setting" => array (
array(
"settingName" => "duplicateWindow",
"settingValue" => "5"
)
)
)
)
)
);
This works just fine however when i try to pass the same setting
"transactionSettings" => array (
"setting" => array (
array(
"settingName" => "duplicateWindow",
"settingValue" => "5"
)
)
)
For charging against a payment profile i get the following error:
(
[code] => E00003
[text] => The element 'transactionRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'transactionSettings' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'subsequentAuthInformation, otherTax, shipFrom, authorizationIndicatorType' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.
)
Here is the post i am sending to authorize.net
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "######",
"transactionKey": "##########"
},
"refId": "62",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "25.00",
"profile": {
"customerProfileId": "1231231",
"paymentProfile": {
"paymentProfileId": "34534534534"
}
},
"customer": {
"type": "business",
"id": 5
},
"processingOptions": {
"isSubsequentAuth": "false"
},
"transactionSettings": {
"setting": [{
"settingName": "duplicateWindow",
"settingValue": "5"
}]
}
}
}
}
When i remove the transaction settings part of my post the charge goes through fine. Does anyone know where this setting needs to be placed? Their documentation clearly states in this location that i am placing however im not sure why it wont go through.
Edit: I tried the method mentioned below and received the same error:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "#####",
"transactionKey": "#######dfsd"
},
"refId": "62",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "25.00",
"profile": {
"customerProfileId": "502810352",
"paymentProfile": {
"paymentProfileId": "511258154"
}
},
"customer": {
"type": "business",
"id": 5
},
"processingOptions": {
"isSubsequentAuth": "false"
}
},
"transactionSettings": {
"setting": [{
"settingName": "duplicateWindow",
"settingValue": "5"
}]
}
}
}
EDIT: i answered the question apparently i had a extra setting within the request that doesnt need to be present
Ok so i figured out the issue for anyone else facing the same problem. The issue seemed to be the
"processingOptions": {
"isSubsequentAuth": "false"
}
setting within the request. I guess it not valid with the transactionsetting being present.
I ended up passing the following request and it worked fine
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "#####",
"transactionKey": "######"
},
"refId": "62",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "25.00",
"profile": {
"customerProfileId": "sdfsdf",
"paymentProfile": {
"paymentProfileId": "51sdfsdf1258154"
}
},
"customer": {
"type": "business",
"id": 5
},
"transactionSettings": {
"setting": [{
"settingName": "duplicateWindow",
"settingValue": "5"
}]
}
}
}
}
I add a new contact API - send POST, according to the example below.
https://intranet_name.bitrix24.com/rest/crm.contact.add?auth=authentication_code&fields[NAME]=Maria&fields[SECOND_NAME]=Anna&fields[LAST_NAME]=Nowacka
It adds correctly, works.
I can not deal with the addition of the PHONE array, how to do it?
<script type="text/javascript">
BX24.callMethod(
"crm.contact.add",
{
fields:
{
"NAME": "John",
"SECOND_NAME": "Lancelot",
"LAST_NAME": "Doe",
"OPENED": "Y",
"ASSIGNED_BY_ID": 1,
"TYPE_ID": "CLIENT",
"SOURCE_ID": "SELF",
"PHOTO": { "fileData": document.getElementById('photo') },
"PHONE": [ { "VALUE": "555888", "VALUE_TYPE": "WORK" } ]
},
params: { "REGISTER_SONET_EVENT": "Y" }
},
function(result)
{
if(result.error())
console.error(result.error());
else
console.info("Created a new contact; ID=" + result.data());
}
);
OAuth 2.0 Protocol API documentation
I changed to uURL, it works.
You had to add a square bracket.
$data = array(
"fields" => array(
"NAME" => "Nowy2",
"LAST_NAME" => "Testowy1",
"ADDRESS" => "NowodÄ…browska 45",
"ADDRESS_POSTAL_CODE" => "54-345",
"ADDRESS_CITY" => "Warszawa",
"ADDRESS_COUNTRY" => "Polska",
"TYPE_ID" => "CLIENT",
"PHONE" => array([
"VALUE" => 994556765,
"VALUE_TYPE" => "WORK"]
)
)
);
I have been trying to solve my problem for days, but without getting the desidred result. Here's a particular structure for a JSON file:
{
"detections": {
"timestamp": "12/04/2016/ 20:25:00",
"rooms": [
{
"name": "r1",
"sensors": [
{
"id": 10,
"type": "rad",
"value": 100,
"valMax": 600,
"valMin": 100
},
{
"id": 12,
"type": "temp",
"value": 30.5,
"valMax": 1000,
"valMin": 0
}
]
},
{
"name": "r2",
"sensors": [
{
"id": 20,
"type": "temp",
"value": 20.7,
"valMax": 1000,
"valMin": 0
},
{
"id": 15,
"type": "rad",
"value": 800,
"valMax": 600,
"valMin": 100
}
]
}
]
}
}
I must encode with that structure data that I've retrieved from MySQL Database.
It consists of three tables linked with foreign key constraints. Now, the code I've written for this is the following:
while($row = mysqli_fetch_array($result)) {
array_push($detections, array("timestamp"=>$row['timestamp'],
"rooms"=>array("name"=>$row['name'],
"sensors"=>array("id"=>$row['id'], "type"=>$row['type'], "value"=>$row['value'], "valMin"=>$row['valMin'],
"valMax"=>$row['valMax']))
));
}
But it gives me this result:
{
"detections": [{
"timestamp": "2016-09-10 17:59:06",
"rooms": {
"name": "Stanza dei Giochi",
"sensors": {
"id": "1",
"type": "prova2",
"value": "12",
"valMin": "1",
"valMax": "12"
}
}
}, {
"timestamp": "2016-09-11 00:41:21",
"rooms": {
"name": "Stanza dei Giochi",
"sensors": {
"id": "1",
"type": "prova2",
"value": "21",
"valMin": "1",
"valMax": "12"
}
}
}, {
"timestamp": "2016-09-10 19:59:20",
"rooms": {
"name": "Stanza dei Giochi",
"sensors": {
"id": "3",
"type": "prova",
"value": "13",
"valMin": "11",
"valMax": "13"
}
}
}, {
"timestamp": "2016-09-11 00:41:21",
"rooms": {
"name": "Stanza dei Giochi",
"sensors": {
"id": "3",
"type": "prova",
"value": "23.5",
"valMin": "11",
"valMax": "13"
}
}
}]
}
which is similar but not the same :/
As I've noticed from the JSON structure I would get, detections with the same timestamp but with different rooms, sensors and values are collected together... but I don't know how to realize that.
Hope y'all can give me a hand, thanks >.<
You are building your array wrong to achieve that structure.
To achieve the desired structure your array needs to look like this
<?php
array (
'detections' =>
array (
'timestamp' => '12/04/2016/ 20:25:00',
'rooms' =>
array (
0 =>
array (
'name' => 'r1',
'sensors' =>
array (
0 =>
array (
'id' => 10,
'type' => 'rad',
'value' => 100,
'valMax' => 600,
'valMin' => 100,
),
1 =>
array (
'id' => 12,
'type' => 'temp',
'value' => 30.5,
'valMax' => 1000,
'valMin' => 0,
),
),
),
1 =>
array (
'name' => 'r2',
'sensors' =>
array (
0 =>
array (
'id' => 20,
'type' => 'temp',
'value' => 20.699999999999999,
'valMax' => 1000,
'valMin' => 0,
),
1 =>
array (
'id' => 15,
'type' => 'rad',
'value' => 800,
'valMax' => 600,
'valMin' => 100,
),
),
),
),
),
);
Check also check json_decode and json_encode
I've got a request to present the data in the following format as a JSON feed:
{
"id": "123",
"info": {
"code": "ZGE",
"description": "test1",
"type": "AVL",
"date": "09/08/2012"
}
},
{
"id": "456",
"info": {
"code": "ZDN",
"description": "test2",
"type": "CLR",
"date": "16/02/2012"
}
}
However in my PHP code, I think I need to have a key itterator - but I end up with this format:
{
"0": {
"id": "123",
"info": {
"code": "ZGE",
"description": "test1",
"type": "AVL",
"date": "09/08/2012"
}
},
"1": {
"id": "456",
"info": {
"code": "ZDN",
"description": "test2",
"type": "CLR",
"date": "16/02/2012"
}
}
}
Any ideas on how to build the first data set with out having the index iterator?
simple create an array of objects, no need for the key (notice the [ ] surrounding your list)
json.txt
[{
"id": "123",
"info": {
"code": "ZGE",
"description": "test1",
"type": "AVL",
"date": "09/08/2012"
}
},
{
"id": "456",
"info": {
"code": "ZDN",
"description": "test2",
"type": "CLR",
"date": "16/02/2012"
}
}]
example.php
<?php
$data = json_decode(file_get_contents('./json.txt'));
?>
It can be built like this:
$arr = array(
array(
'id' => 123,
'info' => array(
'code' => 'ZGE',
'description' => 'test1',
'type' => 'AVL'
)
),
array(
'id' => 456,
'info' => array(
'code' => 'ZDN',
'description' => 'test2',
'type' => 'CLR'
)
)
);
echo json_encode($arr);
Outputs
[
{
"id": 123,
"info": {
"code": "ZGE",
"description": "test1",
"type": "AVL"
}
},
{
"id": 456,
"info": {
"code": "ZDN",
"description": "test2",
"type": "CLR"
}
}
]
the JSON format you've specified in the first example (ie the requested format) is not valid JSON.
A valid JSON string must evaluate to a single Javascript object; the example you've given evaluates to two Javascript objects, separated by a comma. In order to make it valid, you would need to either enclose the whole thing in square brackets, to turn it into a JS array or enclose it in curly braces, and give each of the two objects a key.
The PHP code you've written is doing the second of these two options. It is therefore generating valid JSON code, about as close to the original request as could be expected while still being valid.
It would help if you'd shown us the PHP code that you've used to do this; without that, I can't really give you advice on how to improve it, but if you want to switch to the square bracket notation, all you need is to put your PHP objects into an unkeyed array, and json_encode() should do it all for you; you shouldn't need to use a keyed array or an iterator for that.
The only reason json_encode should produce the output you're seeing is adding another named key to the array that you're passing to json_encode, by default it should work as you want:
$json = '[
{
"id": "123",
"recall_info": {
"code":"ZGE",
"description": "test1",
"type": "AVL",
"date": "09/08/2012"
}
},
{
"id": "123",
"recall_info": {
"code": "ZDN",
"description": "test2",
"type": "CLR",
"date": "16/02/2012"
}
}
]';
$php = array(
(object) array(
'id' => '123',
'recall_info' => (object) array(
'code' => 'ZGE',
'description' => 'test1',
'type' => 'AVL',
'date' => '09/08/2012'
)
),
(object) array(
'id' => '123',
'recall_info' => (object) array(
'code' => 'ZGE',
'description' => 'test2',
'type' => 'CLR',
'date' => '16/02/2012'
)
)
);
var_dump(json_encode($php));
Forgive my terminology im a newbie in in web dev.
To visualize my question, see below.
This is how RESTLER displays json:
[
{
"id": 1,
"name": "Daniel Craig",
"email": "dc#gmail.com"
},
{
"id": 2,
"name": "Tom Cruise",
"email": "tc#gmail.com"
}
]
This is how i would want RESTLER to display json results:
{"actors":[
{
"id": 1,
"name": "Daniel Craig",
"email": "dc#gmail.com"
},
{
"id": 2,
"name": "Tom Cruise",
"email": "tc#gmail.com"
}
]}
Just wrap your result with another array. if we assume that $result returns the first result above, do the following
$result = array(
array(
"id" => 1,
"name" => "Daniel Craig",
"email" => "dc#gmail.com"
),
array(
"id" => 2,
"name" => "Tom Cruise",
"email" => "tc#gmail.com"
)
);
return array('actors'=>$result);