Invalid client error with Sitecore OrderCloud dotnet SDK
A quick post that might help someone else out when using the Sitecore Order Cloud dotnet SDK. When I started playing around with the SDK, I struggled to get it talking to OrderCloud successfully.
I ran code like below in my test application (i.e. Linqpad):
And got an invalid_client exception back.
It took me a little while to realise that the URL in the exception was not the sandbox one, so I needed to specify it in the configuration. Of course the client_id is invalid, because it doesn’t exist in production!
The working code is shown below.
The result is
Concerns
If you don’t specify the ApiUrl or the AuthUrl, your code will be pointed at production endpoints. To me, this is a little bit backwards, and they should by default point at the sandbox. As it is, you should just run into the problem above where the client_id is invalid, but there’s a slim chance that you could be using production credentials, and then if you make a mess, you’re making a mess in prod.
I hope this has been helpful. Thanks for reading. :-)