Boris Yasen
11/09/2023, 10:01 PMhttps://<accountId>.<http://app.netsuite.com/app/login/oauth2/authorize.nl|app.netsuite.com/app/login/oauth2/authorize.nl>
with proper account Id.
In postman I tried to get token code but not sure how to set up its Grant Type and Access token URL.
Any help would be appreciatedbattk
11/09/2023, 10:09 PMbattk
11/09/2023, 10:09 PMbattk
11/09/2023, 10:10 PMBoris Yasen
11/09/2023, 10:10 PMBoris Yasen
11/09/2023, 10:12 PMbattk
11/09/2023, 10:12 PMBoris Yasen
11/09/2023, 10:12 PMbattk
11/09/2023, 10:13 PMBoris Yasen
11/10/2023, 10:13 AMopenssl req -x509 -newkey rsa:4096 -sha256 -keyout auth-key.pem -out auth-cert.pem -nodes -days 730
I ran this command and tried to set it up in Client Credentials setup but it throws me this error.
OAuth 2.0 Client Credentials Error
Unable to parse provided x509 certificate.
Any idea please?battk
11/10/2023, 10:16 AMBoris Yasen
11/10/2023, 10:16 AMBoris Yasen
11/10/2023, 10:16 AMBoris Yasen
11/10/2023, 10:16 AMbattk
11/10/2023, 10:16 AMBoris Yasen
11/10/2023, 10:17 AMbattk
11/10/2023, 10:18 AMbattk
11/10/2023, 10:18 AMBoris Yasen
11/10/2023, 10:19 AMBoris Yasen
11/10/2023, 10:38 AM#! /usr/bin/env python3
import requests
import logging
from pathlib import Path
import datetime
import jwt # PyJWT
GRANT_TYPE = "client_credentials"
CLIENT_ASSERTION_TYPE = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
CLIENT_ID = "<CLIENT_ID>"
TOKEN_ENDPOINT_URL = "https://<COMPID>.<http://suitetalk.api.netsuite.com/services/rest/auth/oauth2/v1/token|suitetalk.api.netsuite.com/services/rest/auth/oauth2/v1/token>"
CONNECT_ENDPOINT_URL = "https://<COMPID>.<http://connect.api.netsuite.com/services/rest/auth/oauth2/v1/token|connect.api.netsuite.com/services/rest/auth/oauth2/v1/token>"
CERTIFICATE_ID = "<CERTIFICATE_ID_GENERATED_WHEN_UPLOADED_TO_NS>"
CERTIFICATE_KEY_FILE = Path("certificates/key.pem")
SCOPES = ['SuiteAnalytics']
def main():
now = datetime.datetime.now()
payload = {
'iss': CLIENT_ID,
'scope': SCOPES,
'aud': CONNECT_ENDPOINT_URL,
'iat': now.timestamp(),
'exp': now + datetime.timedelta(hours=1),
}
private_key = CERTIFICATE_KEY_FILE.read_bytes()
jwt_assertion = jwt.encode(payload, private_key, algorithm="PS256", headers={'kid': CERTIFICATE_ID})
data = {
'grant_type': GRANT_TYPE,
'client_assertion_type': CLIENT_ASSERTION_TYPE,
'client_assertion': jwt_assertion,
}
resp = <http://requests.post|requests.post>(TOKEN_ENDPOINT_URL, data=data)
data = resp.json()
logging.debug("Received '%s'[%d]: %s", TOKEN_ENDPOINT_URL, resp.status_code, resp.raw)
assert data["access_token"]
if __name__ == '__main__':
main()
I tried to get access token following this code, but it returns "invalid_request" error
Could I know if following this code structure is right or not please?battk
11/10/2023, 10:47 AMbattk
11/10/2023, 10:47 AMBoris Yasen
11/10/2023, 10:48 AMBoris Yasen
11/10/2023, 10:48 AMBoris Yasen
11/10/2023, 10:48 AMbattk
11/10/2023, 10:49 AMbattk
11/10/2023, 10:49 AMBoris Yasen
11/10/2023, 10:50 AMbattk
11/10/2023, 10:50 AMbattk
11/10/2023, 10:52 AMbattk
11/10/2023, 10:53 AMBoris Yasen
11/10/2023, 10:53 AMBoris Yasen
11/10/2023, 10:53 AMBoris Yasen
11/10/2023, 2:43 PMbattk
11/10/2023, 6:37 PMbattk
11/10/2023, 6:37 PMbattk
11/10/2023, 6:37 PM