please tell me how to get available maintenance windows by using a SoftLayer REST API.
I tried it in the following way, but it did not work.
curl -K support -d #Maintence.json -X POST https://api.softlayer.com/rest/v3/SoftLayer_Provisioning_Maintenance_Window/getMaintenceWindows
When executing the command, the following error message is displayed:
{"error":"End date must be a later date than begin
date.","code":"SoftLayer_Exception"}
The contents of the JSON file are described below:
{
"parameters":[
{
"beginDate": "2016-12-22T00:00",
"endDate": "2016-12-29T00:00",
"locationId": 138124,
"slotsNeeded" : 1
}]
}
The proper API to use here is SoftLayer_Provisioning_Maintenance_Window::getMaintenanceWindows() as opposed to the misspelled getMaintenceWindows
The API payload is still the same.
curl -K support -d #Maintence.json -X POST https://api.softlayer.com/rest/v3/SoftLayer_Provisioning_Maintenance_Window/getMaintenanceWindows
{
"parameters":[
"2016-12-22T00:00",
"2016-12-29T00:00",
138124,
1
]
}
When making API calls to the softlayer API, the parameters are not named, just listed in order that matches the documentation.
You just need to send the parameters (It's not necesary to define them in an object), so try with this json:
{
"parameters":[
"2016-12-22T00:00",
"2016-12-29T00:00",
138124,
1
]
}
References:
SoftLayer_Provisioning_Maintenance_Window::getMaintenceWindows
Related
I've been trying to make a GET request to an endpoint defined in a ktor route, but the parameters seem to be missing no matter how I try to get them. According to the documentation, I should just be able to call call.receive<Parameters>() and that should yield a map containing the data, but it's always empty.
So Far, I've tried installing my own ContentNegotiator (the convertForReceive method is never called), accessing the queryParams (always empty as well), and using the call.receiveParameters() method, which is always always empty
My CURL request looks like
curl -X GET \
http://localhost:7802/api/v2/plans \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode "id[starts_with]=asdf"
and my endpoint looks like
fun Routing.plans() {
route("plans") {
get("") {
val params = call.receive<Parameters>()
println(params)
call.respond(HttpStatusCode.NoContent)
}
}
}
I expect the parameters to contain something, but they are always empty.
I think that you won't be able to use have a body with a GET request. With that HTTP verb, most servers do not recognize a body. If you want to send a body, I'd recommend trying to change your GET request to a POST.
I think that should get you where you need to go.
We want to programatically order VSI using the flavor (for example. Balanced type), however instead of using the standard os_code, we want the VSI to be created from a public image template (ie. CentOS7-ChangeStable). From the following doc it seems to be possible.
http://softlayer-python.readthedocs.io/en/latest/_modules/SoftLayer/managers/vs.html
However I tried but got the following error:
SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_InvalidValue): Invalid value provided for 'blockDevices'. Block devices may not be provided when using an image template.
Using slcli is failing as well with a different error:
# slcli vs create --hostname testvsi --domain vmonic.local --flavor BL2_4X8X100 --image 1cc8be72-f230-4ab9-b4b2-329c3e747853 --datacenter tok02 --private
This action will incur charges on your account. Continue? [y/N]: y
SoftLayerAPIError(SoftLayer_Exception_Public): Order is missing the following category: Operating System.
Please advice whether using "image_id" with "flavor" is supported in SL API / python API. Thanks!
this is an issue with the API, the python client uses the http://sldn.softlayer.com/reference/services/softlayer_virtual_guest/createObject method to create the VSI using RESTFul the same request would be something like this:
POST: https://$USERNAME:#APIKEY#api.softlayer.com/rest/v3.1/SoftLayer_Virtual_Guest/createObject
Payload:
{
"parameters": [{
"datacenter": {
"name": "tok02"
},
"domain": "softlayer.local",
"hourlyBillingFlag": true,
"blockDeviceTemplateGroup": {
"globalIdentifier": "1cc8be72-f230-4ab9-b4b2-329c3e747853"
},
"hostname": "rcabflav",
"privateNetworkOnlyFlag": true,
"supplementalCreateObjectOptions": {
"flavorKeyName": "BL2_4X8X100"
}
}]
}
and you will get the same error, I reported this error in Softlayer, if you want you can submit a ticket in softlayer and report it as well.
Using the wso2/scim/Users endpoint as described in doc i am supposed to get a response like this one
{
"schemas":[
"urn:scim:schemas:core:1.0"
],
"totalResults":2,
"Resources":[
{
"id":"0032fd29-55a9-4fb9-be82-b1c97c073f02",
"userName":"hasinitg",
"meta":{
"lastModified":"2016-01-26T16:46:53",
"created":"2016-01-26T16:46:53",
"location":"https://localhost:9443/wso2/scim/Users/0032fd29-55a9-4fb9-be82-b1c97c073f02"
}
},
{
"id":"b228b59d-db19-4064-b637-d33c31209fae",
"userName":"pulasthim",
"meta":{
"lastModified":"2016-01-26T17:00:33",
"created":"2016-01-26T17:00:33",
"location":"https://localhost:9443/wso2/scim/Users/b228b59d-db19-4064-b637-d33c31209fae"
}
}
]
}
But i need some extra info for every user and doing subsequent requests for every user using the id to get the extra information (like an email) is too bad.
Is it possible to configure the endpoint response so that i get the information needed for the users in one request ?
You should be able to do this with SCIM extensions.
This blog post has more details.
In WSO2 Identity server 5.3.0, you can achieve this by using the attributes query parameter.
eg. Following request will list all users along with their given names in a single call.
curl -k --user admin:admin 'https://localhost:9443/wso2/scim/Users?attributes=givenname'
Please refer the post here for more details.
the links i created on the dashboard works for deep linking, but the ones i created in the API does not (it works for directing to app, but does not deep link once clicked)
LINKS:
API: https://og75.app.link/6lOctoHLLx\
CONSOLE: https://og75.app.link/lb7RahUIFx
CODE:
HTTP.post("https://api.branch.io/v1/url", :params => {
:branch_key => "KEY",
# also tried not wrapping it in data
:data => {
:linkType => "questions",
:question_id => 1
}
}).to_s
CONSOLE:
Alex from Branch.io: I'm afraid the syntax you're using to build this API call isn't familiar to me so I can't replicate locally yet.
However, a few things that might help:
You can inspect the contents of a link by appending ?debug=true to the URL (e.g., https://og75.app.link/6lOctoHLLx?debug=true). If you do this with both of your links, you'll see the API version is missing the parameters you are trying to set, which is why you don't get correct deep link behavior. Now to figure out why...
Not knowing the syntax of the call you're using in this example, I'm wondering if the data object is malformed. However, this would usually result in a 400 error with no URL returned, so I'm a little bit puzzled. If you look at our documentation for basic API link creation, you'll see the following cURL example:
Note how the contents of the data object are actually pre-escaped
curl -X POST \
\
-H "Content-Type: application/json" \
\
-d '{"branch_key":"key_live_feebgAAhbH9Tv85H5wLQhpdaefiZv5Dv", "campaign":"new_product_annoucement", "channel":"email", "tags":["monday", "test123"], "data":"{\"name\": \"Alex\", \"email\": \"alex#branch.io\", \"user_id\": \"12346\", \"$deeplink_path\": \"article/jan/123\", \"$desktop_url\": \"https://branch.io\"}"}' \
\
https://api.branch.io/v1/url
Perhaps you could try a call with the data object set as a string, and see if your link comes back with all parameters set? I have no idea if this is valid code for what you're working with, but perhaps something like this:
HTTP.post("https://api.branch.io/v1/url", :params => {
:branch_key => "KEY",
# also tried not wrapping it in data
:data => {\"linkType\": \"questions\", \"question_id\": "1"
}
}).to_s
After a lot of testing, and thanks to tips from the amazing Branch support and the debugging tips from Alex above, I finally isolated the situation.
Basically, even tho i was not using this particular parameter in iOS, I needed to add this as part of the parameters.
"$one_time_use": "",
Not doing so basically did not trigger my continueUserActivity - which is weird, even when it is the first time i am using it.
TL;DR
In my current API, I've got two endpoints to handle the context:
GET /context/get
POST /context/set '{"id": "123"}'
What's the recommended way of having this global, id-less state accessible from RESTful API?
Please assume that the context concept can't be changed.
Background
Let's say I've got a user that is logged. He's by default assigned to a context that he can change.
After the context change, all the subsequent API calls will return different data, according to the context.
Example:
// Backend
Context = "Poland"
then
$ curl -X GET http://api.myapp.com/cities
will respond:
{
"cities": [{
"id": "1",
"name": Warszawa"
}, {
"id": "2",
"name": Wrocław"
}]
}
However, if you change the context:
// Backend
Context = "USA"
then, the same URL:
$ curl -X GET http://api.myapp.com/cities
should return the different set of data:
{
"cities": [{
"id": "3",
"name": New York City"
}, {
"id": "4",
"name": Boston"
}]
}
Question
As the context is just a global state on the backend side, it doesn't have an id. It doesn't belong to any collection either. Still, I want it to be accessible in the API. There are three possible solutions I see:
Solution #1 - existing
Set a context
$ curl -X POST http://api.myapp.com/context/set '{"id": "123"}'
Get a context
$ curl -X GET http://api.myapp.com/context/get
This one doesn't really feel like a RESTful API and still, on the frontend side, I have to mock the id (using ember-data). And the resource name is singular instead of plural.
Solution #2 - mocking the id
Set a context
$ curl -X POST http://api.myapp.com/context/1 '{"contextId": "123"}'
Get a context
$ curl -X GET http://api.myapp.com/context/1
Here I mock the id to always equal to one but I feel that it's super hacky and certainly not self-explanatory... Moreover, I've got a name conflict: id vs contextId. And the resource name is singular instead of plural.
Solution #3 - actions
Set a context
$ curl -X POST http://api.myapp.com/context/actions/set '{"id": "123"}'
Get a context
$ curl -X GET http://api.myapp.com/context/actions/get
This is very similar to the first one but using actions that could be a part of my whole API design (taken from e.g. gocardless. Still, I'll have a problem how to model it on the frontend side nicely. And the resource name is singular instead of plural again.
Is there any #4 option? How should I address this problem?
Thanks!
Your three solutions are RPC, not REST. Not only they are not stateless, but setting a resource to some other resource by setting an id is very RCP'ish.
A RESTful solution, if you really want to go that way, is to set the context in a header. The client should send a header like X-ContextId or something like that, and you determine the request context you need from that.
However, don't worry too much about being RESTful if that's not what your application requires. I recommend reading the answer here: SOAP vs REST (differences)
What's the recommended way of having this global, id-less state
accessible from RESTful API?
A RESTful API is by definition stateless, no client context should be stored on the server between requests.
If you want your API to be RESTful, you'll have to pass this id with each request.