how can make throttling per user per api and per resource of the api in wso2 api management 2.6? - publish-subscribe

I am using wso2 API management 2.6. I have 15 API in my store and every API has 5-10 resources (many 'get'-'post'-'delete'-'put'). I have 3 users (consumers) that every one has his own tiers for calling APIs. for example 'user1' can call just one 'get' resource of 'API1' ,all 'post' resources of API2 and can not call other resources in API1 , API2 and API3. This situation is same for user2 and user3. I don't know how can I make throttling tiers for this store?
I found this this example and change it to my own one like this :
key Template:
$userId:$resourceKey
siddhi query :
FROM RequestStream
SELECT userId, ( userId == 'userId#carbon.super' and resourceKey== '/api/1.0.0/resourceKey:GET') AS isEligible ,
str:concat('userId#carbon.super' , ':' , '/api/1.0.0/resourceKey:GET') as throttleKey
INSERT INTO EligibilityStream;
FROM EligibilityStream[isEligible==true]#throttler:timeBatch(1 min)
SELECT throttleKey, (count(userId) >= 1) as isThrottled, expiryTimeStamp group by throttleKey
INSERT ALL EVENTS into ResultStream;
I have this siddhi query but it doesn't work!
I don't know this info helps or not but my api request Url is : https://[APIAdress]/api/1.0.0/resourceKey

Related

Get specific product with id via Rest API Magento 2

I want to get the information from an specific product.
I am using this reference in this moment, and get all the products in given searchCriteria:
http://www.mysite.co/rest/V1/products-render-info?storeId=1&currencyCode=cop
Is there a way I can send the product id in the url and get only all its information?
You can add the filter
http://www.mysite.co/rest/V1/products?searchCriteria[filterGroups][0][filters][0][field]=entity_id&searchCriteria[filterGroups][0][filters][0][value]=1&searchCriteria[filterGroups][0][filters][0][condition_type]=eq
use field entity_id instead of id, value is product id here 1, condition_type is equal to here eq.
You can fetch product info by SKU, not ID.
API endpoint (get method) will pull product info. vendor/magento/module-catalog/etc/webapi.xml
/V1/products/:sku
So, your rest API calling URL should be like this
http://www.mysite.co/rest/V1/products/productsku
Note: If you want to fetch product info by id, you probably need to create a simple rest API. you can check this out.
https://magento.stackexchange.com/questions/282480/i-am-new-here-i-want-to-know-how-can-i-create-my-own-simple-api/282730

How do I export GLBudgetLineDetail via Rest API?

