api blueprint mson object with different values - apiblueprint

I have a collection response which gives back an array of user objects and want to have different values for the user attributes without to create multiple user objects. Is there a way to do this?
# Group Users
## Users Collection [/api/v1/users]
### View Users [GET]
+ Request (application/vnd.api+json)
+ Headers
Accept: application/vnd.api+json
Authorization: Bearer JWT
+ Response 200 (application/vnd.api+json)
+ Attributes
+ meta (UsersMetaData)
+ data (array[User, User])
+ links (UserLinks)
# Data Structures
## User
+ type: users (string, required, fixed)
+ id: 1 (number, required)
+ attributes (UserAttributes, required)
## UserAttributes
+ email: test#test.com (string)
+ confirmed: false (boolean)
+ first_name: Melanie (string)
I don't want to create multiple user data structures to avoid an overload. But maybe there is a way to create sample arrays or something to do this in an easy way?

Edit: I just found out this way, in case someone has the same or similar question:
+ Response 200 (application/vnd.api+json)
+ Attributes
+ data (array)
+ (User)
+ attributes (UserAttributes)
+ email: `another#mail.com` (string)
+ confirmed: true (boolean)
+ (User)
+ attributes (UserAttributes)
+ first_name: Darth Vader
This way it is possible to rewrite just the attributes for each object without the need to create new ones.

Related

Redirect to Zoho matched Customer Record with Deluge function

