无法在TFS中使用批处理操作创建批处理工作项 [英] Cannot create batch work items using batch operations in TFS

查看:130
本文介绍了无法在TFS中使用批处理操作创建批处理工作项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用批处理创建方法创建工作项时遇到错误

I am getting below errors while trying to create workitems with batch creation method

错误1

"Message":"No MediaTypeFormatter is available to read an object of type 'JsonBatchHttpRequest' from content with media type 'application/json-patch+json'."

错误2

{"count":1,"value":{"Message":"One or more errors occurred."}}

我已参考此文档 https://www Microsoft提供的.visualstudio.com/en-us/docs/integrate/api/wit/batch .和我有关stackoverflaw的问题创建大量Javascript REST API在TFS中完成工作项的操作

I have referred to this documentation https://www.visualstudio.com/en-us/docs/integrate/api/wit/batch from Microsoft . and my question on stackoverflaw Create Large Amount of Work Items in TFS Using Javascript REST API

我试图通过以下方法发送数据

I have tried to send data as below methods

  • "json:x"
  • 正文:x:"
  • "body:JSON.stringify(x)"
  • "json:[body:x]"

我尝试将"application/json-patch + json"和"application/json"(推荐为MIcrosoft文档)作为内容类型

I have tried both "application/json-patch+json" and "application/json"(recommended as MIcrosoft documentation) as Content-Types

我已经厌倦了Post(推荐为MIcrosoft文档)和Patch方法

I have tired both Post (recommended as MIcrosoft documentation) and Patch methods

没有可用于此错误的参考,因此我现在很讨厌.这里可能有什么错误,请帮忙.

There is no references available for this error hence I have sucked at this point.What could be possibly wrong here please help..

public batchOperation(  ):q.Promise<boolean>{   

        let deferred = q.defer<boolean>();

        try {            
            var batchCreateUrl = this.collectionURL+"/_apis/wit/$batch?api-version=1.0";

   var x= {
        method:"PATCH",
        uri:"/VSTS_TFS_Test/_apis/wit/workItems/$Bug?api-version=1.0",
        headers:{
                "Content-Type":"application/json-patch+json"
            },
    body:[
            {   "op":"add", 
                "path": "/fields/System.Tags", 
                "value":"tg;tg1;tg2" 
            },
            { 
                "op": "add", 
                "path": "/fields/System.Title", 
                "value": "Some Title Text "
            },
            { 
                "op": "add", 
                "path": "/fields/System.Description", 
                "value":"this is description"
            }
        ]
 }

            var options = {            
                url: batchCreateUrl,
                username: this.username,
                password: this.password,
                domain: this.domain,
                method: 'PATCH',
                headers: {
                'Content-Type': 'application/json-patch+json'
            },

                body: x
            };

            httpntlm.patch(options, function(err,res) {

                if(err) {
                    return deferred.reject(false);}
                else{
                    console.log("Patch Complete");
                    console.log(res.body);
                    deferred.resolve(true);
                }
            });
        } catch (error) {
            console.log("Failed to Perform Batch Operation ")
            deferred.reject(false);
        }
        return deferred.promise;
    }

推荐答案

您需要使用"application/json"作为内容类型,并使用 post 方法,就像

You need to use "application/json" as Content-Types and the post method just like the tutorial of Microsoft documentation described.

由于您使用的是 httpntlm ,因此可以包括以下选项:

Since you are using httpntlm, you can include the following options:

  1. json:如果您想直接发送json(content-type设置为 application/json)
  2. 文件:要上传的文件对象(内容类型设置为 多部分/表单数据; boundary = xxx)
  3. 正文:您要发送的自定义正文内容.如果使用,则上一个 选项将被忽略,您的自定义主体将被发送. (不会设置内容类型)
  1. json: if you want to send json directly (content-type is set to application/json)
  2. files: an object of files to upload (content-type is set to multipart/form-data; boundary=xxx)
  3. body: custom body content you want to send. If used, previous options will be ignored and your custom body will be sent. (content-type will not be set)

源链接

如果您使用主体,则先前的选项将被忽略(内容类型将丢失),这可能会导致问题.尝试直接使用json.

If you are using body, your previous options will be ignored(content-type will lose), this may cause the issue. Give a try with directly using json.

这篇关于无法在TFS中使用批处理操作创建批处理工作项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