0

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?

user2825273
  • 565
  • 1
  • 4
  • 9

1 Answers1

0

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.

Michael Bissell
  • 1,210
  • 1
  • 8
  • 14
  • Thanks Michael, that gave some clarity, however I wanted to ask how can I do this if I am mocking an API specifically if I have a controller that is using node.js? Are there any node.js libraries you can suggest? – user2825273 Dec 03 '14 at 22:57
  • I'm not much of a node guy, but javascript in general has some great JSON parsing tools and you can run depended libraries like jquery easily enough. Check out the Node documentation on apigee at http://apigee.com/docs/api-services/content/overview-nodejs-apigee-edge and the code samples on github at https://github.com/apigee/node-samples – Michael Bissell Dec 04 '14 at 02:12