WSO2IS GET tenant by domain response does not contain the tenant id - rest

Running WSO2IS v5.11.0. After creating a tenant with domain "example.com" using the addTenant endpoint, I execute the following REST call to retrieve it
GET https://host:port/t/carbon.super/api/server/v1/tenants/domain/example.com
Contrary to what is documented in the docs, the response does not contain the tenant's id. Here is the response:
{
"domain": "example.com",
"owners": [
{
"username": "test#example.com"
}
],
"createdDate": "2021-02-04T14:43:53.598Z",
"lifecycleStatus": {
"activated": true
}
}
Why is the id not included in the response? Am I doing something wrong or is this a bug?

Seems it is a bug in IS-5.11.0. If you try the latest milestone release 5.12.0-m9 you can retrieve the tenant id in your request.
The fix https://github.com/wso2/carbon-kernel/pull/2869 should have resolved that issue in the recent milestone versions. So you can patch this into 5.11.0 and use.
In IS-5.11.0,
If you create a tenant using POST request and retrieve the tenant by its domain GET https://host:port/api/server/v1/tenants/domain/example.com the tenant UUID will not return.
If you follow the following steps:
create a tenant using POST request
Find the Location header in the response header and get the tenant UUID
Get the tenant by GET /tenants/{tenant-id}
Next get the tenant by domain GET https://host:port/api/server/v1/tenants/domain/example.com - now you will get the tenant UUID (tenant object may be cached with its unique id due to the request in 3rd step)
So it's not an API level issue. Above mentioned carbon-kernel fix should have fixed the core level issue.

Related

How to make REST calls to Tableau

I need to make REST requests to Tableau to upload and download data sources and other requests.
In the documentation mentioned here, it says that to make a REST request you need.
Server Name
SiteID
Workspace/Group ID
Where can I get these 3 things? I am new thus not familiar with the tableau platform.
Below is my Tableau Dashboard:
I see you've figured this out based on some of your other questions but here is the answer for anyone else searching.
Server name = your server's ip address or if using Tableau Online, the first portion of your url when you login.
10ay.online.tableau.com for the GET call of
https://10ay.online.tableau.com/api/3.12/sites/site-id/projects/project-id
Site ID can be returned using a POST in your API authentication call. Using the server name above the POST call would look like this https://10ay.online.tableau.com/api/3.4/auth/signin You will need to add some info to the POST body that will look like this.
{
"credentials": {
"personalAccessTokenName": "YOURTOKENNAME",
"personalAccessTokenSecret": "YOURTOKENSECRET",
"site": {
"contentUrl": "YOURSITE"
}
}
}
You don't necessarily need the group-id unless you are returning group specific info like user/group relationships. Use this in a GET call to return your group IDs by name. https://10ay.online.tableau.com/api/3.12/sites/site-id/groups

Why I can not reach this keycloak rest api end point?

I am trying to retrieve users list based on their roles. I have this role: ROLE_ADMIN. I would like to retrieve every user that have this role.
I try it with this endpoint:
http://10.10.10.10:5555/auth/demo-realm/clients/e286a05c-6641-49c3-bb7c-ffe5dd2d8c66/roles/ROLE_ADMIN/users
but it sends me back this:
{
"error": "RESTEASY003210: Could not find resource for full path: http://10.10.10.10:5555/auth/demo-realm/clients/e286a05c-6641-49c3-bb7c-ffe5dd2d8c66/roles/ROLE_ADMIN/users"
}
I found the endpoint here: https://www.keycloak.org/docs-api/11.0/rest-api/index.html under "Return List of Users that have the specified role name".
I can reach these end points for example:
http://10.10.10.10:5555/auth/realms/demo-realm/protocol/openid-connect/token
http://10.10.10.10:5555/auth/admin/realms/demo-realm/users
What did I miss? What makes this to not work?
Thanks in advance.
To get the users associate with a given Realm role you need to call the endpoint:
GET <KEYCLOAK_HOST>/auth/admin/realms/<YOUR_REALM>/roles/<ROLE_NAME>/users
to get the users associate with a given Client role you need to call this endpoint:
GET <KEYCLOAK_HOST>/auth/admin/realms/<YOUR_REALM>/clients/<CLIENT_ID>/roles/<ROLE_NAME>/users
where <CLIENT_ID> is the ID from the client to which the <ROLE_NAME> belongs to.
Finally, to get the client ID, you can call this endpoint:
GET <KEYCLOAK_HOST>/auth/admin/realms/<YOUR_REALM>/clients?clientId=<ID_OF_CLIENT>
Note that the client ID is the unique ID generated by Keycloak, whereas <ID_OF_CLIENT> is the Client ID that you have given to your Keycloak client.

Correct REST call for creating a resource

So i have a rest api, which has the following REST uri for creating a resource
/object/{id}
Im using an id that i pass in to set for the resource, in mongo there is also an objectId which is different.
json:
object: {
"id":id
.....
.....
}
mongo:
object: {
"objectId"....
"id":....
}
my question is, is this correct usage of the POST in REST. I could remove the id fromt he uri... and do a POST to ../object with the id in the body.
I thought this was correct since mongo would create an ID, the only doubt i have is that i then use this id that i have passed in for subsequent requests.
You don't need to include the ID in the URI if you are creating a new resource because route parameters are generally used to locate pre-existing resources. For example:
/countries/{countryName}/capital-city
/albums/{albumId}/release-date
/books/{bookId}/author
Just remember that your API endpoint should just describe the location of where the operation will take place, and the HTTP method should just roughly document the type of operation that will take place.
So if you want to add (POST) a new item to a table called "Objects", then your endpoint name should reflect that:
POST {your-webapp-name}/Objects

