Create bug in Bugzilla using Bugzilla Restful Api - rest

Any sample code to create a new bug in Bugzilla using the restful webservice API? What I have done so far is using Postman to see how it works:
The simple json code:
{
"product" : "TestProduct",
"component" : "TestComponent",
"summary" : "This is the best bug report",
"version" : "unspecified",
"description" : "This is the best GUI for reporting bugs"
}
This is the endpoint:
http://localhost/bugzilla/rest.cgi/rest/bug
The error log I'm getting:
{
"code": 32614,
"message": "A REST API resource was not found for 'POST /rest/bug'.",
"documentation": "https://bugzilla.readthedocs.org/en/5.0/api/",
"error": true
}

A sample example written in python, to create a bug in Bugzilla 5.x, using the rest API .
import requests
data = {
"product" : "TestProduct",
"component" : "TestComponent",
"summary" : "This is the best bug report",
"version" : "unspecified",
"description" : "This is the best GUI for reporting bugs"
}
url_bz_restapi = 'http://localhost/bugzilla/rest.cgi/bug'
r = requests.post(url_bz_restapi, data=data)

Create a new token from the api " /rest/login?login=foo#example.com&password=toosecrettoshow "
import requests
url = 'http://localhost/bugzilla/rest.cgi/bug?token=GENERATED TOKEN'
data = {
"product" : "TestProduct",
"component" : "TestComponent",
"version" : "unspecified",
"summary" : "'This is a test bug - please disregard",
"alias" : "Somlias",
"op_sys" : "All",
"priority" : "---",
"rep_platform" : "All"
}
def create_bug(url,data):
test = requests.post(url,data=data)
return test.json()
create_bug(url,data)

Using Rest client
URL : http://IP/bugzilla/rest.cgi/bug
Method: POST
Basic Auth: token:gentoken
JSON :
{
"product" : "Ashok",
"component" : "Test",
"version" : "unspecified",
"summary" : "'This is a test bug - from JSON"
}

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

Swagger 2.0 uploading a file to SP Online that doesn't send the extra content through

I'm hoping someone can point out my mistake here.
I have the following swagger definition which I use on swaggerhub that will upload a file to Sharepoint document library via the rest api
{
"swagger" : "2.0",
"info" : {
"description" : "defaultDescription",
"version" : "2",
"title" : "defaultTitle"
},
"host" : "someSite.sharepoint.com",
"schemes" : [ "https" ],
"paths" : {
"/sites/ms/_api/Web/GetFolderByServerRelativeUrl('doc/test/tt')/Files/Add(url='{filename}',overwrite=true)" : {
"post" : {
"consumes" : [ "multipart/form-data" ],
"produces" : [ "application/json" ],
"parameters" : [ {
"in" : "formData",
"name" : "upfile",
"type" : "file",
"required" : true,
"description" : "The file to upload."
},
{
"in" : "path",
"name" : "filename",
"type" : "string",
"required" : true
} ],
"responses" : {
"200" : {
"schema" : {
"type" : "string"
},
"description" : "Definition generated from Swagger Inspector"
}
}
}
}
}
}
Problem is I can't open any files on SP because they're broken, and I believe I found the reason when I tested with a txt file.
I'll send a text file only containing Sample text bu when I open it on SP doc library it contains all the following as well
-------------------------------28947758029299
Content-Disposition: form-data; name="upfile"; filename="myt.txt"
Content-Type: text/plain
Sample text
-------------------------------28947758029299--
Is the issue with my content type or should I use the parameter differently, I tried researching this but what I found just matched the original guid I found
https://swagger.io/docs/specification/2-0/file-upload/
We came across a similar issue in our project.
The root cause is that Swagger 2.0 won't let you specify a different Content-Type for type file. You have to use multipart/form-data. See details here: https://swagger.io/docs/specification/2-0/file-upload/
To resolve this, you have to change the type from file to generic object. For example:
paths:
/sharepoint_upload/:
post:
description: "This will uploads a document to SharePoint."
operationId: "uploadDocuments"
consumes:
- "application/octet-stream"
produces:
- "application/json"
parameters:
- name: "documentBody"
in: "body"
description: "The actual document"
required: true
schema:
type: "object"
responses:
200:
description: "OK - Your request was successfully completed."
400:

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='*'",

exception- groovy connector : script is null

I'm using Bonita BPM Community Edition v.7.0
In my process, I made a service task and it has a connector. I used Groovy 2.4 connector to call external Restful service.
This restful service url return the response as
{
"RestResponse" : {
"messages" : [ "More webservices are available at http://www.groupkt.com/post/f2129b88/services.htm", "Total [249] records found." ],
"result" : [ {
"name" : "Afghanistan",
"alpha2_code" : "AF",
"alpha3_code" : "AFG"
}, {
"name" : "Ă…land Islands",
"alpha2_code" : "AX",
"alpha3_code" : "ALA"
}, {
"name" : "Albania",
"alpha2_code" : "AL",
"alpha3_code" : "ALB"
}, {
"name" : "Algeria",
"alpha2_code" : "DZ",
"alpha3_code" : "DZA"
}
}}
When I test at the Edit expression window using 'Evaluate' button, it works well.BUT.. when I test using 'Test' button, it prints as follows.
java.lang.reflect.InvocationTargetException
org.bonitasoft.engine.bpm.connector.ConnectorExecutionException: USERNAME=install | org.bonitasoft.engine.core.connector.exception.SConnectorException: org.bonitasoft.engine.connector.exception.SConnectorException: java.util.concurrent.ExecutionException: org.bonitasoft.engine.connector.exception.SConnectorValidationException: org.bonitasoft.engine.connector.ConnectorValidationException: Error validating connector org.bonitasoft.connectors.scripting.GroovyScriptConnector:
The script is null.
My script is as follows,
#Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
import groovyx.net.http.RESTClient
//import groovy.json.JsonSlurper
//import groovy.json.JsonOutput
def client = new RESTClient( 'http://services.groupkt.com' )
def resp = client.get( path : '/country/get/all' ) // ACME boomerang
assert resp.status == 200 // HTTP response code; 404 means not found, etc.
def value= resp.getData()
def value1 = value.RestResponse.result
return value1[0].name
Response like: Afghanistan
while test it, Why it shows that error?
Any one please help me out from this issue,
It was a bug. Fixed in 7.3.1.
Best

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