Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
using c# instead of js
matthias_gubsch641
Member, Developers Posts: 6 ✭✭
in General
hallo,
was anybody successful in using c# instead of node.js with the apikey mechanism?
i tried it, but i'm failed. i was able to build exact the same authorization string than i have in js, but the only result i received was:
status 401, "Unauthenticated API request.
i'm using vs 2013, .NET 4.5 and https://github.com/restsharp
any hint will be helpful
thanks
matthias
was anybody successful in using c# instead of node.js with the apikey mechanism?
i tried it, but i'm failed. i was able to build exact the same authorization string than i have in js, but the only result i received was:
status 401, "Unauthenticated API request.
i'm using vs 2013, .NET 4.5 and https://github.com/restsharp
any hint will be helpful
thanks
matthias
Tagged:
0
Best Answer
-
matthias_gubsch641 Member, Developers Posts: 6 ✭✭many thanks for your answer, but all the hints you are mentioned, i've already found in the readme ...
so i tried to collect some more information for you and during doing that i found the solution :-)
js is using
authDate = (new Date()).toUTCString();
i have used in c#
authDate = String.Format("{0:r}", DateTime.Now);
i'm here in germany, that's why i have a one hour difference.
now i'm using
authDate = String.Format("{0:r}", DateTime.UtcNow)
and everything is now working perfect !0
Answers
There's also some additional details the help section of the Developer Portal - a particular thing to note are the components of the request and what is hashed along with the key to generate the API Key signature. The order and exact presentation of the values prior to generating the HMAC digest is important : Create a string by appending the following information in order. Each field should be separated by a newline (
\n
) character, and the string must be converted to lowercase:- HTTP method
- On-Nonce header value
- Date header value
- Content-Type header value
- URL pathname
- URL query string
The On-Nonce value should be unique for every request and at least 16 characters of alphanumeric data.You don't mention what API you're trying to call - but remember the API keys have a 'scope' (like OAuth) so if your key doesn't have a scope for the permissions required by the API it may fail (though in this case I think you're key generation is at fault since you get the 401 response).
so i tried to collect some more information for you and during doing that i found the solution :-)
js is using
authDate = (new Date()).toUTCString();
i have used in c#
authDate = String.Format("{0:r}", DateTime.Now);
i'm here in germany, that's why i have a one hour difference.
now i'm using
authDate = String.Format("{0:r}", DateTime.UtcNow)
and everything is now working perfect !