Add Quote to XTRF using REST API - xtrf

Please let me know how I can post a quote to XTRF using REST API. We are having POST/quote functionality in REST API, but I am unable to find what are the params that we need to pass to that API call and I am getting Http status 415 - Unsupported Media type.
Please help me if anybody knows how to add Quote in XTRF using REST API

XTRF REST API method POST /quotes expects JSON formatted content.
It responds with HTTP status code 415 (Unsupported Media type) if the content does not conform to the JSON format (i.e. uses different format or there are some syntax errors in JSON string).
Example content might look as follows:
{
"name" : "Google Gloves",
"customerProjectNumber" : "G-312-2012",
"workflow" : { "name" : "TP" },
"specialization" : { "name" : "Economy"},
"sourceLanguage" : {"name" : "English"},
"targetLanguages" : [ {"name" : "Polish"}, {"name" : "German"} ],
"deliveryDate" : "2012-09-15 11:30:00",
"notes" : "Sample notes",
"autoAccept" : false,
"priceProfile" : {"name" : "Euro [€]"},
"persons" : [{"id": 10}, {"id": 12}],
"files" : [{"id": 1415596305}, {"id": 2005194325}],
"referenceFiles" : [{"id": 4129771301}]
}
Tip: If you are using API from JavaScript you can use JSON.stringify function to ensure your object is properly serialized to JSON formatted string.

I am able to create a quote using the following CURL operation. Hope this will help.
$data = '{
"name" : "Test Estimate Newest",
"customerProjectNumber" : "Test Project XX",
"workflow" : { "name" : "Edit" },
"specialization" : { "name" : "Economy"},
"sourceLanguage" : {"name" : "English"},
"targetLanguages" : [ {"name" : "Polish"}, {"name" : "German"} ],
"notes" : "Sample notes",
"autoAccept" : false,
"persons" : [{"id":"131"}],
"files" : [],
"referenceFiles" : []
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'Your URL to XTRF');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiepath);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json', 'Content-Length: '. strlen($data)));
$result = curl_exec($ch);
curl_close($ch);
return $result;
-Vamsi

Related

For OpenAPI Specification 3 how should I define the parameter of a request body

I want to define my API endpoints with swagger OAS 3.0.0. My API requires quite a few parameter in the request body and I would like to give a detailed explanation for each request body parameter. The older version of OAS allows for "path" : { "endpoint" : { "in" : "body"}}} which would be perfect because I can describe each parameter individually. However, for OAS 3.0.0 it is stated that parameter in request body should be defined using the requestBody field which does not support description(ie what is the parameter referring to) for each parameter. Is there anyway for me to describe each request body parameter in OAS 3.0.0.?
This way of defining parameters is perfect for me as my clients will be able to see the various parameters clearly.
"parameters" : [{
"name" : "phone_no",
"in" : "body",
"description" : "User mobile no. It should follow International format.",
"required" : true,
"explode" : true,
"schema" : {
"type" : "string",
"example": "+XXXXXX"
}
}, {
"name" : "signature",
"in" : "body",
"description" : "How to get signature ....",
"required" : true,
"explode" : true,
"schema" : {
"type" : "string",
"example" : "XXXXXXXXXXX"
}
} ]
Good readable request body parameters
According to OAS 3.0.0 I should define the parameters in this format which is not ideal as the rendered API documentation will clump the definition of the parameters together which would be less readable for the client.
"requestBody" : {
"description" : "HTTP Request Body",
"content" : {
"application/json" : {
"schema" : {
"properties" : {
"phone_no" : {
"type" : "string",
"required" : true,
"description" : "User mobile no. It should follow International format."
}, "signature" : {
"type" : "string",
"required" : true,
"description" : "How to get signature ...."
}
}
}
}
}
}
Less readable Request Body parameters

JFrog Artifactory API query for object properties does not return requested detail

