找不到Square Connect API列表位置和库存调整返回404

时间:2016-06-14 02:33:14

标签: c# square-connect

我能够毫无问题地获得所有类别和所有项目。当我尝试获取位置列表或调整库存时,我收到错误消息。

获取位置的代码:     WebRequest request = WebRequest.Create(“https://connect.squareup.com/v1/me/locations”);             request.ContentType =“application / json”;             request.Method =“GET”;             request.Headers [“Authorization”] =“Bearer xxxxxxxxxxxxxxxxxxxxxx”;

        HttpWebResponse response = null;
        string responseMessage = null;
        response = (HttpWebResponse)request.GetResponse();

        if (response.StatusCode == HttpStatusCode.OK)
        {
            using (Stream stream = response.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    responseMessage = reader.ReadToEnd();
                }
            }
        }

我调整广告资源的代码是:     Uri uri = new System.Uri(string.Format(“https://connect.squareup.com/v1/me/inventory/ {0}”,variationId));             WebRequest request = WebRequest.Create(uri);             request.ContentType =“application / json”;             request.Method =“PUT”;             request.Headers [“Authorization”] =“Bearer xxxxxxxxxxxxxxxxxxxxxx”;

        string postData = "{\"quantity_delta\":" + adjustAmount.ToString() + ",\"adjustment_type\":\"MANUAL_ADJUST\"}";
        byte[] byteArray = Encoding.UTF8.GetBytes (postData);
        request.ContentLength = byteArray.Length;
        Stream dataStream = request.GetRequestStream ();
        dataStream.Write (byteArray, 0, byteArray.Length);
        dataStream.Close ();

        HttpWebResponse response = null;
        string responseMessage = null;
        response = (HttpWebResponse)request.GetResponse();

        if (response.StatusCode == HttpStatusCode.OK)
        {
            using (Stream stream = response.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    responseMessage = reader.ReadToEnd();
                }
            }
        }

对于行响应=(HttpWebResponse)request.GetResponse();  我收到远程服务器返回错误:(404)Not Found

我非常感谢任何帮助,因为我不明白为什么我的部分代码正在运行,但这两部分都没有。

1 个答案:

答案 0 :(得分:0)

需要在2016年2月16日之后创建应用以使用v1位置端点,如Business Management Overview section中所示:" 应用程序无法使用本节中描述的端点这是在2016年2月16日之前创建的。有关详细信息,请参阅Connect API changes (2016-02-16)"您能否验证该应用是否是在2016年2月16日之后创建的?如果没有,您能否请创建一个新的应用程序并尝试一下?

对于404库存调整,您能否提供项目变体ID以供进一步调查?