trying to create jira ticket with python - jira-rest-api

here below a piece of code I wrote that should create a jira ticket on my jira domain.
I created a personal token but for some reason it doesnt work...
from pprint import pprint
import requests
import json
from requests.auth import HTTPBasicAuth
TOKEN = "KAJSF21DKSAH1KJHFSAN912"
url = "https://cxscompany.jira.com/rest/api/2/"
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer " + TOKEN
}
payload = json.dumps(
{
"fields": {
"project":
{
"key": "AUT"
},
"summary": "summary mike",
"description": "description mike",
"issuetype": {
"name": "Task"
}
}
}
)
response = requests.post(url, headers=headers, data=payload)
pprint(response)
I expect a ticket to be created in my jira domain, but I get this error:
SSLError: HTTPSConnectionPool(host='cxscompany.jira.com', port=443): Max retries exceeded with url: /rest/api/latest/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1125)')))

Related

Trying to run Automation Anywhere import API through Power Automate Cloud Flow

Have anyone tried to run Automation Anywhere A360 import API with HTTP Post action with Power Automate Flow?
The flow runs smoothly and I'm receiving the requestId in response. However, the whole action fails at the Automation Anywhere Control Room side with no imported bot at the end. I'm receiving the following error: net.lingala.zip4j.exception.ZipException: Zip headers not found. Probably not a zip file?
Power Automate HTTP Post - Body
I added below code to the Http Post Body:
{
"$content-type": "multipart/form-data",
"$multipart": [
{
"headers": {
"Content-Type": "application/x-zip-compressed",
"Content-Disposition": "form-data; name=\"upload\"; filename=\"#{variables('fullPath')}\""
},
"body": "#{variables('contentString')}"
},
{
"headers": {
"Content-Disposition": "form-data; name=\"actionIfExisting\""
},
"body": "OVERWRITE"
},
{
"headers": {
"Content-Disposition": "form-data; name=\"publicWorkspace\""
},
"body": "true"
},
{
"headers": {
"Content-Disposition": "form-data; name=\"upload\""
},
"body": "#{variables('fullPath')}"
}
]
}
The contentString variable is: #{body('Get_file_content_using_path')?['$content']}
What am I doing wrong?

Question about ASP.NET Core 3 Identity / Identity Server / SPA support for Resource Owner Password Grant Type