I'm trying to embed a Zoho CRM by iframe into an application that knows only a phone number.
(Ramble: Originally I intended to call the Zoho api to lookup the Contact by phone number and redirect to or load the Contact's Zoho page - but the hosting app doesn't seem to support enough features to accommodate Zoho's OAuth2-only authentication - so I think I'm stuck with Zoho Deluge which I'm finding to be an ATROCIOUS language)
I'm hoping to GET navigate to this Zoho Function with the phone number as a parameter, have it find the unique match, and redirect to the customer details.
response = zoho.crm.searchRecords(
"Contacts",
"", // no criteria - I hope the later parameter
// normalizes better than this would?
1, // first page
2, // of two max results - just to verify uniqueness
"{ phone: '" + phoneNumber + "'}"); // Docs are terrible. Is this the format?
// I also tried "phone:equal:..."
//if (1 < response.size()) { // script errors show up on nonsense line
// return "[Ambiguous]"; // numbers, but this seems to work until later
//} // lines are included - then errors point here
return response; // Works, but useless string output
return response.firstName; // "Invalid collection object found" - but not expected to work
return response.get(0); // 'TEXT' can not be cast to '[KEY-VALUE, TEXT, LIST]' for the function 'get'
return response.get('firstName'); // 'TEXT' can not be cast to '[KEY-VALUE, TEXT, LIST]' for the function 'get'
return response.get(0).firstName; // Improper Statement Error might be due to missing ';' at end of the line or incomplete expression
// openUrl( <string>, <window_type> ); // hoping to get here
I've also tried variations on returning from inside a for each element loop, no luck.
I THINK I've successfully found the user by phone number because I think I indeed get one match, but I can't verify it and I don't know how to derive the url of the customer detail page for the openUrl() call. Do you know how to make progress on this?
The criteria is malformed, and function searchRecords returns a list of maps.
To access the first element of al list you must use .get(0) and get an element of a map .get("First_Name")
The fields are malformed, you must get the API name of the field form crm.zoho.com->setup->API->API names->Contacts
You can use info to debug the response (info response;)
Zoho CRM API Search records
toReturn = "";
response = zoho.crm.searchRecords("Contacts", "Phone:equals:" + phoneNumber, 1, 2);
if (1 < response.size()) {
toReturn = "[Ambiguous]";
} else if (0 == response.size()) {//error triggered if use get(0) of emty list
toReturn = "[None]";
}else {
toReturn = reponse.get(0).get("First_Name");
openUrl("https://crm.zoho.com/crm/org[yourOrgID]/tab/Contacts/" + reponse.get(0).get("id"), "new window");
}
return toReturn;

Omit property of object defined in MSON

How can I ommit property from defined MSON? I have defined one simple entity (object) using MSON:
# Data Structures
## Article (object)
Represents an article
## Properties
+ id: 1 (number, optional)
+ name: My first article (string)
## Articles [/articles]
### Get all articles [GET]
Get all articles available on this website.
+ Response 200 (application/json)
+ Attributes (array[Article])
### Create an article [POST]
Create new article.
+ Request (application/json)
+ Attributes (Article)
I'm using Article object in several api endpoints. The problem is that I don't want id to be specified when posting new article so I want to omit it in the documentation for POST method. Is it possible to include Article entity in all endpoints and say what fields I want to omit?
There is no actually way how to do it.
You have two options:
declare id with attribute nullable
Declare Article without id and later inherit from Article and attach id.
# Data Structures
## Article (object)
+ name: My first article (string)
## ArticleInstance (Article)
+ id (number)
## Articles [/articles]
### Get all articles [GET]
Get all articles available on this website.
+ Response 200 (application/json)
+ Attributes (array[Article])
### Create an article [POST]
Create new article.
+ Request (application/json)
+ Attributes (Article)

How can you specify multiple GET actions for a Resource

Resources usually have multiple get methods. Get a singular or get many by query params. How is this represented in blueprint? I can do it using two resources, but that in my opinion is not correct as its the same resource.
Related to this question How does one add PUT to the resource given the uri is defined at the resource level.
Ideally this is how i think things should be written but the editor doesn't like it. I have found in docs where the HTTP_ACTION and URI can be put together, but the editor seems to want the URI at the resource level.
# Storefronts
## Read [GET /v1/storefronts{?query_params...}]
+ Parameter
query_params ...
+ Request Matching Storefronts (application/json)
+ Response 200 (application/json)
## Read [GET /v1/storefronts/{id}]
+ Parameter
+ id (string) ... id for record to return
+ Request (application/json)
+ Response 200 (application/json)
## UPDATE [PUT /v1/storefronts/{id}]
+ Parameter
+ id (string) ... id for record to update
+ Request (application/json)
+ Response 200 (application/json)
Technically you have 2 resources: one representing a single Storefront with an identity (typically supporting GET, PUT, DELETE, PATCH) and one representing a collection of Storefronts (typically supporting GET, POST). Here's how you would represent this in API Blueprint:
# Storefront [/v1/storefronts/{id}]
## Retreive a Single Storefront [GET]
## Update a Storefront [PUT]
## Delete a Storefront [DELETE]
# Storefronts Collection [/v1/storefronts]
## List Storefronts [GET]
## Create a New Storefront [POST]

How do I get Apiary model details from the rendered documentation?

I have an API contract defined in Apiary and I'm using the Resource model syntax to enable reuse of payloads.
The documentation rendered by Apiary only shows the model name though (eg Response 200 returns a [Foo][]) - without any further details on what Foo is, or any link to view the attributes in the Foo model.
Given a model, how do I see what its attributes are in the rendered documentation?
update
The relevant part of the contract is below:
### Manipulating a specific Organisation [/organisations/{id}]
Operations to retrieve and update a specific Organisation.
+ Parameters
+ id (required, guid, `F339ADA5-E836-40FE-8E90-BEF06892762E`) ... The guid Organisation `id`.
+ Model (application/json)
+ Headers
Link : <http://foobar.com/organisations/F339ADA5-E836-40FE-8E90-BEF06892762E>;rel="self"
+ Body
{
"id" : "F339ADA5-E836-40FE-8E90-BEF06892762E",
"name" : "joe's gardening supplies"
}
### Retrieve an Organisation [GET]
+ Response 200
[Organisation][]
### Update an Organisation [PATCH]
+ Request
[Organisation][]
+ Response 204
Unless you provide an example, it's just guessing, but my first guess would be wrong level of indentation. How example blueprint could look like:
FORMAT: 1A
HOST: http://www.google.com
# Model Example
Notes API is a *short texts saving* service similar to its physical paper presence on your table.
# Group Notes
Notes related resources of the **Notes API**
## Note [/notes/{id}]
A single Note object with all its details
+ Parameters
+ id (required, number, `1`) ... Numeric `id` of the Note to perform action with. Has example value.
+ Model
+ Header
X-My-Header: The Value
+ Body
{ "id": 2, "title": "Pick-up posters from post-office" }
### Retrieve a Note [GET]
+ Response 200 (application/json)
[Note][]
### Remove a Note [DELETE]
+ Response 204
Code above results in this documentation, where model is correctly incorporated on places where it's referenced (and where such reference is supported - i.e. definition of payload).
Sometimes it's helpful to read the raw version of Apiary's docs on GitHub, because it's easier to spot the right, exact format that way.
ok, from comparing the two examples I've worked it out.
in my contract the model reference
[Organisation][]
was indented two tabs instead of one. :S
that's a really easy mistake to make - would be helpful if Apiary flagged the incorrect indentation level for a model reference.

Deleting an object without objectId, from REST

Using REST, I try to delete an object in a Parse.com database, but without directly pointing to the objectId.
Here is the code:
deleteFavoriteActivity: function (from, to) {
var deleteObjects = "?where={\"fromUser\":\"" + from + "\", \"toPro\":\"" + to + "\"}";
return $http.delete(favoritesActivityUrl + deleteObjects, parseCredentials);
}
As you can see I try to delete object based on a query on 2 fields: "fromUser" and "toPro".
This won't work and return bad request. I don't know if it is even possible to delete object based on query. Is it possible ? Or must I absolutely point to objectID I want to delete ?
The endpoint for delete needs an objectid; just get the object with a get request query, get that object's id, then call delete with that id.

Resources