简体   繁体   English

SnipCart API 授权返回 401 Unauthorized

[英]SnipCart API Authorization returns 401 Unauthorized

I want to use the V3 SnipCart API to get data about specific orders on my thank you page.我想使用 V3 SnipCart API 在我的感谢页面上获取有关特定订单的数据。 I am using C# to do this.我正在使用 C# 来执行此操作。 I keep getting this error when trying to use the API尝试使用 API 时,我不断收到此错误

System.Net.WebException:'The remote server returned an error: (401) Unauthorized.' System.Net.WebException:'远程服务器返回错误:(401)未经授权。'

I have tried to follow their documentation by using only the API key with no password as shown here .我试图通过仅使用没有密码的 API 密钥来遵循他们的文档,如此处所示 Below is my code that I wrote that is giving me the error.下面是我编写的代码,它给了我错误。 I wrote this inside my controller.我在我的 controller 中写了这个。 I get the error as soon as the breakpoint hits this line responseObjGet = (HttpWebResponse)requestObjGet.GetResponse();一旦断点到达这一行,我就会收到错误 responseObjGet = (HttpWebResponse)requestObjGet.GetResponse();

//Testing API get data begin
        string strurltest = String.Format("https://app.snipcart.com/api/orders/c5541254-r8541-8501-0024-juy85vv002154");
       
        WebRequest requestObjGet = WebRequest.Create(strurltest);
        requestObjGet.Credentials = new NetworkCredential("HihiukoJOUBVCTYIiijiGiiYTd6tOiUyTYo", "");
        

        requestObjGet.Method = "GET";
        
        HttpWebResponse responseObjGet = null;
        responseObjGet = (HttpWebResponse)requestObjGet.GetResponse(); //401 is triggered here

        string strresulttest = null;
        using (Stream stream = responseObjGet.GetResponseStream())
        {
            StreamReader sr = new StreamReader(stream);
            strresulttest = sr.ReadToEnd();
            sr.Close();

        }

Concerns that I have as well are the following: 1.The API key that I entered here is my public api key since I am still in the development and testing phase.我也有以下担忧: 1.我在这里输入的 API 密钥是我的公共 api 密钥,因为我仍处于开发和测试阶段。 I am not sure if this api call will work with the test api key or if I have to use the real secret production key.我不确定这个 api 调用是否可以与测试 api 密钥一起使用,或者我是否必须使用真正的秘密生产密钥。 Any thoughts?有什么想法吗?

2.I am debugging this off my local machine (localhost:) for now before I deploy these API calls to production to test these changes in prod still with the test api key, could that be a reason for the 401? 2.在我将这些 API 调用部署到生产环境以测试产品中的这些更改之前,我现在正在我的本地机器(localhost:) 上进行调试,仍然使用测试 api 密钥,这可能是 401 的原因吗? Since the URL that is trying to get the info is my localhost: url and not my actual domain that I added to SnipCart Dashboard.由于试图获取信息的 URL 是我的本地主机:url 而不是我添加到 SnipCart 仪表板的实际域。 I was thinking maybe I have to try and hit this from prod environment instead?我在想也许我必须尝试从 prod 环境中解决这个问题? Any thought?任何想法?

These are the 2 possibilities that come to mind for me.这是我想到的两种可能性。 I am not too savvy on APi's yet so I don't know if my call is missing something.我对 APi 还不太了解,所以我不知道我的电话是否遗漏了什么。

Summary: All I am trying to do is be able to use the API so that I can load the data I want for an order when users reach my custom thank you page with their token.摘要:我要做的就是能够使用 API 以便在用户使用他们的令牌到达我的自定义感谢页面时加载我想要的订单数据。

Our 401 "Unauthorized" status code is returned when the authentication failed to our API with your Authorization header's value.当使用您的 Authorization 标头值对我们的 API 进行身份验证失败时,将返回我们的 401“未授权”状态代码。

Here's the documentation about the auth to our APIs .这是有关我们 API 的身份验证的文档 Make sure to return us a base64 value of your secret API key and the trailing single colon character at the end to respect the Basic Authentication Scheme .确保向我们返回您的秘密 API 密钥的 base64 值和末尾的尾随单冒号字符,以尊重基本身份验证方案

And if you are trying to get data for an order that was placed in live mode then you would need to use the live secret API key.如果您尝试获取处于实时模式下的订单的数据,那么您需要使用实时秘密 API 密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM