Michael McCauley
Michael McCauley

Reputation: 931

NetSuite/SuiteScript nlapiRequeestURL() OAuth Authentication Failure

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.

Upvotes: 0

Views: 381

Answers (1)

Michael McCauley
Michael McCauley

Reputation: 931

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...

Upvotes: 1

Related Questions