I don't know man. That code your provided looks pretty much like it came straight out of postman. It seems like you can't be using the the correct API key if you are getting a 401 Error. I'd maybe reach out to support.
Hi @Pna7. Have you posted this in the Developers area? I'm not a dev, so I'm not sure how I'd fix this, and I'm not sure many in the CRM/Sales forum would also have the dev knowledge. Code makes me itchy. 😂
Did my answer help? Please "mark as a solution" to help others find answers. Plus I really appreciate it!