As per Authentication and authorization for SPAs, I have created a new SPA with support for API authorization. You can view this on GitHub.
In order to support integration tests, I have added a new client (see appsettings.json) that is allowed the resource owner password grant type:
"SecureSpa.IntegrationTests": {
"Profile": "IdentityServerSPA",
"AllowedGrantTypes": [ "password" ],
"ClientSecrets": [ { "Value": "K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=" } ],
"AllowedScopes": [ "SecureSpaAPI", "openid", "profile" ]
}
Then within WeatherForecastControllerTests.cs, I attempt to request the token as follows:
var response = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
{
Address = disco.TokenEndpoint,
ClientId = "SecureSpa.IntegrationTests",
ClientSecret = "secret",
Scope = "SecureSpaAPI openid profile",
UserName = "demouser#securespa",
Password = "Pass#word1"
});
When running the test, I've tried many different combinations, however the results are usually the same (unauthorized_client). This is the relevant log output from Identity Server:
IdentityServer4.Endpoints.TokenEndpoint: Debug: Start token request.
IdentityServer4.Validation.ClientSecretValidator: Debug: Start client validation
IdentityServer4.Validation.BasicAuthenticationSecretParser: Debug: Start parsing Basic Authentication secret
IdentityServer4.Validation.PostBodySecretParser: Debug: Start parsing for secret in post body
IdentityServer4.Validation.SecretParser: Debug: Parser found secret: PostBodySecretParser
IdentityServer4.Validation.SecretParser: Debug: Secret id found: SecureSpa.IntegrationTests
IdentityServer4.Stores.ValidatingClientStore: Debug: client configuration validation for client SecureSpa.IntegrationTests succeeded.
IdentityServer4.Validation.ClientSecretValidator: Debug: Public Client - skipping secret validation success
IdentityServer4.Validation.ClientSecretValidator: Debug: Client validation success
IdentityServer4.Events.DefaultEventService: Information: {
"Name": "Client Authentication Success",
"Category": "Authentication",
"EventType": "Success",
"Id": 1010,
"ClientId": "SecureSpa.IntegrationTests",
"AuthenticationMethod": "SharedSecret",
"ActivityId": "0HLPN4PPDDMCJ",
"TimeStamp": "2019-09-12T02:10:57Z",
"ProcessId": 28948,
"LocalIpAddress": "unknown",
"RemoteIpAddress": "unknown"
}
IdentityServer4.Validation.TokenRequestValidator: Debug: Start token request validation
IdentityServer4.Validation.TokenRequestValidator: Debug: Start resource owner password token request validation
IdentityServer4.Validation.TokenRequestValidator: Error: Client not authorized for resource owner flow, check the AllowedGrantTypes setting{ client_id = SecureSpa.IntegrationTests }, details: {
"ClientId": "SecureSpa.IntegrationTests",
"ClientName": "SecureSpa.IntegrationTests",
"GrantType": "password",
"Raw": {
"grant_type": "password",
"username": "demouser#securespa",
"password": "***REDACTED***",
"scope": "SecureSpaAPI",
"client_id": "SecureSpa.IntegrationTests",
"client_secret": "***REDACTED***"
}
}
IdentityServer4.Events.DefaultEventService: Information: {
"Name": "Token Issued Failure",
"Category": "Token",
"EventType": "Failure",
"Id": 2001,
"ClientId": "SecureSpa.IntegrationTests",
"ClientName": "SecureSpa.IntegrationTests",
"Endpoint": "Token",
"GrantType": "password",
"Error": "unauthorized_client",
"ActivityId": "0HLPN4PPDDMCJ",
"TimeStamp": "2019-09-12T02:10:57Z",
"ProcessId": 28948,
"LocalIpAddress": "unknown",
"RemoteIpAddress": "unknown"
}
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 212.96790000000001ms 400 application/json; charset=UTF-8
Is this approach supported? If not, is there an alternative approach that can be used to get the token in order to write integration tests? I'm planning to set up test users along with the test client so that I can test lots of different behaviours.
I continued working on this issue and found that the allowed grant type of password was not being added when the profile is set to IdentityServerSPA. I couldn't see a way to add a client without a profile via appsettings, so I removed the configuration from appsettings and created the clients using this approach:
services.AddIdentityServer()
//.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>(options =>
{
options.Clients.AddIdentityServerSPA("SecureSpa", builder =>
{
builder.WithRedirectUri("https://localhost:44307/authentication/login-callback");
builder.WithLogoutRedirectUri("https://localhost:44307/authentication/logout-callback");
});
options.Clients.Add(new Client
{
ClientId = "SecureSpa.IntegrationTests",
AllowedGrantTypes = { GrantType.ResourceOwnerPassword },
ClientSecrets = { new Secret("secret".Sha256()) },
AllowedScopes = { "SecureSpaAPI", "openid", "profile" }
});
});
With that in place my tests now run. You can see the final solution here; https://github.com/JasonGT/SecureSpa/.
Everything works fine, however there seems to be a bug (or feature limitation) within DefaultClientRequestParametersProvider. See the 'GetClientParameters' method - if the specified client does not have an associated profile, an InvalidOperationException is thrown.
Let me know if you need more information.
Just for reference' sake: the code above did not work as-is on my end, it broke the SPA sign-in with a redirect_uri invalid exception.
I had to remove the base url, and then it worked:
builder.WithRedirectUri("/authentication/login-callback");
builder.WithLogoutRedirectUri("/authentication/logout-callback");

Flutter send notificiation from client app with curl

I'm trying to send a notification from flutter application directly, but I can not figure it out how to do it.
Everywhere they say have to send a curl request with basic network library but there is no example.
DATA='{"notification": {"body": "this is a body","title": "this is a title"}, "priority": "high", "data": {"click_action": "FLUTTER_NOTIFICATION_CLICK", "id": "1", "status": "done"}, "to": "<FCM TOKEN>"}'
curl https://fcm.googleapis.com/fcm/send -H "Content-Type:application/json" -X POST -d "$DATA" -H "Authorization: key=<FCM SERVER KEY>"
Please help me with an example in DART.
You could try this:
import 'dart:async';
import 'dart:convert' show Encoding, json;
import 'package:http/http.dart' as http;
class PostCall {
final postUrl = 'https://fcm.googleapis.com/fcm/send';
final data = {
"notification": {"body": "this is a body", "title": "this is a title"},
"priority": "high",
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"id": "1",
"status": "done"
},
"to": "<FCM TOKEN>"
};
Future<bool> makeCall() async {
final headers = {
'content-type': 'application/json',
'Authorization': 'key=<FCM SERVER KEY>'
};
final response = await http.post(postUrl,
body: json.encode(data),
encoding: Encoding.getByName('utf-8'),
headers: headers);
if (response.statusCode == 200) {
// on success do sth
return true;
} else {
// on failure do sth
return false;
}
}
}

