API call in Flutter (dart) - api

I have built one asp.net web api for my angular application which is working fine. I'm going to use same api in Flutter but surprisingly I'm not getting full object in response.body. I observed that, response.body is containing only 1023 chars.
final response = await http.post(
apiUrl,
body: body,
headers: {
'Content-Type': 'application/json;',
'Accept': 'application/json ',
'Authorization': 'Bearer $_token',
});
print(response.body) // response.body string length is 1023.
Thank in advance looking at my issue.

i had a similar issue it seems that print has a char limit to unlock use this change number to match ur response chars or just set a higher number and use printWrapped (response.body); instead
void printWrapped(String text) {
final pattern = new RegExp('.{1,800}'); // 800 is the size of each chunk
pattern.allMatches(text).forEach((match) => print(match.group(0)));
}

Related

github API check_runs returning 415, "Unsupported Media Type"

really that simple, making a request with github api: https://docs.github.com/en/rest/reference/checks#list-check-runs-for-a-git-reference
I am trying to find the check runs for a particular branch I have. Below is the url I GET from:
url = ...api/v3/repos/{repo_fullname}/commits/{branch}/check-runs'
Here are my headers:
headers = {
'Authorization': 'token ' + token,
"Accept": "application/vnd.github.v3+json"
}
I get hit with the: 415 Client Error: Unsupported Media Type for url...
Please help, been banging my head for hours. Thanks!
Perhaps you could try a different accept? I work with octokit for node and this fixed my problem, maybe it would help in this case.
headers = {
'Authorization': 'token ' + token,
"Accept": "application/vnd.github.antiope-preview+json"
}

Http with token in Ionic 4

(Sorry for my bad english) I have to access an api, with a token that they have provided me. My problem is that I don't know how to implement it, after searching and searching, it gives me the following error:
Access to XMLHttpRequest at 'https://www.presupuestoabierto.gob.ar/api/v1/credito' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
I pass my code to you, to indicate that it is wrong in the definition of the token (the x instead of the token) and eventually in the CORS policy, thank you very much!
const headers = { 'Authorization': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'http://localhost:8100'}
this.http.get<any>('https://www.presupuestoabierto.gob.ar/api/v1/credito', { headers }).subscribe(data => {
this.datos = data.blabla;
})
Headers should pass like this in Ionic- Angular. Make sure that you have a service file.Visit this link to know more about services:
https://angular.io/tutorial/toh-pt4
let headers = new Headers({
'Content-Type' : 'application/json',
'Auth':authvalue
});
return this.http.get(url,options).pipe(map(res => res.json()));

How can I properly send a batch request using UCWA 2.0?

I am writing a UCWA application to receive each user's presence and note. At the moment, I subscribe to all my desired contacts, I initiate my event stream and then I receive around 200 events. I loop through them to receive my contacts presence and notes using a for loop, meaning I send around 100 requests, which, according to Microsoft documentation, can drain battery on mobile devices or impact performance. I would like to use batching to fix this problem.
onEvent(events) {
for (var i in events) {
const event = events[i]
switch (event.link.rel) { // 250 events filtered down to around 100
case 'contactPresence':
case 'presence':
this.setPresence(event.link.href, this.getUser(event))
break
case 'contactNote':
case 'note':
this.setNote(event.link.href, this.getUser(event))
break
case 'presenceSubscription':
...
break
}
}
}
After searching through Microsoft's documentation, I couldn't find any help on how to format a batch request. I tried following one of the examples provided, but I received a 400 error like this:
{
"code":"BadRequest",
"message":"Your request couldn\u0027t be completed."
}
Eventually I tried sending a batch following formatting that I've seen from this post, like so:
batch() {
const boundary = Date.now()
fetch(this.hub + this.response._links.batch.href, {
method: 'POST',
headers: {
Accept: 'multipart/batching',
Authorization: `Bearer ${this.token}`,
'Content-Type': `multipart/batching;boundary=${boundary}`
},
body: `--${boundary}\r\nContent-Type: application/http; msgtype=request\r\n\r\nGET ${this.response._links.self.href + '/people/contacts'} HTTP/1.1\r\nAccept: application/json\r\nHost: ${this.hub}\r\n\r\n--${boundary}--`
}).then(r => r.json())
.then(data => console.log(data))
}
Here is the request payload:
--1557482296198
Content-Type: application/http; msgtype=request
GET /ucwa/oauth/v1/applications/103357029549/people/contacts HTTP/1.1
Accept: application/json
Host: https://webpoolam41e02.infra.lync.com
--1557482296198--
This returns a 500 error, however, like this:
{
"code":"ServiceFailure","message":"Your request couldn\u0027t be completed.",
"debugInfo":{
"errorReportId":"8d6499597a54443495627bd2b3e3c5b6"
},
"reasonId":"1000005"
}
I have spent a long time searching for an answer but I cannot find one that works.
Does anyone know how to properly format a batch request?
I have found an answer to my own question. It turns out that the final batch requires 3 line breaks:
\r\n\r\n\r\n
Rather than 2:
\r\n\r\n

