在JSON / REST API中更新值

时间:2019-07-17 07:33:34

标签: json powershell updates patch

我想更新JSON / REST API中的值,但无法修补REST API中的新值。我将新值保存在CSV文件中,然后将此文件转换为JSON,以在REST API中修补新值。

$Authorization = "Bearer API-KEY"
$Accept = "application/json"
$Content = "application/json"
$Uri = "URL"

$getTapes = Invoke-RestMethod -Method PATCH -ContentType $content -Uri $Uri -Headers @{'Authorization' = $Authorization}

Import-Csv "C:\123\test.txt" | ConvertTo-Json | Set-Content -Path $getTapes

我的原始JSON文件如下所示。在test.txt(CSV格式)中,我更改了一些值,并希望在原始JSON / REST API中修补此更改。

{
  "rows": [{
    "id": 111,
    "name": "xrx",
    "serial": "A123456",
    "model": {
      "id": 8,
      "name": "wlw"
    },
    "model_number": "2323",
    "status_label": {
      "id": 22,
      "name": "out"
    }
    }]
}

1 个答案:

答案 0 :(得分:0)

C:\ 123 \ test.txt

FrontEndVerticle.homepageHandler(FrontEndVerticle.java:173)
io.vertx.ext.web.impl.RouteImpl.handleContext(RouteImpl.java:232)
io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:86)
io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:134)
io.vertx.ext.web.handler.impl.BodyHandlerImpl$BHandler.doEnd(BodyHandlerImpl.java:296)
io.vertx.ext.web.handler.impl.BodyHandlerImpl$BHandler.end(BodyHandlerImpl.java:276)
io.vertx.ext.web.handler.impl.BodyHandlerImpl.lambda$handle$0(BodyHandlerImpl.java:87)
io.vertx.core.http.impl.HttpServerRequestImpl.onEnd(HttpServerRequestImpl.java:529)
io.vertx.core.http.impl.HttpServerRequestImpl.handleEnd(HttpServerRequestImpl.java:515)
io.vertx.core.http.impl.Http1xServerConnection.handleEnd(Http1xServerConnection.java:172)
io.vertx.core.http.impl.Http1xServerConnection.handleContent(Http1xServerConnection.java:159)
io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:136)
io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:43)
io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:188)
io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:173)


the line number "173" refers to this line of code..



CouchbaseVerticle couchBaseObject =  routingContext.session().get("CouchDbInstance");

如上所述,似乎您希望每次都更新所有数据,所以我相信您需要PUT方法。 PATCH将仅通过您指定的操作进行更改。

{
  "rows": [{
    "id": 111,
    "name": "xrx",
    "serial": "A123456",
    "model": {
      "id": 8,
      "name": "wlw"
    },
    "model_number": "2323",
    "status_label": {
      "id": 22,
      "name": "out"
    }
  }]
}

我不确定是否要使用定义为$ Accept的Accept标头。我相信,如果您在Invoke-RestMethod中指定了内容类型,则可能没有必要,但这可能是错误的。