How to create a webhook on a repository on the GitHub web api using AJAX?

I am experimenting with Webhooks in the GitHub api. I got one working by doing it manually as in going into my repository and clicking into the setting and enabling a web hook. But now I want to do this in AJAX and I am getting problems. Anytime I try to send a POST to the web api it fails with a 400 (Bad Request). I am not sure where I am going wrong with my code.
function createWebHooksOnRepos(token){
const webhookURL = "https://api.github.com/repos/DanoBuck/AlgorithmsAndDataStructures/hooks";
const json = {
"name": "WebHook",
"active": true,
"events": [
"issue_comment",
"issues"
],
"config": {
"url": "http://39a40427.ngrok.io/api/webhooks/incoming/github",
"content_type": "json"
}
};
$.ajax({
headers: {
"Authorization": "Token " + token
},
url: webhookURL,
data: json,
type: "POST",
dataType: "json",
success: function(data){
console.log(data);
}
});
}
Thank you
From github Webhook API doc :
name - string - Required. Use "web" for a webhook or use the name of a valid
service. (See /hooks for the list of valid service names.)
So in your case, just rename Webhook to web :
const json = {
"name": "web",
"active": true,
"events": [
"issue_comment",
"issues"
],
"config": {
"url": "http://39a40427.ngrok.io/api/webhooks/incoming/github",
"content_type": "json"
}
};
Also JSON.stringify your data before sending :
$.ajax({
headers: {
"Authorization": "Token " + token
},
url: webhookURL,
data: JSON.stringify(json),
type: "POST",
dataType: "json",
success: function(data) {
console.log(data);
}
});

Google QPX Express API with Python

Here is the code I write for getting the flight price information by using Google QPX Express API from Python:
import urllib2
import json
url = "https://www.googleapis.com/qpxExpress/v1/trips/search?key=AIzaSyBH_S3LDUQWmQtbXyExUShtUSI8MmxObfY"
code = {
"request": {
"passengers": {
"kind": "qpxexpress#passengerCounts",
"adultCount": 1,
},
"slice": [
{
"kind": "qpxexpress#sliceInput",
"origin": "DCA",
"destination": "NYC",
"date": 2014-11-20,
}
],
"refundable": False,
"solutions": 5
}
}
jsonreq = json.dumps(code, encoding = 'utf-8')
req = urllib2.Request(url, jsonreq, {'Content-Type': 'application/json'})
flight = urllib2.urlopen(req)
response = flight.read()
flight.close()
print(flight)
It always give me the error of urllib2.HTTPError: HTTP Error 400: Bad Request. I really can't figure out what to do.
Related: QPX Express API from Python
You're almost there! Just a few minor errors:
The date needs to be quoted
False is written in lowercase in json: false, so you'll need to quote it in Python
No commas before close-bracket (OK in Python, but better to follow json conventions)
print(response), not print(flight)
also, it's generally a bad idea to publish your API key in a forum!
This gives:
import urllib2
import json
url = "https://www.googleapis.com/qpxExpress/v1/trips/search?key=XXX"
code = {
"request": {
"passengers": {
"kind": "qpxexpress#passengerCounts",
"adultCount": 1,
},
"slice": [
{
"kind": "qpxexpress#sliceInput",
"origin": "DCA",
"destination": "NYC",
"date": "2015-11-20",
}
],
"refundable": "false",
"solutions": 5
}
}
jsonreq = json.dumps(code, encoding = 'utf-8')
req = urllib2.Request(url, jsonreq, {'Content-Type': 'application/json'})
flight = urllib2.urlopen(req)
response = flight.read()
flight.close()
print(response)
By the way, to get the best responses, you should probably ask for more than 5 solutions. QPX Express tries to return a variety of answers (e.g., different times, different airlines, etc.) so if you want to have your own selection of the best trade-off of qualities, you probably want to examine more solutions.