I've been hitting my head against this all morning...
# suitescript
s
I've been hitting my head against this all morning, any hints on how to get(/force my way) past it would be highly appreciated. Here's a censored version of a curl call which works:
Copy code
curl --location --request POST '<https://url.com/oauth/token>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
-d 'client_id=id-id-id&client_secret=secretsecretsecret&grant_type=client_credentials'
Here's me trying the same from NetSuite:
Copy code
<http://https.post|https.post>({
  "url": "<https://url.com/oauth/token>",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
  },
  "body": "client_id=id-id-id&client_secret=secretsecretsecret&grant_type=client_credentials"
})
But then I get this error:
Copy code
Invalid content-type: text/html;charset=UTF-8 received from upstream server
👀 1
b
you can try using an object instead of a string for your body
N/https supports form encoding the body if its an object
otherwise I recommend using an echo service like httpbin.org to see what data is being sent by netsuite
s
same result with object as body. I'll try to echo
Here's what I'm getting back:
Copy code
{
  "body": {
    "args": {},
    "data": "",
    "files": {},
    "form": {
      "client_id": "id-id-id",
      "client_secret": "secretsecretsecret",
      "grant_type": "client_credentials"
    },
    "headers": {
      "Accept": "text/*",
      "Accept-Encoding": "gzip, deflate",
      "Content-Length": "81",
      "Content-Type": "application/x-www-form-urlencoded",
      "Host": "<http://httpbin.org|httpbin.org>",
      "User-Agent": "NetSuite/2021.1 (SuiteScript)",
      "X-Amzn-Trace-Id": "Root=1-612616bc-5864b4314743e0270237d607"
    },
    "json": null,
    "method": "POST",
    "origin": "----",
    "url": "<https://httpbin.org/anything>"
  }
}
b
you will notice here that the content type looks correct
which means that the problem probably isnt the content type
the guess here would be that the error message is misleading
and that it actually has a problem with the accept header
s
Adding Accept: / fixed it!
I can't thank you enough