【问题标题】:Salesforce Commerce Cloud/Demandware - OCAPI query orders by date rangeSalesforce Commerce Cloud/Demandware - OCAPI 按日期范围查询订单
【发布时间】:2017-08-18 20:15:46
【问题描述】:

我正在尝试查询 Demandware (SFCC) api 以使用日期范围提取订单。 orders_search 的 POST 有效,但似乎非常低效。首先我提取 ALL 数据,然后过滤结果。

我想简单地查询日期范围,但我不知道该怎么做。帮助。

{ 
    query : {
        filtered_query: {
            query: {
                term_query: { fields: ["creation_date"], operator: "is_not_null" } 
            },
       filter: {
                range_filter: {
                    field: "creation_date",
                    from: "2017-08-12T00:00:00.000Z",
                    to: "2017-08-13T00:00:00.000Z",
                    from_inclusive: true
                }
            }
        }
    }
}

编辑:虽然我解决了最初的问题,但这最终变得更加复杂,因为该服务一次只允许 200 个响应。因此,首先您必须发出请求以找出有多少结果,然后多次调用该服务以获取数据。下面是与 C# 一起使用的代码。日期范围作为变量传入。

                var m_payload_count = "{ query : { filtered_query: { query: { term_query: { fields: [\"creation_date\"], operator: \"is_not_null\" } }, filter: { range_filter: { field: \"creation_date\", from: \"" + strBeginDateTime + "\", to: \"" + strEndDateTime + "\", from_inclusive: true } } } } }";

                // can only get 200 responses at a a time so make a basic call first to get the total

                m_response_count = apiClient.UploadString(m_url, m_payload_count);

                dynamic m_jsoncount = JsonConvert.DeserializeObject(m_response_count);

                // determine number of times of full api call, rounding up.  substitute begin/end dates and beginning count placeholder 

                int m_records = m_jsoncount["total"];
                int m_numbercalls = (m_records + (200 - 1)) / 200;

                dynamic m_json;

                for (int i = 0; i < m_numbercalls; i++)
                {
                    var m_payload = "{ query : { filtered_query: { query: { term_query: { fields: [\"creation_date\"], operator: \"is_not_null\" } }, filter: { range_filter: { field: \"creation_date\", from: \"" + strBeginDateTime + "\", to: \"" + strEndDateTime + "\", from_inclusive: true } } } }, select: \"(**)\", start: " + i * 200 + ", count: 200 }";

                    m_response = apiClient.UploadString(m_url, m_payload);

                    m_json = JsonConvert.DeserializeObject(m_response);

省略了其余代码,但它本质上是在迭代 m_json 对象。

【问题讨论】:

  • 请问您为什么不要求 SFCC 代码的维护者为您创建这些订单的批量导出?
  • 因为它是自动化过程的一部分,而且批量导出听起来非常手动。
  • 它可以创建为重复性工作,因此根本不需要手动操作。

标签: salesforce demandware salesforce-commerce-cloud


【解决方案1】:
{ 
   "query" :
   { 
      "filtered_query": {
            "query": { match_all_query: {} },
            "filter": {
                "range_filter": {
                    "field": "creation_date",
                    "from": "2016-01-01T00:00:00.000Z"
                }
            }
        }
   },
   "select" : "(**)"
}

【讨论】:

  • 请简要说明您的答案,以指出您提出此作为解决方案的原因
猜你喜欢
  • 1970-01-01
  • 2020-03-19
  • 1970-01-01
  • 2018-04-10
  • 2017-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多