Usergrid: How to delete add on Metadata from Usergrid entities - apigee

I created an entity on usergrid but I find that usergrid tacks on additional data in the JSON, that I really don't want appearing in the API layer. For example here is my entity:
{
**"uuid": "7cd5c98a-7b16-11e4-9085-b5397738dcd5",
"type": "summaries",
"created": 1417629724184,
"modified": 1417629993800,**
"accountId": "123123",
"accounts": [
{
"id": "123123",
"type": "Individual",
"category": "Prepaid",
The fields uuid/type/created/modified is not what I want to pull although usergrid tacks it along. I can write logic on the receiving side which parses this out, but we don't want to write any kind of business logic in the Proxy. How can I suppress this behaviour?

Unfortunately Usergrid isn't really good for an Open API and you should put it behind a management layer like Apigee Edige. Log into your Apigee account and click on Create and Manage APIs.
In there you can manipulate the JSON payload by extracting blocks or individual elements (like below where I grab either all accounts or just the ID for the first account in the list)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Account-Response">
<DisplayName>Extract Account Response</DisplayName>
<FaultRules/>
<Properties/>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<JSONPayload>
<Variable name="allComments">
<JSONPath>$.accounts</JSONPath>
</Variable>
<Variable name="account0">
<JSONPath>$.accounts[0].id</JSONPath>
</Variable>
</JSONPayload>
<Source clearPayload="false">commentResponse</Source>
</ExtractVariables>
If you're not using Apigee you'll still need to put some kind of programatic facade in front of Usergrid to manipulate the responses.

Related

.net object to object declarative mapping with the rules in a file

I need to map objects of similar domain but from different systems and different internal representation.
I would prefer to have the mapping rules in some external file and update the rules without re-compiling the mapping tool.
Internally it's xml to json mapping and I was thinking about xslt. But I'm not sure if it's a good choice - mostly because not a lot of developers will be able to read and support it easily nowadays.
I can generate C# domain objects for both systems and use auto-mapper but it means a lot of C# code and every change would require a new build and release.
I found the following: https://github.com/camous/acmemapper
It's close to what I need but it's too json centric.
To give some example.
I would need to convert that:
<Statement name="SendEmail" continueOnFail="false">
<Parameter xsi:type="StringParameter" name="To" value="someone#fake.com" />
<Parameter xsi:type="StringParameter" name="Subject" value="test subj" />
<Parameter xsi:type="MultiLineStringParameter" name="Body" value="test body" />
</Statement>
into the
{
"workflowStepType": 0,
"actionType": 9,
"parameters": {
"recipients": [
"someone#fake.com"
],
"subject": "test subj",
"body": "test body",
"variables": []
},
"outcome": false,
"id": 1674239989193,
"displayName": "Send Email"
}
I was not able to find a library which would allow to have mapping rules in an external file and it wouldn't be as complicated as xslt to read.

Adding User Defined Interface Data (UDID) to Sabre PNR

I'm trying to add UDID fields to PNRs using the SOAP API. There is no mention of such functionality anywhere in the docs!
So I tried using the SabreCommandLLSRQ endpoint to attach the UD fields, but I don't seem to be able to make any changes, despite receiving a * response.
I've tried the following command using the endpoint:
5.S*RL[record locator]*UD56 [some test value]
For example:
5.S*RLEPLHYN*UD56 YVRYEG
But that also leads to a * response without the PNR actually changing.
Are you sure that's the right UDID format? I've never seen a record locator prepended to a UDID before. If using the SabreCommandLLSRQ endpoint I would expect your format to look like this:
5.S*UD56 [some test value]
There are many UDID formats so I may be wrong there and I know the responses can be quirky. What response do you get in a PNR if you simply enter your format into Sabre Red?
There is also support for itin remarks in the Add Itinerary Remark (AddRemarkLLSRQ), which may be worth implementing for you as well.
I found it in the API too, it is only mentioned in one of many examples in AddRemarkRQ:
If you want it to show up on the itinerary:
<AddRemarkRQ xmlns="http://webservices.sabre.com/sabreXML/2011/10" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="2.1.1">
<RemarkInfo>
<Remark Type="Invoice">
<Text>
U45-111794
</Text>
</Remark>
</RemarkInfo>
</AddRemarkRQ>
If you don't want it to show up on the itinerary:
<AddRemarkRQ xmlns="http://webservices.sabre.com/sabreXML/2011/10" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="2.1.1">
<RemarkInfo>
<Remark Type="Invoice">
<Text>
U*45-111794
</Text>
</Remark>
</RemarkInfo>
</AddRemarkRQ>
I've tested it in both CreatePassengerNameRecordRQ and AddRemarkRQ contexts.

Request External Password protected XML information and parse to my Classic ASP page

I am in charge of Web Design and Marketing for the company I work for. I kind of got thrown into the role of Coding.
We use an eCommerce software to help with site structure and product information. This site uses Classic ASP to form all pages in order to make the process easier.
Well now I have been given an XML Data Feed instructions, but I have no idea where to begin. I have read some different posts, but none really give examples of what I am trying to do.
What I need to do is submit a request to "https://ec.synnex.com/SynnexXML/PriceAvailability" which is password protected and get the return xml.
Request sent to https://ec.synnex.com/SynnexXML/PriceAvailability using below xml:
<?xml version="1.0" encoding="UTF-8" ?>
<priceRequest>
<customerNo>YOUR_ID</customerNo>
<userName>USERNAME</userName>
<password>PASSWORD</password>
<skuList>
<mfgPN>PRODUCTPARTNUMBER</mfgPN>
<lineNumber>1</lineNumber>
</skuList>
</priceRequest>
and it will return the xml:
<?xml version="1.0" encoding="UTF-8" ?>
<priceResponse>
<customerNo>YOUR ACCOUNT NUMBER</customerNo>
<userName>YOUR ID</userName>
<PriceAvailabilityList>
<mfgPN>108R00645</mfgPN>
<mfgCode>13439</mfgCode>
<status>Active</status>
<description>IMAGING UNIT, PHASER 6300/6350</description>
<GlobalProductStatusCode>Active</GlobalProductStatusCode>
<price>228.48</price>
<totalQuantity>240</totalQuantity>
<AvailabilityByWarehouse>
<warehouseInfo>
<number>3</number>
<zipcode>94538</zipcode>
<city>Fremont, CA</city>
<addr>44211 Nobel Drive</addr>
</warehouseInfo>
<qty>30</qty>
</AvailabilityByWarehouse>
<AvailabilityByWarehouse>
<warehouseInfo>
<number>4</number>
<zipcode>30071</zipcode>
<city>Norcross, GA</city>
<addr>200 Best Friend Court, Suite# 250</addr>
</warehouseInfo>
<qty>27</qty>
</AvailabilityByWarehouse>
<AvailabilityByWarehouse>
<warehouseInfo>
<number>5</number>
<zipcode>75081</zipcode>
<city>Richardson, TX</city>
<addr>660 N Dorothy Drive, Suite 100</addr>
</warehouseInfo>
<qty>2</qty>
</AvailabilityByWarehouse>
<lineNumber>1</lineNumber>
</PriceAvailabilityList>
</priceResponse>
I have no idea even where to even begin with this.
Once I get the information sent and it comes back I'm sure I can assign a Dim Value and then use the call for the value in the code I already have for displaying our products. <%=whatevervalue%>
Any help would be much appreciated.

Is it possible to use computed keys with KeyValueMaps?

I would like to use KeyValueMaps to store some simple values, but they keys I need to use would be computed at runtime. For example in my 'InitialEntries' I want to do something like this:
<KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="Sandbox-Read-Count">
<DisplayName>Sandbox - Read Count</DisplayName>
<FaultRules/>
<Properties/>
<ExclusiveCache>false</ExclusiveCache>
<ExpiryTimeInSecs>-1</ExpiryTimeInSecs>
<InitialEntries>
<Entry>
<Key>
<Parameter>{variable}.sandbox.calls</Parameter>
</Key>
<Value>0</Value>
</Entry>
</InitialEntries>
<Scope>apiproxy</Scope>
</KeyValueMapOperations>
However, when doing this I get an error when I try to save the policy:
Error while Uploading file for API Test.
messaging.config.beans.InvalidBundle. Errors:[Entity : policy-Sandbox-Read-Count, Invalid Key Names For Entries: [{apikey}.sandbox.calls];]
Is it possible to use computed values in the KeyValueMap policy? Is there a different syntax that I should be using?
I've investigated this. What happens is when you save the proxy with InitialEntries in the apiproxy-scoped KVM, the KVM is immediately created with the initial entries. Therefore, there is no way to use runtime variables, because the priming of the KVM has happened before the proxy ever runs.
You didn't use the mapIdentifier field in your KeyValueMapOperations element (look at the KeyValueMap PUT Sample in the Apigee docs), so the KVM you would create would be named kvmap.
You can use the following management API call to get a list of the KVMs and their contents for a given apiproxy:
GET https://api.enterprise.apigee.com/v1/o/{org}/apis/{apiname}/keyvaluemaps?expand=true
Authorization: Basic {base64 username:password}
Since The InitialEntries section is only used when the proxy is first loaded successfully (even if you change the InitialEntries section and redeploy, no changes will be made if the KVM of that name already exists), I think the usefulness of the InitialEntries section is rather limited. I'd recommend manually priming your KVM's using the management API to initialize the KVM:
PUT https://api.enterprise.apigee.com/v1/o/{org}/apis/{apiname}/keyvaluemaps
Authorization: Basic {base64 username:password}
Content-Type: application/json
{
"entry" : [ {
"name" : "key",
"value" : "0"
} ],
"name" : "{kvmName}"
}

What's the RESTful way to structure an URL for user interactions with other entities?

I'm trying to figure out what's the correct RESTful way to structure an URL for user interactions with other entities?
For example, I have three entities: users, posts and tags.
How do you represent "user likes post", "user follows tag" or "user follows user".
This is what I had in mind, but I'm not sure if it's the correct way to do it:
POST /user/:id/like/post/:id (user likes post)
POST /user/:id/follow/user/:id (user follows another user)
Looks very semantic, but I'm not sure about the POST method
Fair warning: I am a newbie to REST as well.
Some general remarks, taken from RESTful Web Services by Leonard Richardson and Sam Ruby:
use plural for your resource names
use POST to the resource name if the server controls the identity of the resource
use PUT to the resource/:id if the client controls the identity of the resource
Applying that to your situation I can see the following resources
/users : list of users
/users/{id} : specific user
/users/{id}/tags : list of tags used by this specific user
/users/{id}/posts : list of posts liked by this specific user
/users/{id}/follows : list of users that this specific user is following
To add a post to the ones liked by a user, I would POST to /users/{id}/posts with the identification of the post(s) that are to be added to the list of liked posts in the request body.
Similary to record that user 1 is now also following user 200 and 300, I'd POST to /users/{id}/follows with the identifications of those users in the request body.
After all you are not supplying the identification of the relationship between user 1 and the other two users, but you are adding two new relationship resources that have user 200 and user 300 as their "follows user" attribute respectively.
A database backing your app would most likely have a Users table, a Posts table and a Likes where the Likes table is the one being added to when you record that a User likes a Post. And the identification of the Likes record will not be the User's identification nor the Post's identification, but it will have its own identification (separate or as a combination of the User's and Post's identifications).
Even if you were to store the Posts liked by a User in something other than a relational model, possibly even without separate identifications for the Likes', the identification of each Likes would still be the combination of the User and the Post.
RESTful interfaces have a single well known URL as a starting point. From there every other action and entity should be accessed by hypermedia controls provided in the responses. In that sense, the URL structure should not matter at all and should not matter to the client. They could be completely opaque (e.g., like http://bit.ly/9xhUgg) and the clients will still be able to work.
Here is some useful reading:
Richardson Maturity Model
A RESTful Hypermedia API in Three Easy Steps
Having said that, from a server implementation point of view, it will easier using a structure like the one you have suggested. Something like:
GET /
<myapplication href="/">
<users href="/users"/>
<posts href="/posts"/>
<tags href="/tags"/>
</myapplication>
GET /users
<users href="/users">
<user username="johndoe" href="/users/1234"/>
<user username="janedoe" href="/users/1235"/>
<next href="/users?page=2"/>
<search href="/users">
<name type="string" cardinality="required"/>
</search>
</users>
GET /users?page=2
<users href="/users">
<user username="bobgeldof" href="/users/1236"/>
<user username="biancajager" href="/users/1237"/>
<next href="/users?page=3"/>
<prev href="/users"/>
<search href="/users">
<name type="string" cardinality="required"/>
</search>
</users>
GET /users/1236
<user username="bobgeldof" href="/users/1236">
<posts-liked href="/users/1236/posts"/>
<tags-followed href="/users/1236/tags"/>
<users-followed href="/users/1236/users"/>
<like-post href="/users/1236" method="PUT">
<post type="URL" cardinality="required"/>
</like-post>
<follow-tag href="/users/1236" method="PUT">
<tag type="URL" cardinality="required"/>
</follow-tag>
<follow-user href="/users/1236" method="PUT">
<user type="URL" cardinality="required"/>
</follow-user>
</user>
The important thing to not in the above is that when a post is being liked, or a tag or user is being followed, the URI for the post, tag or user is what is submitted as a parameter, not an ID. BTW the reason I use PUT for those operations is that the action is idempotent. If it wasn't I would use POST instead.
GET /users/1236/posts
<liked-posts href="/users/1236/posts">
<post href="http://stackoverflow.com/questions/11566436" title="What's the RESTful way to structure an URL for user interactions with other entities?">
<unlike href="/users/1236/posts?href=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F11566436" method="DELETE"/>
</post>
...
<next href="/users/1236/posts?page=2"/>
</liked-posts>
GET /users/1236/users
<followed-users href="/users/1236/users">
<user username="biancajager" href="/users/1237">
<unfollow href="/users/1236/users?href=%2Fusers%2F1237" method="DELETE">
</user>
<user username="Jorge Pedret" href="http://stackoverflow.com/users/201092/jorge-pedret">
<unfollow href="/users/1236/users?href=http%3A%2F%2Fstackoverflow.com%2Fusers%2F201092%2Fjorge-pedret" method="DELETE"/>
</user>
<next href="/users/1236/users?page=2"/>
</followed-users>
The thing I really like about the above (besides it being truly RESTful) is that because you are using URLs instead of IDs, you can like and follow posts and users in other systems. :)

Resources