Miniflux API URL endpoint - json

I have Miniflux running on an Amazon EC2 instance which I intend to use for my Android application. According to the Miniflux documentation here I should be able to get a JSON response with this URL endpoint:
www.mydomain/miniflux/jsonrpc.php
which in my case is:
{
"jsonrpc":"2.0",
"id":null,
"error":{
"code":-32700,
"message":"Parse error"
}
}
To get more information in JSON format I need to pass in more arguments but the Miniflux documentation does not explain how. The OpenWeatherMap API on the other hand, has a guide on how the URL endpoint may be used with the API key. Any advice on this matter will be greatly appreciated.

first go to miniflix preferences and pick your JSON-RPC URL. it must be something like: API endpoint: https://username.miniflux.net/jsonrpc.php.
there also you will get:
API username: username
API token: swB3/nSo1CB1X2F (example)
type the end point url into your rest client application or chrome extension like postman.
on postman use HTTP Basic Authentication. means put the your login user name in the usename field, api token in the poassword filed then click on Refresh headers button.
chose post method (as all miniflux jsonrpc calls are post) then navigate to "row" tab and write your query like:
{"url": "http://images.apple.com/main/rss/hotnews/hotnews.rss"}, "id": 1}
then you will see the json response.
if you want to use curl it is simple also.
curl \
-u "demo:swB3/nSo1CB1X2F" \
-d '{"jsonrpc": "2.0", "method": "feed.create", "params": {"url": "http://images.apple.com/main/rss/hotnews/hotnews.rss"}, "id": 1}' \
https://demo.miniflux.net/jsonrpc.php
I suggest you to spend sometime reading their JsonRPC code then you will come to understand all the miniflux api calls, response and how it works.

Assuming, for example, your miniflux API reports the following parameters:
API username: username
API endpoint: https://username.miniflux.net/jsonrpc.php
API token: swB3/nSo1CB1X2F
Lift the API method you want from direct the curl -d statements in the miniflux documentation. E.g., for the method to list all feeds (for the sake of convenience, calling it 'payload'):
payload = {"jsonrpc": "2.0", "method": "feed.list", "id": 1}
Assemble a python equivalent of curl's -u command from the username and token API parameters:
auth=('username', 'swB3/nSo1CB1X2F')
Import python's request and json modules and use them to query the miniflux API. The assembled request statement is equivalent to the curl command given in the miniflux documentation:
response = requests.post('https://username.miniflux.net/jsonrpc.php', auth=auth, data=json.dumps(payload), headers=headers).json()
using python3

Related

Apps script: SumUp api requests giving error 400

