Perl script with JIRA REST-API to create JIRA along with custom field - perl

We are unable to create the new ticket in Jira using REST-API via Perl script.
Note: Without custom field script successfully executing. please provide the suggestion to add a custom field in my script.
Screenshot for the custom field.
Error Message:
JIRA::REST Error[400 - Bad Request]:
- [custom_field] Field 'custom_field' cannot be set. It is not on the appropriate screen, or unknown.at copy_of_new-jira.pl line 16.
Perl Script :
#Loading the modules from a specific location such that JIRA::REST.
use JIRA::Client::Automated;
use JIRA::REST;
use Data::Dumper;
#Login details about Jira server
my $jira = JIRA::REST->new({
url => 'https://xxxxxxxx.xxxxx.com',
username => 'xxxxxxx',
password => 'xxxxxxx',
});
# Create the ticket using post function
my $issue = $jira->POST('/issue', undef, {
fields => {
project => { key => 'TIME' },
issuetype => { name => 'Task' },
summary => '20-7-2018 checking field persent or not',
description => 'test',
custom_field => { Epic Link => 'Application Framework'},
},
});

It looks like you're missing some quote marks in your fields->custom_field data structure:
# Create the ticket using post function
my $issue = $jira->POST('/issue', undef, {
fields => {
project => { key => 'TIME' },
issuetype => { name => 'Task' },
summary => '20-7-2018 checking field persent or not',
description => 'test',
custom_field => { 'Epic Link' => 'Application Framework'},
},
});
There's also a typo in summary, but presumably that doesn't matter too much.

Related

Moodle - Invalid course module ID

I am adding a folder module to a Moodle course using the API:
folder_add_instance($data, null);
I am getting the error below when running the script using CMD:
!!! Invalid course module ID !!!
I looked into the folder_add_instance() function in the library, the error is occurring when trying to get the context:
$context = context_module::instance($cmid)//$cmid = 8
i looked into the mdl_context table in Moodle database but couldn't understand the values and their relation to the error i am getting.
Will deleting the mdl_context values from the database will help? or i am missing something here?
Note that the script was working fine, until i deleted all the courses i had on Moodle using the web interface.(i deleted the category containing all the courses).
To programmatically create a module in Moodle you should use function add_moduleinfo().
Look at the example in the folder generator:
https://github.com/moodle/moodle/blob/master/mod/forum/tests/generator/lib.php#L67
Will be something like:
require_once($CFG->dirroot.'/course/modlib.php');
$foldername = 'YOUR NAME HERE';
$courseid = 12345;
$sectionnum = 0;
$course = get_course($courseid);
$moduleid = $DB->get_field('modules', 'id', array('name' => 'folder'));
$data = (object)array(
'name' => $foldername,
'intro' => '',
'display' => FOLDER_DISPLAY_PAGE,
'revision' => 1,
'showexpanded' => 1,
'files' => file_get_unused_draft_itemid(),
'visible' => 1,
'modulename' => 'folder',
'module' => $moduleid,
'section' => $sectionnum,
'introformat' => FORMAT_HTML,
'cmidnumber' => '',
'groupmode' => NOGROUPS,
'groupingid' => 0,
'availability' => null,
'completion' => 0,
'completionview' => 0,
'completionexpected' => 0,
'conditiongradegroup' => array(),
'conditionfieldgroup' => array(),
'conditioncompletiongroup' => array()
);
return add_moduleinfo($data, $course, $mform = null);
Invalid course module ID . That means moodle can find a course module record, but the cm doesn't actually exist in the course object when fetching all the course data.
What you can do to fix it is add the broken module back into a section of this course. It might be in a section that exists, then you also need to add the cmid to the sequence field. (Just add this cmid on the end of the existing sequence).
update mdl_course_modules set section=<existingsection> where id=cmid;
update mdl_course_sections set sequence='XX,YY,ZZ,cmid' where id =<existingsection>;
Then after you purge caches, you should now be able to view the module again, eg. for an assignment:
https://moodle.com/mod/assign/view.php?id=cmid

How can I embed metadata into a custom XMP field with exiftool?