I am requesting label properties for docker artifact, perhaps the url is not correct? I get response object (json) but label properties are not included. Code example:
response = Net::HTTP.get_with_headers("http://myrepo:8081/artifactory/api/storage/dockerv2-local/anonymizer/functional/manifest.json;docker.label.com.company.info.build='*'",
{'Authorization' => 'Bearer <REDACTED>'})
if response.code.to_s == "200"
puts ("Artifactory response "+ response.body)
puts ("response object: "+response.inspect())
else
puts ("Artifactory request returned "+response.code.to_s)
end
Connecting to artifactory
Artifactory response {
"repo" : "dockerv2-local",
"path" : "/anonymizer/functional/manifest.json",
"created" : "2018-03-14T14:52:22.681-07:00",
"createdBy" : "build",
"lastModified" : "2018-03-15T15:52:34.225-07:00",
"modifiedBy" : "build",
"lastUpdated" : "2018-03-15T15:52:34.225-07:00",
"downloadUri" : "http://myrepo:8081/artifactory/dockerv2-local/anonymizer/functional/manifest.json",
"mimeType" : "application/json",
"size" : "1580",
"checksums" : {
"sha1" : "bf2a1f85c7ab8cec14b64d172b7fdaf420804fcb",
"md5" : "9c1bbfc77e2f44d96255f7c1f99d2e8d",
"sha256" : "53e56b21197c57d8ea9838df7cffb3d8f33cd714998d620efd8a34ba5a7e33c0"
},
"originalChecksums" : {
"sha256" : "53e56b21197c57d8ea9838df7cffb3d8f33cd714998d620efd8a34ba5a7e33c0"
},
"uri" : "http://myrepo:8081/artifactory/api/storage/dockerv2-local/anonymizer/functional/manifest.json"
}
response object: #<Net::HTTPOK 200 OK readbody=true>
If I understand you correctly, you want to get the properties of the manifest.json file, "docker.label.com.company.info.build" in particular.
From looking at your command:
response = Net::HTTP.get_with_headers("http://myrepo:8081/artifactory/api/storage/dockerv2-local/anonymizer/functional/manifest.json;docker.label.com.company.info.build='*'",
It seems that you are using a semicolon to get the properties, which is not the right way. As you can see in this REST API, in order to use the get properties you should use the ampersand sign, so your command should look like:
response = Net::HTTP.get_with_headers("http://myrepo:8081/artifactory/api/storage/dockerv2-local/anonymizer/functional/manifest.json&docker.label.com.company.info.build='*'",

Guzzle 6, put request and description json

I use guzzle 6 with a json file to describe my methods to call.
Bellow, an example with a put request :
in the json descriptor file :
"putObjects" : {
"httpMethod": "PUT",
"uri": "objects",
"summary": "Send objects to the api",
"parameters": {
"objects" : {
"type" : "string",
"location" : "body"
}
}
}
in the symfony controller :
$clientResponse = $client->execute(
$client->getCommand("putObjects", array(
'objects' => $request->getContent()
))
);
Before, with guzzle 3 when the put request was sent, the data sent was formated like this (a valid json) :
{objects: [{....}]}
But now, with guzzle 6, the data is formated as :
objects = {objects: [{....}]}
And of course my api send me an error 'Invalid json message received'.
Someone has an idea about this issue ?
I have found the solution.
In symfony controller :
$content = json_decode($request->getContent(), true);
$clientResponse = $client->execute(
$client->getCommand("putObjects", array(
'objects' => $content['objects']
))
);
In the json descriptor file :
"putObjects" : {
"httpMethod": "PUT",
"uri": "objects",
"summary": "Send objects moderated",
"parameters": {
"objects" : {
"type" : "array",
"location" : "json"
},
}
}

how can I do a POST Req for a REST service in SoapUI 5.1.2 with form-data

Could you help me to resolved the problem that I have?
Using Postman (REST Client - chrome extension) I do a Post to a REST service an I get the correct answer from the services.
The answer is "201 Created" and a new row is added into the DB.
URL = http://suring-t.suremptec.com.ar/gis/13/rest/1.0/organizations
form-date = metadata
{
"meta" : {
"version" : "1.0",
"description" : "Organization"
},
"id" : null,
"name" : "test org",
"startDate" : "2014-06-05 16:20:31.334",
"endDate" : null,
"administrable" : true,
"published" : true,
"href" : "\/2\/rest\/1.0\/organizations\/1"
}
I can't find the way to make SoapUI (5.1.2) works with the same request.
URL = http://suring-t.suremptec.com.ar/gis/13/rest/1.0/organizations
form-date =
metadata
{
"meta" : {
"version" : "1.0",
"description" : "Organization"
},
"id" : null,
"name" : "test org",
"startDate" : "2014-06-05 16:20:31.334",
"endDate" : null,
"administrable" : true,
"published" : true,
"href" : "/2/rest/1.0/organizations/1"
}
The response is "200 - Ok" but
Any Ideas, how should configure the soapui request?
This should get you started Getting started with REST

trying to automate Rally user creation using perl and json

We are tring to automate user creation using perl and json. I have this error on the PUT command:
<h1>Method Not Allowed</h1>
<p>The requested method PUT is not allowed for the URL /https://sandbox.rallydev.com/slm/webservice/1.43/user/create.js.</p>
</body></html>
',
'_rc' => '405',
Attempting POST gives me this:
<h1>Not Found</h1>
<p>The requested URL /https://sandbox.rallydev.com/slm/webservice/1.43/user/create.js was not found on this server.</p>
</body></html>
',
'_rc' => '404',
Is there an example of creating a Rally user with perl?
Here is a basic example in Perl showing how to create a Rally user. Requires the following Perl modules:
REST::Client
JSON
MIME::Base64
I tested this using v5.14.2 on Ubuntu 12.04.
use strict;
use warnings;
# Needed includes
use REST::Client;
use JSON;
use MIME::Base64;
use URI;
use URI::Split;
# User parameters
# Must be a Rally Subscription Administrator, or a Workspace Administrator
# in a Rally Workspace whose Workspace Admins have been granted user administration
# privileges
my $username='user#company.com';
my $password='topsecret';
# Rally connection parameters
my $base_url="https://rally1.rallydev.com";
my $wsapi_version = "1.43";
# Connect to Rally and create user
# ====================================
my $headers = {
Accept => 'application/json',
Authorization => 'Basic ' . encode_base64($username . ':' . $password)
};
# instantiate REST Client
my $rest_client = REST::Client->new();
# set host
$rest_client->setHost($base_url);
# Formulate POST request to create user
# Note that the a Rally User must have at least one Workspace Permission / Project Permission
# pair. Thus the user will be given User Permissions in the Default Workspace of the
# Subscription or Workspace Administrator whose RallyID is used to run this script.
# The user will receive Viewer-level permissions to the alphabetically
# First project in the Default Workspace of the Rally UserID used to run the script
my $new_rally_user_id = 'user12#company.com';
print "Connecting to Rally and attempting to create user of UserID: \n";
print $new_rally_user_id . "\n\n";
my $wsapi_endpoint = "/slm/webservice/" . $wsapi_version . "/";
my $user_create_endpoint = $wsapi_endpoint . "user/create.js";
my $user_post_body = '{"User": {"UserName": "' . $new_rally_user_id . '", "EmailAddress": "' . $new_rally_user_id . '"}}';
print "POST Body for user creation:\n";
print $user_post_body . "\n\n";
# Attempt Create
$rest_client->POST($user_create_endpoint, $user_post_body, $headers);
# Output JSON Response
print "Create Response:\n\n";
print $rest_client->responseContent();
Here's the outcome of running the script:
$ perl rally_create_user.pl
Connecting to Rally and attempting to create user of UserID:
user12#company.com
POST Body for user creation:
{"User": {"UserName": "user12#company.com", "EmailAddress": "user12#company.com"}}
Create Response:
{ "CreateResult" : { "Errors" : [ ],
"Object" : { "Boolean" : null,
"CUF" : null,
"CostCenter" : "None",
"CreationDate" : "2013-07-11T22:49:00.056Z",
"Date" : null,
"Department" : "None",
"Disabled" : false,
"DisplayName" : null,
"Editable" : null,
"EmailAddress" : "user12#company.com",
"FirstName" : null,
"LandingPage" : "/dashboard",
"LastLoginDate" : null,
"LastName" : null,
"LastPasswordUpdateDate" : "2013-07-11T22:49:00.056Z",
"MiddleName" : null,
"NetworkID" : null,
"ObjectID" : 12345678913,
"OfficeLocation" : "None",
"OnpremLdapUsername" : null,
"Phone" : null,
"RevisionHistory" : { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/revisionhistory/12345678915.js",
"_type" : "RevisionHistory"
},
"Role" : "None",
"ShortDisplayName" : null,
"Specialty" : null,
"String" : null,
"Subscription" : { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/subscription/12345678914.js",
"_refObjectName" : "My Subscription",
"_type" : "Subscription"
},
"SubscriptionAdmin" : false,
"TeamMemberships" : [ ],
"Text" : null,
"UserName" : "user12#company.com",
"UserPermissions" : [ { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/workspacepermission/12345678917u12345678918w3.js",
"_refObjectName" : "My Workspace User",
"_type" : "WorkspacePermission"
},
{ "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/projectpermission/12345678919u12345678920p1.js",
"_refObjectName" : "A Project",
"_type" : "ProjectPermission"
}
],
"UserProfile" : { "_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/userprofile/12345678921.js",
"_type" : "UserProfile"
},
"_CreatedAt" : "just now",
"_objectVersion" : "2",
"_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43",
"_ref" : "https://rally1.rallydev.com/slm/webservice/1.43/user/12345678922.js",
"_refObjectName" : "user12",
"_type" : "User",
"yesno" : null
},
"Warnings" : [ "API status is Deprecated and will become Not Supported on 2014-Jun-20" ],
"_rallyAPIMajor" : "1",
"_rallyAPIMinor" : "43"
You start your URI and its https scheme mistakenly with a /. Remove it.