Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Fail to send http.post for creating new issue

yuval zohar June 29, 2024

Hello,

 

I'm using http REST API for creating a new issue inside my JSM space.

When I'm sending the following curl command it works:
  

curl --request POST --url 'https://my-domain.atlassian.net/rest/api/3/issue/' --user 'my-email:my-token' --header 'Accept: application/json' --header 'Content-Type: application/json' --data '{ "fields": {    "project": { "id": "10001"} ,"issuetype": {"id": "10005" },"summary": "new test","description": {"version": 1,"type": "doc","content": [{ "type": "paragraph","content": [{"type": "text","text": "this is the description test"}]}]},"assignee": {"id": "712020:ca397ef3-d08a-4a36-9bf0-6bd230252ef6"},"reporter": {"id": "712020:ca397ef3-d08a-4a36-9bf0-6bd230252ef6"}}}'

 

But when I'm trying to send it from my flutter app (FlutterFlow) it fails.
I'm using it in the following way

return http.post(

Uri.parse('https://amigo-apps.atlassian.net/rest/api/3/issue/'),

headers: <String, String>{

"Content-Type": "application/json",

"Accept": "application/json",

"Authorization": "Basic ${encoded}"},

body: jsonEncode(

<String, Object>{

"fields": {

"project": {"id": "10001"},

"issuetype": {"id": "10005"},

"summary": "hello from flutterflow",

"description": {

"version": 1,

"type": "doc",

"content": [

{

"type": "paragraph",

"content": [

{

"type": "text",

"text": "hello from flutterflow -- description"

}]}]},

"assignee": {"id": "712020:ca397ef3-d08a-4a36-9bf0-6bd230252ef6"},

"reporter": {"id": "712020:ca397ef3-d08a-4a36-9bf0-6bd230252ef6"}

}},),);}




My main problem is how to present the --user "email:token" being used inside the curl command in my app. Should it be inside the header option? ('authorization':'Basic ${base64(email:token)}) ? Should it be inside the body as a new line before the fields? 
Actually I've tried all options and failed with all. The error message I keep receiving is:


Access to XMLHttpRequest at 'https://my-domain.atlassian.net/rest/api/3/issue/' from origin 'https://ff-debug-service-frontend-pro-ygxkweukma-uc.a.run.app' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 

*I'm also tried using the atlassian flutter code inside pub.dev (https://pub.dev/packages/atlassian_apis) but it also didnt work.

Thanks,
Yuval

2 answers

1 vote
Kuan Yi Ming _ServiceRocket_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2024

Hi @yuval zohar 

It sounds like your browser's default mode to disable CORS has triggered. You will need to add the access-control-allow-origin header with your FlutterFlow proxy site's URL.

For more info on the header, you can refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin

I would presume this is a common question asked by FlutterFlow users. As I'm not familiar with it, I would suggest consulting FlutterFlow's support or community forums.

Regards
Yi Ming

yuval zohar June 29, 2024

Hi @Kuan Yi Ming _ServiceRocket_ , 

Thanks for your reply.
No sure I understsnd, is this should be defined inside my header request like this:

Map<String, String> get headers => {

"Content-Type": "application/json",

"Accept": "application/json",

"Access-Control-Allow-Origin": "*",

"Authorization": ${email:token}

};



or, inside the browser network settings? 
yuval zohar June 29, 2024

@Kuan Yi Ming _ServiceRocket_  you were right. 
It was a browser issue.
I've tested the flutter code in my android app and it worked. 

I was able to create a JSM issue from my android app by sending http request.

 

The reason I'm a bit confused is , other API requests are being sent from the browser without any issues like this..   

Anyway, thanks

0 votes
Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 29, 2024

@yuval zohar -

Welcome to the community.  ALthough I am not a technical programmer, but it is my understand that all authentications should always be a part of the header section.  If you are using your program to create issue (I am assuming it is for your customers and not yourself/agents), then your body section cannot contain the line of setting issue assignee.

Here is Atlassian REST APIs documentation in case you have not look into it yet - https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/

Lastly, have you contacted "FlutterFlow" vendor for possible technical support?

Hope this helps.

Best, Joseph Chung Yin

yuval zohar June 29, 2024

@Joseph Chung Yin Hi,

Thank you for your reply.

Unfortunately it doesnt really address my problem.
As mentioned I've also tried using the token in the header option but it didnt help.
I guess I'm doing it improper but I couldnt find any documentation or tutorial which explains what is the right way doing it with http request.

This link you've attached (https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/), contains curl examples, which worked for me as I mentioned.
So my main issue is running the http post request from flutter to JSM.

These are my attempts inside the header of my flutter code inside FlutterFlow:

Attempt 1:

String encoded = base64Url.encode(utf8.encode(email:token)); 

 

headers: <String, String>{

"Content-Type": "application/json",

"Accept": "application/json",

"Authorization": "Basic ${encoded}"},


Attempt 2:

headers: <String, String>{

"Content-Type": "application/json",

"Accept": "application/json",

"Authorization": "${email:token}"},


Attempt 3:


headers: <String, String>{

"Content-Type": "application/json",

"Accept": "application/json",

"Authorization": "Basic ${email:token}"},

Attempt 4:

headers: <String, String>{

"Content-Type": "application/json",

"Accept": "application/json",

"user": "${email:token}"},


I didnt try yet the FlutterFlow forums since it seems as a specific case of Atlassian to handle the 'user' param (email:token) with http:post request using flutter  

yuval zohar June 29, 2024

@Joseph Chung Yin  it was resolved. 
I was able to send it successfully by running the app from my android app instead from the web app using the browser.

The header being used was: '

"Authorization": "Basic ${encoded}"}",



Thanks

 

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events