2 answers
- 210
Hi,
The following worked for me:
def createIterationBodyStr = groovy.json.JsonOutput.toJson(createIterationBody) converter = scala.collection.JavaConverters; arrForScala = [new scala.Tuple2("Content-Type","application/json-patch+json")] scalaSeq = converter.asScalaIteratorConverter(arrForScala.iterator()).asScala().toSeq(); createIterationBodyStr = groovy.json.JsonOutput.toJson(createIterationBody) def result = await(httpClient.azureClient.ws .url(baseUrl+"/${project}/_apis/wit/workitems/${workItem.id}?api-version=6.0") .addHttpHeaders(scalaSeq) .withAuth(token, token, play.api.libs.ws.WSAuthScheme$BASIC$.MODULE$) .withBody(play.api.libs.json.Json.parse(createIterationBodyStr), play.api.libs.ws.JsonBodyWritables$.MODULE$.writeableOf_JsValue) .withMethod("PATCH") .execute())
Check this video to see it in action!
Please let me know if you have any further questions on this one.
Thanks
Majid
CommentAdd your comment... - 10-1
The error returned by ADO is
The crux of this message is
"The request indicated a Content-Type of \"application/json\" for method type \"PATCH\" which is not supported. Valid content types for this method are: application/json-patch+json."
This indicates that you have to add a header to the request - this can be done using the addHttpHeaders method - as inUNTESTEDdef result = await(httpClient.azureClient.ws .url(baseUrl+"/${project}/_apis/wit/workitems/${workItem.id}?api-version=6.0") .withAuth(token, token, play.api.libs.ws.WSAuthScheme$BASIC$.MODULE$) .withBody(play.api.libs.json.Json.parse(createIterationBodyStr), play.api.libs.ws.JsonBodyWritables$.MODULE$.writeableOf_JsValue) .addHttpHeaders([scala.Tuple2.apply("Content-Type", "application/json-patch+json")]) .withMethod("PATCH") .execute())
Can you give it a try and let me know?- Pavel Kholodyr
Hi, Francis Martens (Exalate) ,
- Tried your code but got another error: img.png
- Tried to remove array brackets- got error: img1.png
3. Tried to convert another way but now I get another error img2. Row 392-img3(code in block and in picture is the same)
converter = scala.collection.JavaConverters; arrForScala = ["Content-Type","application/json-patch+json"] scalaSeq = converter.asScalaIteratorConverter(arrForScala.iterator()).asScala().toSeq(); debug.error("SCALA" + scalaSeq+"SCALA"+ scalaSeq.class) def createIterationBodyStr = groovy.json.JsonOutput.toJson(createIterationBody) // debug.error("JSON" + createIterationBodyStr+"JSON TYPE" + createIterationBodyStr.class) // debug.error("debug "+workItem.id + " "+baseUrl+"/${project}/_apis/wit/workitems/${workItem.id}?api-version=6.0") def result = await(httpClient.azureClient.ws .url(baseUrl+"/${project}/_apis/wit/workitems/${workItem.id}?api-version=6.0") .withAuth(token, token, play.api.libs.ws.WSAuthScheme$BASIC$.MODULE$) .withBody(play.api.libs.json.Json.parse(createIterationBodyStr), play.api.libs.ws.JsonBodyWritables$.MODULE$.writeableOf_JsValue) // .addHttpHeaders("Content-Type", "application/json-patch+json") .addHttpHeaders(scalaSeq) .withMethod("PATCH") .execute())
- Serhiy Onyshchenko
Hey, Pavel Kholodyr , please try
converter = scala.collection.JavaConverters; arrForScala = [new scala.Tuple2("Content-Type","application/json-patch+json")] scalaSeq = converter.asScalaIteratorConverter(arrForScala.iterator()).asScala().toSeq(); debug.error("SCALA" + scalaSeq+"SCALA"+ scalaSeq.class) def createIterationBodyStr = groovy.json.JsonOutput.toJson(createIterationBody) // debug.error("JSON" + createIterationBodyStr+"JSON TYPE" + createIterationBodyStr.class) // debug.error("debug "+workItem.id + " "+baseUrl+"/${project}/_apis/wit/workitems/${workItem.id}?api-version=6.0") def result = await(httpClient.azureClient.ws .url(baseUrl+"/${project}/_apis/wit/workitems/${workItem.id}?api-version=6.0") .withAuth(token, token, play.api.libs.ws.WSAuthScheme$BASIC$.MODULE$) .withBody(play.api.libs.json.Json.parse(createIterationBodyStr), play.api.libs.ws.JsonBodyWritables$.MODULE$.writeableOf_JsValue) // .addHttpHeaders("Content-Type", "application/json-patch+json") .addHttpHeaders(scalaSeq) .withMethod("PATCH") .execute())
- Oleksandra Honcharenko
Hello Serhiy Onyshchenko I am working with Pavel on the same script. And we tried your fix but got error:
We used this debug code:debug.error("RESULT"+result+"RESULT BODY"+result.body() + " " + baseUrl+"/_apis/wit/workitems/${workItem.id}?api-version=6.0")
- Oleksandra Honcharenko
Serhiy Onyshchenko Any ideas?
(Also we will need DELETE request to delete links from ADO.) - Francis Martens (Exalate)
Oleksandra Honcharenko - checkout the suggestion from Majid ^^^
CommentAdd your comment...
Hi all,
I'm try to make sync Jira linked issues to ADO,
from Jira side
ADO side:
And we have error