Angular-5 StripeConnect -303 Error -Response for Preflight is invalid (Redirect)

I am doing StripeConnect(Standard Account Type) with Angular 5 and Asp.NetCore.
I am able to get redirected to required URL with code={} value.
When I am trying to use this code in below URL,
https://connect.stripe.com/oauth/token\client_secret={{secret test key}}\code={{code}}\grant_type = authorization_code"
1.I get preflight is invalid (Redirect) error in browser from my angular solution.
2.The html for stripe login page from Postman.
The code I wrote for making the post call to above URL (in angular) is :
getCredentialsFromStripe(code: any)
{
let Url = "https://connect.stripe.com/oauth/token";
//\client_secret=" + {{key}} + "\code=" + code + "\grant_type
= authorization_code";
return this.http.post(Url, {
Body: "client_secret = {{key}}\code =" + code,
Headers: {
'Authorization': 'Bearer '+ code,
"Accept": "application/json; charset=UTF-8",
"Access-Control-Allow-Origin": "https://connect.stripe.com/oauth/token"
}
}).map(res => res.json());
}
As per suggestions on internet,I tried making the post call from backend(.NET core(2.0) API for me),but didn't get through in creating account for standard account type.
Moreover testing from postman is giving the full html page of login ,instead of getting this object:
{
"token_type": "bearer",
"stripe_publishable_key": "{PUBLISHABLE_KEY}",
"scope": "read_write",
"livemode": false,
"stripe_user_id": "{ACCOUNT_ID}",
"refresh_token": "{REFRESH_TOKEN}",
"access_token": "{ACCESS_TOKEN}"
}
Can anybody give me a lead on this.I have been stuck past two days.
Any thoughts will be really appreciated.
Well,I was able to fix it. Instead of creating accounts using the URL (given above) in angular project (following the node.js documents),I called the stripe api's in Asp.net core (my api solution) and called them.It worked easily.

Invalid signature Open Bank Project Oauth1.0a

I'm developing a React-Native App with Open Bank Project and I can't use suggested SDKs, not even the nodeJS one as Oauth1.0 is not available in RN.
And I'm stuck with a Bad Signature error on Access Token request '/oauth/token' after passed '/oauth/initiate' and '/oauth/authorize' without any problem.
As specified in docs here before accessing to a Protected Resource we need an Access Token via a POST Request, which gives me the Bad Signature answer.
Here is my code for the request:
getAccessToken(verifier){
let request = {
url: 'https://api.openbankproject.com/oauth/token',
method: 'POST',
data: {
oauth_verifier: verifier,
oauth_token: this.auth.oauth_token,
oauth_token_secret: this.auth.oauth_token_secret
}
}
return fetch(this.url_login, {
method: request.method, //POST
form: request.data,
headers: this.oauth.toHeader(this.oauth.authorize(request))
})
.then((res) => {return res.text()})
.then((txt) => {
console.log('setUID', txt, this.url_login, {
method: request.method,
form: request.data,
headers: this.oauth.toHeader(this.oauth.authorize(request))
})
})
Here is the signed request:
Object {method: "POST", form: Object, headers: Object}
form:
oauth_token:"..."
oauth_token_secret:"..."
oauth_verifier:"71531"
headers:
Authorization:
"OAuth oauth_consumer_key="...", oauth_nonce="3UlQ5dx958tibf6lSg0RUGPQFZeV7b8V", oauth_signature="weyE1lFkoIjAErYLKdSi9SDlCZsNBi7%2BuAkLV2PWePo%3D", oauth_signature_method="HMAC-SHA256", oauth_timestamp="1464248944", oauth_token="...", oauth_token_secret="...", oauth_verifier="71531", oauth_version="1.0""
I've tried with and without Oauth_token_secret, also moving oauth_verifier from body to query but with the same Bad Signature result.
Any idea? thx
You can use oauth module https://github.com/ciaranj/node-oauth
var oauth=require('oauth');
var consumer = new oauth.OAuth(
"https://twitter.com/oauth/request_token", "https://twitter.com/oauth/access_token",
_twitterConsumerKey, _twitterConsumerSecret, "1.0A", "http://127.0.0.1:8080/sessions/callback", "HMAC-SHA1");
then generating signature like this :
var parameters = consumer._prepareParameters("user_access_token", "user_access_token_secret", "http_method", "request_url");
var headers = consumer._buildAuthorizationHeaders(parameters);
parameters array contains signature, also you can build authorization headers if needed. Hope it helps :)