I am creating a groovy script to run from SoapUI to create test plans in VSTS through VSTS api, But on executing it I am getting HTTP400 error. While the same request runs successfully with same headers in REST step of SoapUI.
Initialy I was getting error for authorization but now that got resolved.. It seems the way I am passing the Request body is incorrect
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.JSON
import org.apache.commons.codec.binary.Base64;
import com.eviware.soapui.support.types.StringToStringMap
import org.apache.http.client.methods.HttpPost;
import java.io.File;
import java.io.IOException;
import groovy.json.JsonBuilder
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import static groovyx.net.http.Method.*;
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.protocol.HTTP;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.http.entity.StringEntity;
import static groovy.json.JsonOutput.toJson;
HttpClient httpclient = new DefaultHttpClient();
def post = new HttpPost("https://dev.azure.com/xxx?api-version=1.0");
def jsonBody = [:]
// Test title
jsonBody.put("title", "Test title")
def http = new HTTPBuilder( 'https://dev.azure.com/xxx?api-version=1.0' )
post.addHeader("Authorization","Basic
Onvdfdsfgsdgdfhgfhgfhgfhjgfhtrhtrhtrhtrbvdfb=");
post.addHeader("Accept","application/json");
post.setEntity(jsonBody)
HttpResponse response = httpclient.execute(post);
Expected Result: New test plan should be created in VSTS with the Provided name.
Actual Result: Getting Error: Tue Jan 15 17:03:14 IST 2019:INFO:HTTP/1.1 400 Bad Request [Cache-Control: no-cache, no-store, must-revalidate, Pragma: no-cache, Content-Length: 207, Content-Type: application/json; charset=utf-8, Expires: -1, P3P: CP="CAO DSP COR ADMa DEV CONo TELo CUR PSA PSD TAI IVDo OUR SAMi BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR LOC CNT", Set-Cookie: VstsSession=%7B%22PersistentSessionId%22%3A%22b53ba5ae-5940-4bc4-b464-24b72350fd09%22%2C%22PendingAuthenticationSessionId%22%3A%2200000000-0000-0000-0000-000000000000%22%2C%22CurrentAuthenticationSessionId%22%3A%2200000000-0000-0000-0000-000000000000%22%7D; domain=.dev.azure.com; expires=Sun, 14-Jan-2024 11:36:12 GMT; path=/; secure; HttpOnly, X-TFS-ProcessId: ffde6ea4-0faa-4f90-b5d8-07ed687398f7, Strict-Transport-Security: max-age=31536000; includeSubDomains, ActivityId: 3b96e21f-0539-4724-b31f-178b14072bb1, X-TFS-Session: 3b96e21f-0539-4724-b31f-178b14072bb1, X-VSS-E2EID: 3b96e21f-0539-4724-b31f-178b14072bb1, X-VSS-UserData: 3486938b-c20d-69ff-9eca-14d4011c8ebf:[email protected], X-FRAME-OPTIONS: SAMEORIGIN, X-AspNet-Version: 4.0.30319, X-Powered-By: ASP.NET, X-Content-Type-Options: nosniff, X-MSEdge-Ref: Ref A: BD9BB78BC2814FFD94BEE99ECAE98955 Ref B: BY3EDGE0205 Ref C: 2019-01-15T11:36:12Z, Date: Tue, 15 Jan 2019 11:36:11 GMT]