Can someone please explain how to embed metadata into a custom metadata field in an MP4 file with exiftool? I've searched all the docs and it seems to be related to the config file that needs to be created. Here is what I'm working with. (I know this isnt even close, as its not doing XMP fields, but I havent found a single working example with XMP fields yet.
%Image::ExifTool::UserDefined = (
'Image::ExifTool::Exif::Main' => {
0xd001 => {
Name => 'Show',
Writable => 'string',
WriteGroup => 'IFD0',
},
);
1; #end
The command I'm trying to run is:
exiftool -config exifToolConfig -show="Lightning" /reachengine/media/mezzanines/2015/02/13/13/CanyonFlight.mp4
Running this in a linux environment.
What is the properly way to set XMP metadata on custom metadata fields via ExifTool in linux on MP4 files?
The sample exiftool config file contains a number of working examples of custom XMP tags.
Basically, it is done like this:
%Image::ExifTool::UserDefined = (
'Image::ExifTool::XMP::Main' => {
xxx => {
SubDirectory => {
TagTable => 'Image::ExifTool::UserDefined::xxx',
},
},
},
);
%Image::ExifTool::UserDefined::xxx = (
GROUPS => { 0 => 'XMP', 1 => 'XMP-xxx', 2 => 'Other' },
NAMESPACE => { 'xxx' => 'http://ns.myname.com/xxx/1.0/' },
WRITABLE => 'string',
MyNewXMPTag => { },
);
Then the command is
exiftool -config myconfig -mynewxmptag="some value" myfile.mp4

Can someone provide a php sample using nusoap/sugarcrm api to create an acct/lead in sugarcrn?

Can someone provide a sample code chunk of php using the sugarcrm API/nusoap for adding creating an acct. and then linking a lead to the acct?
I've got a sample function that adds a lead, and I can see how to create an acct, but I can't see how to tie a lead to the acct, to simulate the subpanel process in the sugarcrm acct/subpanel process.
thanks
// Create a new Lead, return the SOAP result
function createLead($data)
{
// Parse the data and store it into a name/value list
// which will then pe passed on to Sugar via SOAP
$name_value_list = array();
foreach($data as $key => $value)
array_push($name_value_list, array('name' => $key, 'value' => $value));
// Fire the set_entry call to the Leads module
$result = $this->soap->call('set_entry', array(
'session' => $this->session,
'module_name' => 'Leads',
'name_value_list' => $name_value_list
));
return $result;
}
$result = $sugar->createLead(array(
'lead_source' => 'Web Site',
'lead_source_description' => 'Inquiry form on the website',
'lead_status' => 'New',
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email1' => $_POST['email'],
'description' => $_POST['message']
));
You need to find the ID for the account and assign that ID to whatever the account_id field name is in the Lead Module. I have run into a couple things like this before and I have found it easier to go straight to the Sugar database. So, write a statement that will return the account is, for example: SELECT id WHERE something_in_the_account_table = something else;
Then you can assign that id in your $result array. I hope it helps. I didn't have any code or documentation in front of me or I would have helped more.

How distinguish between pages and applications?

Using php-sdk I obtain pages in this way:
$array = $this->instance->api(
'/' . $fb_user . '/accounts', 'GET', array('access_token' => $access_token)
);
Now var_dump($array['data']); gives me:
array (
0 =>
array (
'name' => 'my name 1',
'access_token' => '***',
'category' => 'Electronics',
'id' => '***',
),
1 =>
array (
'name' => 'my name 2',
'access_token' => '***',
'category' => 'Application',
'id' => '***',
)
Only the first item is a page, the second is an app. Any way to distinguish them or improve this snippet?
EDIT: Using the category field seems a too weak procedure.
If you don't want to rely on "category", you need to fetch informations from these ids.
Run a query for:
https://graph.facebook.com/[page_or_app_id]
Among other things, there will be field:
{
[...]
"type": "application"
]
or:
{
[...]
"type": "page"
]
To avoid long responses, you may consider Batch Requests as described:
http://developers.facebook.com/docs/reference/api/batch/ (general instruction)
Batch calls with Facebook Graph API & PHP (php examples)
Give that the category says "Application", I'd use the category property to filter with.
Alternatively, if as you say using category is too weak for you. You can use strong FQL. SELECT display_name FROM application WHERE app_id='{the id from your me/accounts}' and see if you get back an object or not.

How do I use Perl's WWW::Facebook::API to publish to a user's newsfeed?

We use Facebook Connect on our site in conjunction with the WWW::Facebook::API CPAN module to publish to our users newsfeed when requested by the user.
So far we've been able to successfully update the user's status using the following code:
use WWW::Facebook::API;
my $facebook = WWW::Facebook::API->new(
desktop => 0,
api_key => $fb_api_key,
secret => $fb_secret,
session_key => $query->cookie($fb_api_key.'_session_key'),
session_expires => $query->cookie($fb_api_key.'_expires'),
session_uid => $query->cookie($fb_api_key.'_user')
);
my $response = $facebook->stream->publish(
message => qq|Test status message|,
);
However, when we try to update the code above so we can publish newsfeed stories that include attachments and action links as specified in the Facebook API documentation for Stream.Publish, we have tried about 100 different ways without any success.
According to the CPAN documentation all we should have to do is update our code to something like the following and pass the attachments & action links appropriately which doesn't seem to work:
my $response = $facebook->stream->publish(
message => qq|Test status message|,
attachment => $json,
action_links => [#links],
);
For example, we are passing the above arguments as follows:
$json = qq|{ 'name': 'i\'m bursting with joy', 'href': ' http://bit.ly/187gO1', 'caption': '{*actor*} rated the lolcat 5 stars', 'description': 'a funny looking cat', 'properties': { 'category': { 'text': 'humor', 'href': 'http://bit.ly/KYbaN'}, 'ratings': '5 stars' }, 'media': [{ 'type': 'image', 'src': 'http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg', 'href': 'http://bit.ly/187gO1'}] }|;
#links = ["{'text':'Link 1', 'href':'http://www.link1.com'}","{'text':'Link 2', 'href':'http://www.link2.com'}"];
The above, nor any of the other representations we tried seem to work. I'm hoping some other perl developer out there has this working and can explain how to create the attachment and action_links variables appropriately in Perl for posting to the Facebook news feed through WWW::Facebook::API.
Thanks in advance for your help!
I think the problem is that your JSON string might be invalid. I was able to get it to work by just using JSON::Any to serialize a Perl data structure instead of building the JSON string manually. (WWW::Facebook::API uses JSON::Any under the hood; it would be nice if it could take a Perl data structure instead of a JSON string. I will try to submit a patch this weekend.)
use WWW::Facebook::API;
use JSON::Any;
my $j = JSON::Any->new;
my $fb = WWW::Facebook::API->new(
desktop => 0,
api_key => $api_key,
secret => $secret,
session_key => $session,
session_expires => $expires,
session_uid => $fb_uid
);
my $res = $fb->stream->publish(
message => 'Test message',
attachment => $j->objToJson(
{ name => 'Foo bar baz',
href => 'http://www.google.com/',
description => "this is a thing"
} ),
action_links => $j->objToJson(
[ { text => 'action link text',
href => 'http://www.foobar.com/'
} ] )
);
The result:
http://www.friedo.com/fb_attach.jpg