My goal is to export data from the [GLBudgetlineDetail] table via the Rest API.
To accomplish this:
1) I created created a custom endpoint based on the Budgets screen (Finance > General Ledger > Work Area > Enter > Budgets)
!(http://imgur.com/sQC0zOI)
2) I populated the endpoint by adding all the fields from the Budget Articles container
!(http://imgur.com/tZp2GMh)
When I query this endpoint, I only get an empty array returned "[]".
Here is the query:
GET http ://servername/WebServiceAPITest/entity/MyStore/6.00.001/Budget
Headers:
Content-Type -> application/json
("Budget" is the name I gave to the endpoint)
I can successfully query other endpoints (Accounts, Vendors, JournalTransactions, etc) but I can't get any data back from this one.
I created the MyStore Demo (Course I210) and have access to the [GLBudgetLineDetail] table and can verify that it has data. On the Budgets screen, if I filter to year 2013, Ledger 'Budget', Branch 'SOFT', I can see Budget information.
How do I get access to this info via the Rest API?
Since you mentioned the Course I210, You might want to refer yourself to the section 3.4.1 about Retrieving the Price of an Item for a Customer.
In that section, they are saying that if you want to retrieve data from an inquiry, you must use the Put command:
"Because you are retrieving the price of an item from the inquiry, you will use the Put() method to obtain data."
Since the Budget Screen is an Inquiry Screen you must use the Put command to set the parameter you want.
Here is one that I tried and that worked on an Acumatica web site with demo
data:
PUT http://localhost/Demo610u04/entity/BudgetEndpoint/6.00.001/Budget
Headers (Key -> Value):
Content-Type -> application/json
Accept -> application/json
Body :
{
"BudgetArticles":[{}],
"FinancialYear":{"Value":"2016"},
"Ledger":{"Value":"BUDGET"}
}
EDIT: Looking at the image you added, you should have your budget Filter fields in the main entity and have a sub entity of type Detail containing the Budget Articles fields

How to use 'not equal' to filter on users attribute in a URL using REST Identity API in Bonita

I'm using Bonita in a 7.3 Version. My goal is to use the identity API to gather information about my users, such as it's name etc. The thing is : I'm trying to catch all the users in a certain group of users with the following API request :
http://localhost:XXXXX/bonita/API/identity/user?a&f=role_id=101&f=manager_id=0
As we can imagin, this query gives me a list of users, with a role_id = 101 and no managers.
And then, I want to filter on a new attribute, which is the id : I d'ont want the user with the id equal to 101. I've tried this :
http://localhost:XXXXX/bonita/API/identity/user?a&f=role_id=101&f=manager_id=0&f=id!=101
But it does not work. Is it even possible to use the != element in Bonita ?
There is no != option within the f={filter name}={filter value}

Designing RESTful shopping cart

I am building a single page application for booking hotel conference rooms and am not sure how to set it up, or even if RESTful is the proper approach. There will be four steps to this SPA:
The user chooses a date (available dates come from server - some days could be fully booked).
The user chooses a conference room (conference rooms available at this hotel on the date chosen in step 1 are retrieved from the server).
The user enters their name, address, billing info.
User sees confirmation page.
This same SPA will be used by multiple hotels with the same database back-end, and for the front-end I was thinking Ember.
Is RESTful the right approach for this application?
I was thinking:
GET /dates?hotel_id=xxx (should I pass the hotel ID in the URL vs. in headers vs. in the body?)
GET /rooms?hotel_id=xxx&date=yyy (should I be passing the date and hotel_id in, or somehow remember it on the server?)
POST /order with body: {date, conference_room_id, name/address/billing info}, returns { confirmation_id }
Should the name/address/billing info be put into a separate POST?
Thank you for your advice.
In a REST(ful) framework there's no concept of session. Every request must send all the required information in order to identify a resource.
I'll post an example below, based on requirements you provided.
GET /hotels/{hotel_id}/dates
Path params:
hotel_id (required)
Query params:
startDate (optional, default: today)
endDate (optional, default (example): today + 3 months)
status (optional, "available"/"booked"/"all", default: "all")
Response body: [{"id":"20160503", "dateStr":"May 5th 2016", "status": "available"}]
GET /hotels/{hotel_id}/dates/{date_id}/rooms
Path params:
hotel_id (required)
date_id (required)
Query params:
status (optional, "booked"/"available"/"all", default:"all")
Response body: [{"id": "12", "status": "available", "reservationId": ""}, {"id: "13", "status": "booked", "reservationId" : "123"}]
Note: this kind of implementation allows to list different combinations of dates and rooms (e.g. booked rooms in available days).
POST /hotels/{hotel_id}/reservations
Path params:
hotel_id(required)
Request body: {"dateId":"20160503", "roomId":"12", "firstName":"John", "lastName":"Doe", "address": "xxx", "vatNumber" : "yyy", "companyName": "zzz"}
Note: if you store billing addresses as separate entities (e.g. if your server is required to "remember" them), then it can be useful to implement POST and GET services for billing addresses (/billing) and refer to them with proper identifiers.
Response body: {"reservationId" : "324"}
GET /hotels/{hotel_id}/reservations/{reservation_id}
Path params:
hotel_id(required)
reservation_id (required)
Response body: {"dateId":"20160503", "roomId":"12", "firstName":"John", "lastName":"Doe", "address": "xxx", "vatNumber" : "yyy", "companyName": "zzz"} (same as POST request body)
GET /dates?hotel_id=xxx (should I pass the hotel ID in the URL vs. in headers vs. in the body?)
GET /rooms?hotel_id=xxx&date=yyy (should I be passing the date and hotel_id in, or somehow remember it on the server?)
POST /order with body: {date, conference_room_id, name/address/billing info}, returns { confirmation_id }
Your solution can use Restful API approach. Because it enable any other component to directly call your APIs. It can be APP, or a website or plugin or just another java program connected to internet, they just need to trigger your API and they are done.
URL you mentioned for your application, please note that one should use resource-based URL approach while building RESTful api.
GET /date/hotels/ -> Gives you all available rooms in all hotels on that particular day
GET /dates/hotels/ -> Give you list of available rooms for a particular hotel (Use dates/hotel_id instead of dates/?hotel_id=xxx). Parameter should be used to filter your result. E.g. dates/hotels/hotel_id?PIN=142: This should gives you hotel whose pin matches 142
dates/hotels?MAX_RECORD=50: This should give you list of hotels but limit to 50
You can find more about creating resource-based Restful API https://www.youtube.com/playlist?list=PLqq-6Pq4lTTZh5U8RbdXq0WaYvZBz2rbn
I would put the "Selects" into GETs as designed.
e.g. dates GET /hotel/:id/date -> Get all available dates
rooms GET /hotel/:id/date/:date/rooms -> Get all available rooms
per design in a RESTful API GET is defined for requesting data.
For the POST I would not breakdown into a seperate POST but you can put some parameter like hotel_id or date into the URL.
Best
Fabian

magento rest api (get products) is returning duplicate data

i tried to retrieve all the products using magento rest api,
I used google chrome -> POSTMAN as restclient and specified the headers properly (Consumerkey, ConsumerSecret, token, token secret)
There are only 215 products in magento and i tried to access the products using restclient
https://domain.com/api/rest/products?type=rest&category_id=7&limit=100&page=1
Question :
on page no 3 it has to return only 15 products but it is returning 100 products, why? and if i specify page no as 4 or 5 or even 100000 means it is returning the response with duplicate data?