Single Softlayer API to collect information from different services - api

SoftLayer's API has different "services" for the different objects represented in the API. Virtual Guests, Bare Metal Servers, VLANs, IP addresses, etc are all different types of services. There are also links between these services, so I want to use a single API query to get information about multiple services. The Object Mask is one way of joining the different services.
Can anyone please tell me how to achieve it using object mask.

Here you can see information about object mask:
http://sldn.softlayer.com/article/object-Masks
Now all the services are attached to your account, so you need to take a look to the service:
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Account
http://sldn.softlayer.com/reference/services/SoftLayer_Account
The service provides several methods to get differents services such as virtual guest:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getVirtualGuests
or get all the bare metal servers in your account:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getHardware
Using Object mask you just need to call the getObject method and add the properties that you want for example see this RESTFul to get the virtual guest, bare metal servers and VLans:
GET https://$USERNAME:$APIKEY#api.softlayer.com/rest/v3.1/SoftLayer_Account/getObject?objectMask=mask[virtualGuests,hardware,networkVlans]
So you can get all the information that you need in a single request however, when your response contains a big amount of data your request will throw an exception, in order to handle that you need to use result limits in your request you can see more information about how to add it to your request here:
https://sldn.softlayer.com/article/REST
Regards

Related

CrowdStrike API - How to pull all active hosts' without specifying Host Id's?

I am trying to write a query to get every active host on my network using the GET /devices/entities/online-state/v1 endpoint, however this endpoint requires a specific host's ID as a filter - meaning I would first have to query out to another API functionality to get the host ID, then hard code them into my initial query. Furthermore this API endpoint limits the amount of host Id's to 100 per query. I work on a network with 10's of thousands of endpoints, so this is not practical. I know there has to be a way to blanketly grab every host & its associated status, but I am still very new to the CS API and do not know what function to use. If anyone knows a solution - be it through a CS API endpoint I am unware of, or through syntactical corrections, (for example a wildcard I could use,) to my original query, I would really appreciate some help.

Is it okay to return all data that related to the resource in one endpoint

We have a recipe in our mobile application, this recipe has a details screen and the details screen has a lot of information, for example:
Rating
Related recipes
Ingredients
Recipe info
Nutritional info
So is that right to return all this info in the same endpoint or create multiple endpoints for each section?
One endpoint example:
GET: https://www.example.com/api/v1/{recipeId}
Multiple endpoints example:
GET: https://www.example.com/api/v1/{recipeId}/info // this API will return all info including the ingredients
GET: https://www.example.com/api/v1/{recipeId}/rating
GET: https://www.example.com/api/v1/{recipeId}/related
GET: https://www.example.com/api/v1/{recipeId}/nutritional
It depends.
If a consumer of your API is say a web page where you want to display all the information at the same time in one click, you can just bring all information together and display in one go rather than calling APIs one by one and then aggregating, however if there is possibility that individual endpoints are also required to be called separately, then you can expose multiple endpoints.
Also,your resource uri should be like this :
/api/v1/recipes/{recipeId}
In this case, you can create a single API endpoint. And, can expose a query parameter which shows which are the fields user (rest client, web) is interested in.
/api/v1/recipes/{recipeId}/?fields=all
/api/v1/recipes/{recipeId}/?fields=info,rating,related
/api/v1/recipes/{recipeId}/?fields=info
In this way, you will be saved from the headache of writing multiple endpoints for a single serving type.
Also, the schema of output message or JSON will be the same.
Maybe in future, you want to add another field to your response. You just need to add another filter name. Your client (web/rest) doesn't need to use a new API for that. Just pass the new filter and done.

Which fields of service plan provide high level information about services?

I'm trying to list service plans usinf the cf api:
from cloudfoundry_client.client import CloudFoundryClient
target_endpoint = 'https://api.ng.bluemix.net'
client = CloudFoundryClient(target_endpoint, skip_verification=False)
client.init_with_user_credentials(
ibm_id,
ibm_id_password
)
import json
for sp in client.service_plans.list():
print(sp['entity']['name'],
sp['entity']['description'])
I was hoping to see a list of services with meaningful names and description as are listed in the bluemix web console, however, some of the responses I'm receiving don't really have much meaning, e.g.
(("100mb", "Basic"), ...)
Which minimal set of fields do I need to extract to list the services?
The API endpoints are listed in the docs, and the ones of interest to you are List Service Plans and Service Plan Details.
You can also get information about everything offered by a Service Broker by hitting its Catalog endpoint.

Magento rest api resources

I have an android application connected to magento server by rest api. The application must preform some actions, but I have no examples of requests needed for the application.
For example I have this list of requests, but it is superficial enough for my application. For example, I do request:
"http://myUrl.com/api/rest/products?limit=15" and receive the list of 15 products. But after I need to receive next 15 product, and next, and next... What request can do it?
Also I need to do another requests which have no in site examples.
Where can I get more information and examples about rest api requests? Thank You in advance.
You can use various get filters available for REST request in magento GET FILTERS. To access second page you can use page filter available i.e. "http://myUrl.com/api/rest/products?limit=15&page=2". You can also combine many filters and use them as you want. Eg. For getting a result of products which have their name like 'product123', you can use: magentohost/api/rest/products?filter[1][attribute]=name&filter[1][like]=%product123%.

RESTfully creating object graphs

I'm trying to wrap my head around how to design a RESTful API for creating object graphs. For example, think of an eCommerce API, where resources have the following relationships:
Order (the main object)
Has-many Addresses
Has-many Order Line items (what does the order consist of)
Has-many Payments
Has-many Contact Info
The Order resource usually makes sense along with it's associations. In isolation, it's just a dumb container with no business significance. However, each of the associated objects has a life of it's own and may need to be manipulated independently, eg. editing the shipping address of an order, changing the contact info against an order, removing a line-item from an order after it has been placed, etc.
There are two options for designing the API:
The Order API endpoint intelligently creates itself AND its associated resources by processing "nested resource" in the content sent to POST /orders
The Order resource only creates itself and the client has to make follow-up POST requests to newly created endpoints, like POST /orders/123/addresses, PUT /orders/123/line-items/987, etc.
While the second option is simpler to implement at the server-side, it makes the client do extra work for 80% of the use-cases.
The first option has the following open questions:
How does one communicate the URL for the newly created resource? The Location header can communicate only one URL, however the server would've potentially created multiple resources.
How does one deal with errors? What if one of the associons has an error? Do we reject the entire object graph? How is that error communicated to the client?
What's the RESTful + pragmatic way of dealing with this?
How I handle this is the first way. You should not assume that a client will make all the requests it needs to. Create all the entities on the one request.
Depending on your use case you may also want to enforce an 'all-or-nothing' approach in creating the entities; ie, if something falls, everything rolls back. You can do this by using a transaction on your database (which you also can't do if everything is done through separate requests). Determining if this is the behavior you want is very specific to your situation. For instance, if you are creating an order statement you may which to employ this (you dont want to create an order that's missing items), however if you are uploading photos it may be fine.
For returning the links to the client, I always return a JSON object. You could easily populate this object with links to each of the resources created. This way the client can determine how to behave after a successful post.
Both options can be implemented RESTful. You ask:
How does one communicate the URL for the newly created resource? The Location header can communicate only one URL, however the server would've potentially created multiple resources.
This would be done the same way you communicate linkss to other Resources in the GET case. Use link elements or what ever your method is to embed the URL of a Resource into a Representation.