I'm building an integration between NetSuite and the PayTrace credit card processing service. I have no trouble obtaining an authentication key from PayTrace. However, for some reason when sending a request using nlapiRequestURL(url, postData, headers, httpMethod), I get a 401 error and the value of "The access token is invalid" in the response header information. But, if I make the same request with the same token in Postman, it works just as it should. Here's a sample of the request headers I add to the request (as indicated in the PayTrace API documentation):
[
{ "Authorization" : "Bearer XXXXXXXXXX:XXXXXXXXXX:XXXXXXXXXX" }
, { "Content-Type" : "application/json" }
, { "Cache-Control" : "no-cache" }
]
Is it possible that Postman is adding a header value that allows proper authentication that NetSuite does not? For the life of me I can't quite understand why a valid token won't be accepted form one system but get accepted from a different system. I was able to pull these additional header values from Postman, if they're useful in figuring out this issue:
[
{ "User-Agent" : "PostmanRuntime/7.21.0" }
, { "Accept" : "*/*" }
, { "Postman-Token" : "96d421d7-c47b-4c58-8462-aece865bc673" }
, { "Host" : "api.paytrace.com" }
, { "Accept-Encoding" : "gzip, deflate" }
, { "Content-Length" : "401" }
, { "Cookie" : "BIGipServeriAPP-paytraceAPI.app~iAPP-paytraceAPI_pool=!QQe1sQcLLr7QlVc1dGILKzdv552p1+6KLUz7ZVVyyyi2jm4f32eA463wj2bBLYLGBMTo5UmUvj4DzNk=; TS0179310f=01bb9fcf1ed38f2fe502d18776cc42820b00dd85ced785a7a00c8aa2120628c8b485e498ef8a8cacad2fe52a52612a9c6c8aee023b02bca74bc7716a8e066a85df49c4acfa" }
, { "Connection" : "keep-alive" }
]
I'm not certain at all as to what headers NetSuite adds to these HTTP requests.
Once again I figure it out myself. I was passing in the headers as an array of header name/value pair objects, but it was just supposed to be a single object of name/value pairs of header info. That solved the problem. I don't know why I did it incorrectly that way, since I've done this sort of thing countless times. Maybe I need a vacation...
Related
I'm adding Strava to an iOS application, Strava uses Auth2.0, every Strava API call needs a token to prove the user is authenticated and the app has permission to access the API. After obtaining a special "code" from user login response, I need to exchange it with Strava to get a token. I try to retrieve the token using the "code" I got from the login like this:
var headers : HTTPHeaders {
get {
return [
"Accept": "application/json",
]
}
}
let par =
["client_secret": "671333e8c4a7726a5160adb615b74a428535f86e",
"client_id": "32573",
"code": "4/7wAZ8rA_jMXwponVhwGKuPmCDP4UGuCViojCq-K5KRiZ1CI1Gzqc2TdglTJ7k1DU2wIxH22fNguNNXTfIGpaD8g"] as [String : Any]
Alamofire.request("https://www.strava.com/oauth/token", method: .post, parameters: par, encoding: JSONEncoding.default, headers: headers)
.validate()
.responseJSON { response in
print("Response -> \(response.debugDescription)")
}
The problem is that I always get a 400 Bad request, if anyone have experience with the Strava API or any idea of what I'm doing wrong please advise.
You have to specify grant_type=authorization_code to tells the token endpoint that the application is using the authorization code grant type:
https://www.strava.com/oauth/token?
client_id=<YOUR_CLIENT_ID>&
client_secret=<YOUR_CLIENT_SECRET>&
code=<AUTHORIZATION_CODE_FROM_STRAVA>&
grant_type=authorization_code
I'm trying to connect to google home using OAuth2.0 mechanism. However, hitting with an issue where I'm not able to retrieve success message.
The failing request is - https://oauthintegrations.googleapis.com/v1/token:getForService
with the response payload as redirectState. I know about redirect but what is redirectState? I tried to search a bit over this one, but failed.
Any help would be appreciated.
Note:I have followed all the necessary steps mentioned in doc, I can receive authorisation code, but not able to make token request to desired endpoint.
The docs are https://developers.google.com/actions/identity/oauth2-code-flow and https://developers.google.com/actions/identity/account-linking.
In configuration settings we have Linking type as Oauth -> Authorization Code.
In dialog flow in Integration -> Integration Settings we have checked in for 'Sign in required' for Default Welcome Intent and have the firebase function as
app.intent('Default Welcome Intent', (conv) => {
conv.ask(new SignIn());
});
according to https://developers.google.com/actions/identity/account-linking document and I am currently using API version V2.
After the auth code is received as mentioned it does not call token url, we receive this screen :
Bad response from IdP in Auth Code Exchange & what is redirect_state
The https://gala-demo.appspot.com/app#redirect_state=XXX&state=yyy&service=abc when inspected fails at https://oauthintegrations.googleapis.com/v1/token:getForService as mentioned by #rajesh with status code 400, but when this request is made through postman it return the response. Here is the body and response for the request.
Body :
{
"credential" : {
"redirectState": "XXX"
},
"scopes": [],
"gdiState": "APP_AUTH",
"serviceId": "tapclicks-integration-adac2_dev"
}
RESPONSE :
{
"serviceInfo": {
"authUrl": "https://-domain-/authorization",
"name": "tapclicks dashboard",
"logoUrl": "https://placeholder.com/",
"clientId": "zdqexVMaVvxIMQ7Frjwa",
"tokenUrl": "https://-domian-/token_url",
"privacyPolicyUrl": "https://placeholder.com/",
"tosUrl": "https://placeholder.com/",
"id": "tapclicks-integration-adac2_dev"
},
"completionInfo": {
"appauthInfo": {
"appauthRedirectUrl": "https://-domain-/authorization?response_type=code&client_id=zdqexVMaVvxIMQ7Frjwa&redirect_uri=https://oauth-redirect.googleusercontent.com/r/tapclicks-integration-adac2&scope=gmail&state=yyy",
"appauthRedirectState": "abcxxx"
},
"oauthAuthorizationUrl": "https://-domain-/authorization?response_type=code&client_id=zdqexVMaVvxIMQ7Frjwa&redirect_uri=https://oauth-redirect.googleusercontent.com/r/tapclicks-integration-adac2&scope=gmail&state=yyy"
},
"gdiState": "APP_AUTH",
"header": {}
}
Can you please tell if i might be making any configuration mistake or any other info you need.
Authorization Url : https://kprb95tye7.execute-api.us-east-1.amazonaws.com/authorization/
Token Url : https://9343j46f16.execute-api.us-east-1.amazonaws.com/token_url/
Thanks
I'm getting a 404 - File name not provided in url response when creating an upload session.
My request looks like (without any body):
POST /v1.0/drives/{drive-id}/items/{item-id}/createUploadSession
Authorization: bearer <token>
Content-Type: application/json
This problem is only with the consumer OneDrive, OneDrive for Business works fine.
It worked for me:-
POST - https://graph.microsoft.com/v1.0/me/drive/root:/filename.txt:/createUploadSession
In Headers:-
Content-Type : application/json
Authorization: Bearer EwCIA8l6BAAUO...9chh8cJaAg==
In Body:-
{
"item": {
"#odata.type": "microsoft.graph.driveItemUploadableProperties",
"#microsoft.graph.conflictBehavior": "rename",
"name": "filename.txt"
}
}
I could upload a file in a personal account using this URL for create the storage session:
https://graph.microsoft.com/v1.0/me/drive/items/{folderID}:/{fileID}:/createUploadSession
var config = {
method: 'post',
url: 'https://graph.microsoft.com/v1.0/me/drive/items/{folderID}:/{fileID}:/createUploadSession',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer
}
Response:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.uploadSession",
"expirationDateTime": "2020-11-06T14:25:27.662Z",
"nextExpectedRanges": [
"0-"
],
"uploadUrl": {url}
}
Then:
To create the file you gonna need to send a PUT request for the
{uploadUrl} that you got in the response.
I've never run across your particular scenario but I suspect this is due to the folder that was shared with you via OneDrive for Business being part of the same tenant as your own OneDrive for Business. When you're accessing a shared folder from a consumer OneDrive however, you are effectively accessing a drive in a completely separate tenant.
Since using the root:/{path}:/ method I suggested works, it sounds like this scenario may cause some issues with the API determining the file's information from the {itemId}. I'm looking to confirm this so I can update the documentation going forward.
My API calls work correctly in Postman. But when I send requests from Swagger UI, it shows "no response from server" for all requests:
Response Body
no content
Response Code
0
Response Headers
{
"error": "no response from server"
}
What can the problem be and how to fix it?
The browser console shows these errors:
Failed to load resource: net::ERR_CONNECTION_REFUSED
Uncaught TypeError: Cannot read property 'length' of undefined
at showStatus (index.js:24)
at showErrorStatus (index.js:24)
at error (index.js:607) at spec-converter.js:533
at Request.callback (index.js:24)
at Request.crossDomainError (index.js:24)
at XMLHttpRequest.xhr.onreadystatechange (index.js:24)
net::ERR_CONNECTION_REFUSED sounds like you need to enable CORS on your localhost, so that it sends the Access-Control-Allow-Origin: * header in responses. How you do this depends on the server you use. More info here:
https://enable-cors.org/server.html
https://github.com/swagger-api/swagger-ui/#cors-support
You may also need to allow OPTIONS pre-flight requests.
Swagger returns 0 response code due to the Reference Looping in your serializer response.
Ignore the reference looping while getting the serializer response back.
If you are using Web API, use the following code
services.AddMvc()
.AddJsonOptions(opt =>
{
opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});
remove schemes from swagger config json file(in my case tsoa.json) and restart the server. It worked for me.
{
"readme": "https://github.com/lukeautry/tsoa/blob/HEAD/tsoa.json",
"swagger": {
"outputDirectory": "./dist/src",
"entryFile": "./src/server.ts",
"basePath": "/",
"schemes": [
"http",
"https"
],
"securityDefinitions": {
"basic": {
"type": "basic"
}
}
},
"routes": {
"basePath": "/",
"entryFile": "./src/server.ts",
"routesDir": "./src",
"authenticationModule": "./src/security/Authentication"
}
}
In my case there was a problem with https. In swagger config the http scheme was "disabled" (not available). I had it like this:
GlobalConfiguration.Configuration.EnableSwagger(c => { c.Schemes(new[] { "https" }); });
And I had to change it to make it work in debug on localhost:
GlobalConfiguration.Configuration.EnableSwagger(c => { c.Schemes(new[] { "https", "http" }); });
The first snippet worked on production with enabled https but id didn't work while debugging in Visual Studio in default config.
In my case I was sending very simple text response e.g. "Resource not found" in the body and set Content-Type to "application/json". Depends on version Swagger has a hard time deserializing simple text to json, so im my case changing Content-Type to "text/plain" did the trick.
Whenever I try a post a complex character to create a list entry in an O365 SharePoint list (via REST API) I get a JSON parse error from the server. The following is the simple post and it is the β (beta) character which causes the fail. &mdash (—) and other non-simple characters also cause the fail.
The code works just fine for alphabetic characters. It appears to me to be a parsing issue on the SharePoint side but I wanted to know if I was missing something stupid (it happens...)
If I remove the β character from Title field it works just fine. If I create the list item manually through the SP web interface it works just fine, so I know that it is not that the character is invalid, just the creation of the list item through the API.
The headers for the post are:
var outHeaders = {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Authorization": 'Bearer ' + token,
"Content-Length": data.length,
"X-RequestDigest": digest,
"IF-MATCH" : "*"
}
The data being posted is as follows
{
"__metadata": {
"type": "SP.Data.EmailArchiveListItem"
},
"Title": "TEST fail email β",
"Sender": "Mark Roden",
"Recipient": "Mark Roden",
"Body": "HI Marky"
}
The error returned is:
400
Bad Request
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message": {
"lang": "en-US",
"value": "Invalid JSON. Unexpected end of input was found in JSON content. Not all object and array scopes were closed."
}
}
}
Any input/thoughts appreciated.
Try using this code: β That should make it through.
In 2021 (five years later) I had a similar problem (using the SharePoint MS Graph REST API) which I fixed by specifying the charset in the content-type explicitly:
application/json; charset=utf-8
Joe Jorden's answer at least got me this far - If you post the β or — into an RTF Field it works - posting it into a plain text field does not.