Trouble with addAttachment method using JSON-RPC in Confluence - confluence

I haven't used REST services in combination with JSON-RPC that much, so I could use some help here.
I am trying to add an attachment to a page in Confluence using a JSON-RPC call. I am testing my calls using soapUI 5.0.0.
The URI of my REST call is:
https://{sitename}/rpc/json-rpc/confluenceservice-v2/addAttachment
I have constructed the following JSON code, which should create a very simple text file:
[ 2339970
, { "fileName" : "Testfile.txt"
, "contentType" : "text/plain"
, "comment" : "to be ignored"
}
, "VGhpcyBpcyBhIHRlc3QuClRvIENvbmZsdWVuY2Ugb3Igbm90IHRvIENvbmZsdWVuY2U/Cg=="
]
The third parameter is a base64 encoded string.
Unfortunately I get an error message from the server:
<error>
<code>-32602</code>
<data null="true"/>
<message>Request parameter types did not match method parameter types (method addAttachment taking 3 parameters)</message>
</error>
Any idea what I'm doing wrong here?

Related

Unable to create mocks on post request with content-type : application/x-www-form-urlencoded

I am working with mountebank to create mocks for an External REST API
which is a POST request with content-type : application/x-www-form-urlencoded.
The API is of format
https://<url>/dpay/MPmt
and data payload is passed in format msg=01223~20170607114321~ABC~12345~NA~NA
I have to search on the basis of ~ABC~12345~ which would remain constant.
I have used contains, matches and equals predicates but was not able to run them while passing the payload in request body.
However, I was able to get it running when passing payload as a query parameter
https://url/dpay/MPmt?msg=01223~20170607114321~ABC~12345~NA~NA
but can't find a way to get it done when passed in request body.
Any pointers would be really appreciated.
Use the predicate "contains" and pass your matching string only. What I suspect is that you are using
"contains" :
{ "body" : {
"msg": "~ABC~12345~"
}
}
this will look for an msg variable in the request body, instead, use
"contains" : {"body": "~ABC~12345~"}
and it will match it directly in your request body.
I faced the same issue, Hope it works for you.

Apigility code-connected service - for POST method

I am a newbie to the apigility code-connected service & was able to create a RESTful service with fetch and fetchall class method on the mapper file.
Can someone point me a good sample for insert (POST) data via REST service ?
Thank you,
Kevin
POST is going to be used for creating a new resource typically. This means that in your request you're going to want the following headers:
Accept: application/json
Content-Type: application/json
The first tells Apigility what sort of a response it is expecting. The second says that the data you'll be providing to the API will be in json format.
Apigility uses json or json+hal by default for a return and expects json for the incoming data.
When you're creating a new resource, typically you'll be persisting it in a database and as such the id of the resource will be generated by your code or database. The rest of the resource will be provided by the caller to the API. Example:
POST /api/user
{
"username": "kevin voyce",
"firstname": "kevin",
"lastname":" "voyce"
}
If you do this, you should see a response of something like
405 - Method Not Allowed
The body of the error should indicate that the method has not been defined. The error message is coming from the create method in the resource. Inside this method, you'll see an argument called $data which at this point will consist of a PHP stdClass with fields matching the stuff you passed in via the JSON body.
This is where the fields part of configuring your API in Apigility comes in. If you set up the names of the fields and put validators on the fields, Apigility will make sure that the fields that are passed in conform to and are valid according to these validators before the call is made into your API. The same applies to not just POST, but PATCH and PUT as well. This means that within your methods you don't have to worry that the input hasn't been validated (as long as you correctly configured your validators).

BigCommerce API Update Order with PUT

I need to update an order which is done via PUT method passing the order id as part of the https url string and a single parameter, the status_id.
https://mystore.mybigcommerce.com/orders/12345.json
I have tried several methods to pass the status_id value but no matter what I try "status_id=12" or formatted as JSON "{"status_id": 12,}" I always get the same response:
[{"status":415,"message":"The specified input content type is not valid."}]
I have also tried as a POST request passing the JSON or XML code as raw data but that method is not supported.
How am I supposed to pass that field=value pair? can I embed it in the url string?
I also tried it but it wouldn't work for me.
Any ideas?
In case you are wondering I am doing it within FileMaker with TROIUrl plugIn, not a very popular technology, but the GET method retrieving orders works like a charm
TURL_Put( ""; $url ;"status_id=12") (I have also tried other FM plugIns to no avail)
Don't get too caught up in the Filemaker part, I don't expect many people out there to be familiar with BigCommerce and Filemaker. I just need a generic answer.
Thanks
Commandline tool curl is worth a try. It supports put and https.
Mac OS X: curl already installed, call from FileMaker via AppleScript do shell script.
Windows: must be installed, call via Powershell.
It works for me using { "status_id": "3" } which means you probably need to put quotes around the actual number.
Also, it is a PUT operation and application/json which is part of the request content.
The error message received by the OP:
[{"status":415,"message":"The specified input content type is not valid."}]
Is saying that he did not supply the 'Content-Type' header in his request or that the header supplied is for a content type that is not allowed. For the OP's case using JSON he would need to include the header:
Content-Type: application/json
in his HTTPS request. This description can be found along with those of the other status codes you may see here:
https://developer.bigcommerce.com/api/status-codes

WSO2 API Manager - Publishing API with non-XML response

I am trying to proxy the following call through WSO2 API Manager
http://api.qrserver.com/v1/create-qr-code/?data=HelloWorld&size=100x100
which returns a QR code image. I published the API using http://api.qrserver.com/v1/ as endpoint, no problem there. But when I perform the call through the API Manager, I get the following error:
curl -H 'Authorization:Bearer 7q6W4LteX9idveFWbSa_oaGPhVsa' 'http://ec2-xx-xx-xx-xx.eu-west-1.compute.amazonaws.com:8280/qrcode/1.0.0/create-qr-code/?data=HelloWorld&size=100x100'
<Exception>Unexpected response received. HTTP response code : 200 HTTP status : OK exception : com.ctc.wstx.exc.WstxIOException: Invalid UTF-8 start byte 0x89 (at char #1, byte #-1)</Exception>
when performing the call directly the response header seems good to me (the mime type image/png is correctly set), but the WSO2 API proxy refuses the response... what I am doing wrong? Setting a wadl file with response mediaType="image/png" does not seem to help either.
Thanks in advance
I have a similar problem in wso2 esb. Seems that the response works with short xml files but not with a big one.
This problem is due to not having match message builders and formatters by default in API manager's axis2.xml. Please add following parameters to axis2.xml.
<messageBuilder contentType=".*" class="org.wso2.carbon.relay.BinaryRelayBuilder"/>
<messageFormatter contentType=".*" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
Thanks.
Sanjeewa.

post data to REST API using RESTClient for firefox addon

I am using RESTClient for firefox addon to test REST API, i set some headers that's working fine if i set request body and method to GET , i couldn't access data via my PHP application, but headers available
**Request headers**
Content-Type : application/json
**Request Body**
[
{
"data1" : "value1",
"data2" : "value2",
"data3" : 1
}
]
How do i set Request body correctly?
Set a body to GET requests is a "nonsense" because GET means retrieve some information and the body of a request is used to send data.
It is precisely from this point of view that web servers, most of the time, ignore the body of a GET request, which could explain why you can't get your data from your PHP script.
If the purpose of your request is to create or update a resource you should consider using a POST or PUT to be REST.
There is already a topic opened with almost the same question here : HTTP GET with request body