Fail to send http.post for creating new issue
Asked by yuval zohar:

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"}

}},),);}



```

<br />

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


Answers:
author: Kuan Yi Ming _ServiceRocket_
body: Hi [@yuval zohar](/t5/user/viewprofilepage/user-id/5532240)

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

comments: author: yuval zohar
body: Hi [@Kuan Yi Ming _ServiceRocket_](/t5/user/viewprofilepage/user-id/5382365) ,   

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? 
```


author: yuval zohar
body: [@Kuan Yi Ming _ServiceRocket_](/t5/user/viewprofilepage/user-id/5382365) 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


author: Joseph Chung Yin
body: [@yuval zohar](/t5/user/viewprofilepage/user-id/5532240) -

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

comments: author: yuval zohar
body: [@Joseph Chung Yin](/t5/user/viewprofilepage/user-id/396739) 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}"},
```

<br />

**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}"},
```

<br />

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


author: yuval zohar
body: [@Joseph Chung Yin](/t5/user/viewprofilepage/user-id/396739) 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}"}",
```

<br />

<br />

Thanks


Tags: cloud

jira-service-management

jira-service-management-cloud