I am integrating online payments to a web app. To do this I am using the SumUp API. It takes simple http requests. Here is the part of the documentation I am working with: https://developer.sumup.com/docs/single-payment/
My initial request for an access token from the API works fine. But issues arise when creating a checkout resource. I have checked many times and my JSON appears to be correct. The values all appear fine too. However when I run the code the SumUp server returns me this:
Request failed for https://api.sumup.com returned code 400. Truncated server response: {"error":"Unexpected token a in JSON at position 0"}
Here is my code:
var pay_headers = {
"Authorization": `Bearer ${access_token}`,
"Content-Type": "application/json"
};
var pay_details = {
"checkout_reference": "SH8Q0B5C", //random string of letters and numbers
"amount":10,
"currency":"GBP",
"pay_to_email": "docuser#sumup.com",
"description":"Sample one-time payment"
};
var pay_options = {
"method": "post",
"headers": pay_headers,
"payload": pay_details
};
var pay_response = UrlFetchApp.fetch("https://api.sumup.com/v0.1/checkouts",pay_options).getContentText();
Is there something wrong with this? I would appreciate any help as this has been a problematic issue. Thanks
The final 403 error here is due to a poorly documented requirement on the Sumup API. Basically you have to request that your account (whether test or live) is granted scope for the payments part of the API.
If you don't have this you can get an access token but will then be served a 403 error when creating a Checkout.
Save yourself some time and follow this: (I didn't)
https://github.com/sumup/sumup-ecom-php-sdk/issues/24
i.e. email integration#sumup.com
API docs:
https://developer.sumup.com/docs/authorization/#authorization-scopes
When I saw your provided document, the sample curl is as follows. Ref
curl -X POST \
https://api.sumup.com/v0.1/checkouts \
-H 'Authorization: Bearer 565e2d19cef68203170ddadb952141326d14e03f4ccbd46daa079c26c910a864' \
-H 'Content-Type: application/json' \
-d '{
"checkout_reference": "CO746453",
"amount": 10,
"currency": "EUR",
"pay_to_email": "docuser#sumup.com",
"description": "Sample one-time payment"
}'
If this curl command is converted to Google Apps Script, how about modifying your script as follows?
From:
"payload": pay_details
To:
"payload": JSON.stringify(pay_details)
Note:
When the above modification is reflected to your script, when an error occurs, can you provide the error message?
Added:
When above modification is reflected to your script, the request is the same with the sample curl command. From your following reply,
The thing is with the previous API request made in the script (the one that fetches the access token) the payload works fine without using stringify. I did try it for this payload however and it gave me a 403 forbidden. Here is the error message: Exception: Request failed for https://api.sumup.com returned code 403. Truncated server response: {"error_message":"request_not_allowed","error_code":"FORBIDDEN","status_code":403}. This error can be replicated by removing various other parts of the request too so I'm not sure whether it is beneficial to use stringify...
If your access token and your request body are valid values, from 403 of the status code, I'm worried that in your situation, the access from Google side might not be able to be done.
Reference:
403 Forbidden

How to use a GET curl in postman?

I have this curl example:
curl -i -X GET -H "Content-Type:application/json" https://dev.ga.coach/intervention/:getworse/ -d '{"user_id": "012ab3", "section_id": "6"}'
When I run it through cygwin it's working properly! When I'm trying to import it in postman then it shows it as POST and I get the following response.
<h1>Not Found</h1>
<p>The requested URL /intervention/ was not found on this server.</p>
When I test https://dev.ga.coach/intervention/:getworse/ through web browser, this is what I see:
cURL allows you to include a payload on a GET request but the HTTP specification says:
A payload within a GET request message has no defined semantics;
sending a payload body on a GET request might cause some existing
implementations to reject the request.
When you try to make the same request with Postman, you are experiencing it "rejecting" the request. In this case, the rejection comes in the form of it converting to a POST request instead.
It would be appropriate to include a JSON payload on a POST request, but since it looks like you are trying to GET information you should move the data to the URL instead.
For example:
https://dev.ga.coach/intervention/012ab3/6/:getworse/
This will require you change your server-side code (which you, presumably, can do since you said I'm developing the rest-apis) to read the data from the new location.

Api request in Swift

I want to use a recipe API for an app. I have registered and obtained a key for an API. However, I don't know where to put my key in the URL so I can paste it into the browser and get the JSON response.
This is the example Curl request
$response = Unirest\Request::get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?fillIngredients=false&ingredients=apples%2Cflour%2Csugar&limitLicense=false&number=5&ranking=1",
array(
"X-Mashape-Key" => "KEY",
"X-Mashape-Host" => "spoonacular-recipe-food-nutrition-v1.p.mashape.com"
)
);
This is what I get when I search the URL:
{
"message":"Missing Mashape application key. Go to http:\/\/docs.mashape.com\/api-keys to learn how to get your API application key."
}
If anyone knows how to create the full URL with the key or another way to get the Json response in Swift it would be really appreciated.
Thank you
If you want to call an API in Swift, I would recommend using the Alamofire library found here: https://github.com/Alamofire/Alamofire.
In order to authenticate to an API call you have to follow their documentation to find out how they want you to authenticate. Some services have no authentication, while others use a one time use token and some use an API key passed through the request header. It looks like this API call requires the key and host to be passed through the request header. Using Alamofire, the request would look something like this:
let headers: HTTPHeaders = [
"X-Mashape-Key": "KEY",
"X-Mashape-Host": "spoonacular-recipe-food-nutrition-v1.p.mashape.com"
]
Alamofire.request("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?fillIngredients=false&ingredients=apples%2Cflour%2Csugar&limitLicense=false&number=5&ranking=1", headers: headers).responseJSON { response in
debugPrint(response)
}
If you want to test API calls without coding the request in the app before hand, I would recommend downloading an application called Postman. This will allow you to test APIs and see their responses to help you in your swift app.