Update Stock_level in OCAPI

How I can update the inventory (stock_level) using (business manager API).
I use the business manager API to retrieve products. I am able to retrieve the products but I am not sure how I can set its stock (stock_level).
I have a special requirement where product quantity cannot exceed 1, so for that I need to set it in an inventory so that I can test it.
I have tried to see if I can set inventory level using product but that doesn't seem possible.
When I try to get inventory following is the error
{
"_v": "18.8",
"fault": {
"arguments": {
"method": "GET",
"path": "/data/v18_8/inventory_lists/*"
},
"type": "ClientAccessForbiddenException",
"message": "Access to resource 'GET /data/v18_8/inventory_lists/*' is not allowed for the current client."
}
}
There is actually a DATA API endpoint that can be used to update inventory. It is called the ProductInventoryRecords resource.
You can update a product inventory record with a PATCH eg:
PATCH /inventory_lists/{inventory_list_id}/product_inventory_records/{product_id}
With a ProductInventoryRecordAllocation payload as such:
{
"_resource_state" : "847f9c3c5867f641470b3046aeec31f07757991b792d722e10079926f7a289fb",
"allocation": {
"amount": 2000,
"reset_date": "2016-03-31T14:05:40.872Z"
}
}
See more about this document type here.
Please note that the best practice is to pass the _resource_state key to ensure that the record is properly updated. OCAPI checks to see if this value is the same as the current state of the record if that attribute provided.
So systems should first check the record to get the _resource_state by performing a GET on the same resource.
Edit Note that you'll need an authorization token that grants you access to the API in order to make this kind of call.
your question is not crystal clear but I will try to answer. Commerce Cloud has three distinct (OCAPI) APIs:
Shop API (provides similar access as a customer on the site)
Data API (provides similar access as a merchant using business manager)
Meta API (describes the API from a functional perspective)
To get availability of a product in the inventory use below call: {{shop_url}}/products/701644676568M/availability and look at ATS in the response.
To set the stocklevel go into to business manager or use business manager import utility. There is no out-of-the-box API to update the stocklevel.

How can I retrieve a large number of DELETED Campaigns, Adsets, Ads?

Task
I'm trying to retrieve all Ad Campaign, Adsets and Ads from various accounts associated with our Business Manager.
Issue
The specific endpoints that I'm accessing are:
https://graph.facebook.com/v2.8/act_xxxxxxxxxxxxx/campaigns
https://graph.facebook.com/v2.8/act_xxxxxxxxxxxxx/adsets
https://graph.facebook.com/v2.8/act_xxxxxxxxxxxxx/ads
When I query some of these accounts for all Campaigns using the filter parameter,
[{'operator': 'IN',
'field': 'ad.effective_status',
'value': [
'ACTIVE',
'PAUSED',
'DELETED',
'PENDING_REVIEW',
'DISAPPROVED',
'PREAPPROVED',
'PENDING_BILLING_INFO',
'CAMPAIGN_PAUSED',
'ARCHIVED',
'ADSET_PAUSED']}]
the Facebook API always returns this error:
{"error":{"code":1,"message":"Please reduce the amount of data you're asking for, then retry your request"}}
Troubleshooting
I've used various values for the filter parameter such as 1, 25, 50, 100, 500.
I've tried limiting the date using the date_preset parameters (this seems irrelevant).
I've tried limiting the queries by filtering down to individual campaigns by including {'operator': 'IN','field':'campaign.id','value':['xxxxxxxxxxxxx']} as an additional filter in the filter parameter.
I've attempted batch requests and querying the /insights endpoint, but I haven't had one work yet.
Other Details
When I only include ACTIVE campaigns in the filter, the query works. This has allowed me to deduce that the DELETED campaigns are the problem. In other words, these accounts have a ton of DELETED campaigns.
I'm making my requests using Postman Version 5.0.0 (5.0.0).
I imagine if I can figure out how to get the Campaigns, the Adsets and Ads will be similar. How do I go about resolving this?
The reason is that the API does not actually support querying for deleted objects for certain endpoints. I tried to obtain all campaigns for a certain account and this is the response.
Method: GET
Path:
https://graph.facebook.com/v2.10/act_XXXX/campaigns
Params: {'effective_status': '["ACTIVE","PAUSED","DELETED","ARCHIVED"]', 'fields': 'id,name,status', 'summary': 'true'}
Response:
{
"error": {
"code": 100,
"is_transient": false,
"error_subcode": 1815001,
"error_user_msg": "Requesting for deleted objects is not supported in this endpoint.",
"error_user_title": "Cannot Request for Deleted Objects",
"message": "Invalid parameter",
"type": "OAuthException",
"fbtrace_id": "FYDwMABcwxj"
}
}
After looking at the documentation I discovered this
https://developers.facebook.com/docs/marketing-api/best-practices/storing_adobjects
And here they state
If you keep the deleted object id, you can continue to retrieve the
stats or object details by individually querying the object ID.
However you cannot retrieve the deleted objects as a connection object
from a non deleted node/object.