Excel+VBA+JSON+Put 请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21786734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 01:55:19  来源:igfitidea点击:

Excel+VBA+JSON+Put Requests

jsonexcelexcel-vbavba

提问by Bryan Heckler

I don't fully understand how to properly package the category IDs I need to send to the API.

我不完全了解如何正确打包我需要发送到 API 的类别 ID。

Sub testing()
  Dim sc As Object
  Set sc = CreateObject("ScriptControl")
  sc.Language = "JScript"

  Dim strURL As String: strURL = "https://api-sandbox.site.com/v1/customers/111111?api_key=xxxxxxxxxxxxx"

  Dim strRequest
  Dim XMLhttp: Set XMLhttp = CreateObject("msxml2.xmlhttp")
  Dim response As String

  XMLhttp.Open "PUT", strURL, False
  XMLhttp.setrequestheader "Content-Type", "application/json;charset=UTF-8"
  XMLhttp.send strRequest
  response = XMLhttp.responseText

End Sub

Objective: Take a set of category IDs and push them to a specific client. My current focus is just to gain understanding on how to do this with a single case. As always any information is GREATLY appreciated.

目标:获取一组类别 ID 并将它们推送到特定客户端。我目前的重点只是了解如何使用单个案例来做到这一点。与往常一样,非常感谢任何信息。

https://api-sandbox.site.com/v1/customers/clientID?api_key=xxxxxxxxxxxxx

The API uses JSON to TX/RX. The format (from my understanding) for the categories would need to be:

API 使用 JSON 到 TX/RX。类别的格式(根据我的理解)需要是:

{"categoryIDs" : [ 1, 2096, 2008, 2009 ]}

An example session from the API:

来自 API 的示例会话:

PUT /v1/customers/2938293/locations/39483?api_key=xxxxxxxxxxxxx HTTP/1.1
Host: api.site.com
Content-Type: application/json;charset=UTF-8

{
  "zip": "92886",
  "phone": "7147147147",
  "countryCode": "US",
  "state": "CA",
  "locationName": "Backpack Brigade",
  "isPhoneTracked": false,
  "specialOfferIsDeal": false, 
  "specialOffer": "Check out our new Summer Backpacks!",
  "folderId": "0",
  "city": "Yorba Linda",
  "id": "123",
  "customerId": "140149",
  "categoryIds": [
    90,
    833
  ],
  "suppressAddress": false,
  "address": "4345 Bastanchury Road",
  "websiteUrl": "http://backpackbrigade.com/",
  "hours":"2:12:00:PM:5:00:PM,3:12:00:PM:5:00:PM,4:12:00:PM:5:00:PM,6:12:00:PM:5:00:PM,7:12:00:PM:5:00:PM",
  "additionalHoursText": "Sunday by Appointment",
  "description": "Best Backpack Store in Southern California!",
  "twitterHandle": "backpackbrigade",
  "logo": { 
    "url": "http://cms.site.com/cms/328812732-backpack.png",
    "description": "Picture of a backpack" 
  },
  "displayLatitude": 33.8991997,
  "displayLongitude": -117.8437043,
  "emails":["[email protected]"]
}

I can't say with certainty, but the code I provided is for handling the response mostly and it would appear that I'm not packaging anything to send with the PUTrequest.

我不能肯定地说,但我提供的代码主要用于处理响应,而且我似乎没有打包任何东西与PUT请求一起发送。

Do the category IDs I'm sending need to be packaged as an objector is a stringok?

我发送的类别 ID 需要打包为object还是可以string

采纳答案by Bryan Heckler

For anyone looking to use JSON and EXCEL I highly recommend this website as a resource: http://ramblings.mcpher.com/Home/excelquirks/json

对于任何想要使用 JSON 和 EXCEL 的人,我强烈推荐这个网站作为资源:http: //ramblings.mcpher.com/Home/excelquirks/json

The modules that Bruce Mcpherson has put together here makes PUT requests, sorting and saving data from JSON API calls simple and straight forward.

Bruce Mcpherson 在这里放置的模块使得 PUT 请求、从 JSON API 调用中排序和保存数据变得简单而直接。

I hope this helps anyone that is in the same situation I was!

我希望这可以帮助任何与我处于相同情况的人!