# While trying to use @okta/okta-sdk-nodejs i get an error for invalid character in JSON

**URL:** <https://devforum.okta.com/t/while-trying-to-use-okta-okta-sdk-nodejs-i-get-an-error-for-invalid-character-in-json/28474>\
**Category:** API\
**Tags:** nodejs\
**Created:** [May 26, 2024, 9:00am UTC](https://devforum.okta.com/t/while-trying-to-use-okta-okta-sdk-nodejs-i-get-an-error-for-invalid-character-in-json/28474 "2024-05-26T09:00:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eyal.ringwald](https://avatars.discourse-cdn.com/v4/letter/e/59ef9b/32.png) [@eyal.ringwald](https://devforum.okta.com/u/eyal.ringwald)\
**Post date:** [May 26, 2024, 9:00am UTC](https://devforum.okta.com/t/while-trying-to-use-okta-okta-sdk-nodejs-i-get-an-error-for-invalid-character-in-json/28474/1 "2024-05-26T09:00:09Z")

</div>

i am using the @okta/okta-sdk-nodejs , set the client according to documentation :  
const client = new okta.Client({  
orgUrl: ‘’,  
authorizationMode: ‘PrivateKey’,  
clientId: '. ',  
scopes: [‘okta.users.read’],  
privateKey: key, // the key is a JSON as a string that was copied according to the guide, currently in another file and exported as string  
keyId: ‘\<my kid from the app integration API service general tab’,  
})  
}

when running any api , for example :  
const user = await client.userApi.getUser({ userId: ‘00u7j1z1z1Z2Z2Z2Z2Z2’ })

i get the following error :  
“invalid json response body at /error/404?fromURI=%2Foauth2%2Fv1%2Ftoken reason: Unexpected token ‘\<’, "\<!DOCTYPE "… is not valid JSON”

I could not find any ‘\<’ sign …

my key file looks like :

export const key = `{ "d": "<some-string>", "p": "<some-string>", "q": "<some-string>", "dp": "<some-string>", "dq": "<some-string>", "qi": "<some-string>", "kty": "RSA", "e": "<some-string>", "kid": "my KID", "n": "<some-string>" }`

can you please help to understand what may be the issue ?

---

<div class="post-metadata">

**Author:** ![krishna](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@krishna](https://devforum.okta.com/u/krishna)\
**Post date:** [May 28, 2024, 7:59am UTC](https://devforum.okta.com/t/while-trying-to-use-okta-okta-sdk-nodejs-i-get-an-error-for-invalid-character-in-json/28474/2 "2024-05-28T07:59:49Z")

</div>

What’s your specific goal in signing your own private key tokens using this SDK? Typically, it’s best to utilize built-in directives whenever possible. Have you explored those options yet?

> **[GitHub - okta/samples-nodejs-express-4: Express 4 samples. Will publish an...](https://github.com/okta/samples-nodejs-express-4)**
>
> Express 4 samples. Will publish an artifact that can be consumed by end-to-end sample repos - okta/samples-nodejs-express-4

You would need to explain a bit more of the requirements? The Key format is throwing this error.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [June 27, 2024, 8:00am UTC](https://devforum.okta.com/t/while-trying-to-use-okta-okta-sdk-nodejs-i-get-an-error-for-invalid-character-in-json/28474/3 "2024-06-27T08:00:15Z")

</div>

Closed on June 27, 2024, 8:00am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