Making REST API call using curl to Bluemix Predictive Modeling service

I would like to create HTTP GET request to REST API using the curl tool that comes with the Cloud Foundry command line interface (cf). The content/format of the request is described here, under "Retrieving a list of all currently deployed models:" subtitle. In short, the description gives me the url that I can make the request to, it also gives me the following "request example":
Content-Type: */*
Parameters:
Query Parameters:
accesskey: access_key from env.VCAP_SERVICES
I know how to retrieve all necessary parameters (i.e. the access keys, etc). The problem is that I am not sure how to interpret the above "request example" (is it header or body of the request?) and how to create curl command that will properly send the request.
I want to briefly describe what I have tried so far. When I try:
cf curl -X GET "http://{my_url}/model?accesskey={my_access_key}"
I always get the following response:
{
"code": 10000,
"description": "Unknown request",
"error_code": "CF-NotFound"
}
, when I try:
cf curl -X 'GET' http://{my_url}/model?accesskey={my_access_key}
, I think I actually get a response from the server:
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>
Whenerver I try to use just "normal" curl (not the one that comes with the cf command line interface) the Bluemix Predictive Modeling service doesn't respond at all - the connection always times out. I'm not sure why, since Bluemix documentation says that any programming language can be used to make the REST API calls. In the future I would also like to use POST requests - an explanation of how to make one would be very helpful too.
Any help will be greatly appreciated.
You first need to "bind" an instance of the Predictive Model service to an app. When you have done it, you will have a "Show credentials" link below the app widget in your Bluemix dashboard. Click "Show credentials", and you will see a JSON object (which happens to be the VCAP_SERVICES value that Bluemix sets as environment variable for your app), for example:
{
"pm-20": [
{
"name": "Predictive Modeling-i6",
"label": "pm-20",
"plan": "free",
"credentials": {
"url": "https://ibmpmsrvus1.pmservice.ibmcloud.com:8443/pm/v1",
"access_key": "xxxyyyzzz"
}
}
]
}
(I have just removed my own credentials).
Finally for the Curl command, use the "url" above as root of your API, and add a query parameter "?accesskey=xxxyyyzzz" (whatever credentials you have on your own) to all API calls. For example, I add /model to my URL to query my list of models (none created):
curl -X GET "https://ibmpmsrvus1.pmservice.ibmcloud.com:8443/pm/v1/model?accesskey=xxxyyyzzz"
which returns
[]
(as I have not created any models). Note that you will likely need to quote the URL, since the access key contains characters that may mess up your shell command.
I explicitly used "-X GET": You will want to do "-X PUT" in some commands (PUT HTTP method), and most likely you can use "-d #" to upload a file as form data payload:
curl -X PUT -d #mymodelfile "https://..."

Post parameter to Rest API

I need to post a json data and it's parameter to REST API. I know there might be some issues when using json in cross domain, but I tried using mozilla addon "http requester" and using "php-curl" and getting result in a json format as {"success":false}.
Is there any way to inspect the REST API using json data? If so please provide me some example to pass a json data to a REST API using a parameter.
If you have curl installed, at the command line you can do:
curl -d "{\"success\": false}" http://path/to/api?param=value