RE: OAuth2 M2M Token Endpoint 500 Server Error

I am attempting to implement the OAuth2 Client Credentials Flow aka Machine to Machine.

I found this thread on the slack but the trail went cold.

I set up an integration record, took down the application ID and the certificate ID and used this code (with the application ID as the client ID /’iss’ and the certificate ID as the ‘kid’). To incrementally test the process, I ran get or incomplete post requests on the token endpoint as suggested in the slack thread. They return 4XX errors and show up in the login audit log.

However, when I submit what I think should be a fully formed request I get a 500 – server error response, and the request does not appear in the audit log to provide additional details.

Any help would be appreciated.

import jwt
import requests
import time
url = f’https://{account_id}.suitetalk.api.netsuite.com/services/rest/auth/oauth2/v1/token’
issued_at = int(time.time())
expiration = issued_at + (60*30) # 30 minutes
jwt_headers = {
    “typ”: ‘JWT’,
    “alg”: ‘PS256’,
    “kid”: kid
}
jwt_payload = {
    “iss”: issuer,
    “scope”: “rest_webservices”,
    “aud”: url,
    “exp”: expiration,
    “iat”: issued_at
}
jwt_token = jwt.encode(payload=jwt_payload, key=private_key_data, algorithm=’PS256′, headers=jwt_headers)
headers = {
    “Content-Type”: “application/x-www-form-urlencoded”
}
payload = {
    ‘grant_type’: “client_credentials”,
    ‘client_assertion_type’: “urn:ietf:params:oauth:client-assertion-type:jwt-bearer”,
    ‘client_assertion’: jwt_token
    }
response = requests.post(url, headers=headers, data=payload)
response.json()

{‘error’: ‘server_error’}


OAuth2 M2M Token Endpoint 500 Server Error

bweithers Rookie Asked on November 14, 2024 in Administration.
Add Comment
2 Answers

I was using the ‘Application ID’ instead of the only-shown-once Client ID upon integration record creation. After resetting my integration record and using the Client ID as the ‘iss’ parameter I was able to receive an access token back.

Rookie Answered on November 15, 2024.

Glad you got it sorted!

on November 15, 2024.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.