RestAssured调用Trello更新组织接口返回200但数据未更新求助
问题原因
- 冗余传参问题:你已经在PUT请求的路径中拼接了目标组织ID
organizationId,不需要额外通过queryParam传入organizationId参数,该参数属于无效冗余参数。 - 核心错误:参数传递格式不符合接口要求:Trello的组织更新接口不支持JSON格式的请求体,你放在
body中的displayName、name参数不会被服务端解析,因此接口虽然返回200状态码,但实际没有执行任何更新操作,返回的是未修改的原组织数据。
修正方案
将需要更新的字段调整为查询参数传递即可,修正后的代码示例如下:
@Test(priority = 1) public void updateOrganization() { Response response = given() .spec(reqSpec) // 移除多余的organizationId查询参数,将需要更新的字段作为查询参数传入 .queryParam("displayName", "org") .queryParam("name", "test123") .when() .put("https://api.trello.com/1/organizations/" + organizationId) .then() .statusCode(200) .extract() .response(); JsonPath json = response.jsonPath(); System.out.println(response.asString()); organizationId = json.getString("id"); organizationName = json.getString("name"); Assert.assertEquals(organizationName, "test123"); }
内容的提问来源于stack exchange,提问作者M.Sz
相关产品推荐
相关产品推荐

