{"_id":"588f722cbcace50f0052ba29","category":{"_id":"588f722bbcace50f0052b9e6","__v":0,"project":"565f5fa26bafd40d0030a064","version":"588f722bbcace50f0052b9e1","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-02-25T18:09:36.891Z","from_sync":false,"order":4,"slug":"dashboard-api","title":"Dashboard API"},"project":"565f5fa26bafd40d0030a064","__v":0,"parentDoc":null,"user":"565f3941ea46251700972783","version":{"_id":"588f722bbcace50f0052b9e1","project":"565f5fa26bafd40d0030a064","__v":1,"createdAt":"2017-01-30T17:04:43.410Z","releaseDate":"2017-01-30T17:04:43.410Z","categories":["588f722bbcace50f0052b9e2","588f722bbcace50f0052b9e3","588f722bbcace50f0052b9e4","588f722bbcace50f0052b9e5","588f722bbcace50f0052b9e6","588f722bbcace50f0052b9e7"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"5.3.0","version":"5.3.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-01-04T22:57:18.906Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"method":"post","results":{"codes":[{"status":200,"language":"json","code":"{\n    \"proxy_endpoint\": {\n        \"api_id\": 13,\n        \"environment_id\": 9,\n        \"id\": 618,\n        \"name\": \"testProxyEndpoint\",\n        \"description\": \"testDescription\",\n        \"active\": false,\n        \"routes\": []\n    }\n}\n","name":""}]},"settings":"","examples":{"codes":[{"code":"curl -b cookies.txt -c cookies.txt -H \"Content-Type: application/json\" -X POST -d '{\"proxy_endpoint\":{\"name\":\"testProxyEndpoint\",\"description\":\"testDescription\",\"active\":false,\"cors_enabled\":false,\"environment_id\":9,\"endpoint_group_id\":null,\"routes\":[],\"components\":[],\"tests\":[]}}' https://api.nanoscale.io/apis/:id/proxy_endpoints","language":"curl"}]},"auth":"required","params":[],"url":"/proxy_endpoints"},"isReference":true,"order":13,"body":"Creates a single proxy endpoint.\n\nHere is a list of fields that can be provided:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"key\",\n    \"h-1\": \"type\",\n    \"h-2\": \"description\",\n    \"0-0\": \"name (required)\",\n    \"1-0\": \"description\",\n    \"2-0\": \"active\",\n    \"3-0\": \"cors_enabled\",\n    \"5-0\": \"environment_id (required)\",\n    \"6-0\": \"endpoint_group_id\",\n    \"7-0\": \"routes (required)\",\n    \"8-0\": \"components\",\n    \"9-0\": \"tests\",\n    \"0-1\": \"`string`\",\n    \"1-1\": \"`string`\",\n    \"2-1\": \"`boolean`\",\n    \"3-1\": \"`boolean`\",\n    \"5-1\": \"`number`\",\n    \"6-1\": \"`number`\",\n    \"7-1\": \"`array`\",\n    \"8-1\": \"`array`\",\n    \"9-1\": \"`array`\",\n    \"0-2\": \"The name of the proxy endpoint\",\n    \"1-2\": \"The description of the proxy endpoint\",\n    \"2-2\": \"Indicates if the proxy endpoint is active or inactive, defaults to `false`\",\n    \"3-2\": \"Indicates if the proxy endpoint is CORS enabled, defaults to false\",\n    \"5-2\": \"The environment identifier\",\n    \"6-2\": \"The endpoint group identifier, no endpoint group if `null` is provided\",\n    \"7-2\": \"An array of objects representing the routes belonging to the proxy endpoint\\n\\nExplained [below](http://google.com)\",\n    \"8-2\": \"The array of workflow components belonging to the proxy endpoint\\n\\nExplained [below](http://google.com)\",\n    \"9-2\": \"The array of tests\\n\\nExplained [below](http://google.com)\",\n    \"4-0\": \"api_id\",\n    \"4-1\": \"`number`\",\n    \"4-2\": \"The API identifier\"\n  },\n  \"cols\": 3,\n  \"rows\": 10\n}\n[/block]\nHere is the structure of a complete example:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{  \\n   \\\"proxy_endpoint\\\":{  \\n      \\\"name\\\":\\\"TestA\\\",\\n      \\\"description\\\":\\\"TestA\\\",\\n      \\\"active\\\":true,\\n      \\\"cors_enabled\\\":true,\\n      \\\"environment_id\\\":4,\\n      \\\"endpoint_group_id\\\":null,\\n      \\\"routes\\\": [\\n            {\\n                \\\"id\\\": 4,\\n                \\\"path\\\": \\\"/helloworld.json\\\",\\n                \\\"get_method\\\": true,\\n                \\\"post_method\\\": false,\\n                \\\"put_method\\\": false,\\n                \\\"delete_method\\\": false,\\n                \\\"proxy_endpoint_id\\\": 70,\\n                \\\"methods\\\": [\\n                    \\\"GET\\\"\\n                ]\\n            }\\n       ],\\n      \\\"components\\\":[\\n        \\t\\t// Logic Component\\n\\t\\t\\t\\t\\t\\t{\\t\\t\\n                \\\"id\\\": 72,\\n                \\\"conditional\\\": \\\"\\\",\\n                \\\"conditional_positive\\\": true,\\n                \\\"type\\\": \\\"js\\\",\\n                \\\"data\\\": \\\"response.headers[\\\\\\\"Content-Type\\\\\\\"] = \\\\\\\"application/json\\\\\\\";\\\\nresponse.body = JSON.stringify({message: \\\\\\\"Hello world! Your nanoscale.io instance is running correctly.\\\\\\\"});\\\"\\n            },\\n        \\t\\t// Single Call Component\\n        \\t\\t{\\n                \\\"id\\\": 79,\\n                \\\"conditional\\\": \\\"//Respond with statusCode 400 and do not make request if latitide and longitude is not passed in\\\\nresponse.statusCode  = 400;\\\\nrequest.params.latitude \\\\u0026\\\\u0026 request.params.longitude;\\\",\\n                \\\"conditional_positive\\\": true,\\n                \\\"type\\\": \\\"single\\\",\\n                \\\"before\\\": [\\n                    {\\n                        \\\"id\\\": 149,\\n                        \\\"type\\\": \\\"js\\\",\\n                        \\\"data\\\": \\\"//Format request to comply with remote endpoint query parameters\\\\nrequest.query.latlng = request.params.latitude + \\\\\\\",\\\\\\\" + request.params.longitude;\\\\n\\\\n//Remove unneeded query params\\\\ndelete request.query.latitude;\\\\ndelete request.query.longitude;\\\\n\\\\n\\\"\\n                    }\\n                ],\\n                \\\"after\\\": [\\n                    {\\n                        \\\"id\\\": 150,\\n                        \\\"type\\\": \\\"js\\\",\\n                        \\\"data\\\": \\\"//Accept json string response\\\\nresponse.headers[\\\\\\\"Content-Type\\\\\\\"] = \\\\\\\"application/json\\\\\\\";\\\\n\\\\n\\\\nresponse.statusCode = 200;\\\\nparsed_data = [];\\\\n\\\\n//Convert response to json object \\\\nresponse_data = JSON.parse(response.body);\\\\n\\\\n//Format response \\\\nresponse_data.results.forEach(function(p){\\\\n var p_data = {};\\\\n p_data.open_now = {};\\\\n p_data.latitude = {};\\\\n p_data.longitude = {};\\\\n  p_data.address = p.formatted_address;\\\\n  p_data.latitude = p.geometry.location.lat;\\\\n  p_data.longitude = p.geometry.location.lng;\\\\n  parsed_data.push(p_data);\\\\n});\\\\n\\\\n//Return json string\\\\nresponse.body = JSON.stringify(parsed_data);\\\"\\n                    }\\n                ],\\n                \\\"call\\\": {\\n                    \\\"id\\\": 73,\\n                    \\\"remote_endpoint_id\\\": 46,\\n                    \\\"endpoint_name_override\\\": \\\"\\\",\\n                    \\\"conditional\\\": \\\"\\\",\\n                    \\\"conditional_positive\\\": true\\n                },\\n                \\\"data\\\": \\\"\\\"\\n            },\\n\\t\\t        // Multi-Call Component\\n        \\t\\t{\\t\\t\\n                \\\"id\\\": 91,\\n                \\\"conditional\\\": \\\"\\\",\\n                \\\"conditional_positive\\\": true,\\n                \\\"type\\\": \\\"multi\\\",\\n                \\\"before\\\": [\\n                    {\\n                        \\\"id\\\": 173,\\n                        \\\"type\\\": \\\"js\\\",\\n                        \\\"data\\\": \\\"\\\"\\n                    }\\n                ],\\n                \\\"after\\\": [\\n                    {\\n                        \\\"id\\\": 174,\\n                        \\\"type\\\": \\\"js\\\",\\n                        \\\"data\\\": \\\"//Set response to JSON string format\\\\nresponse.headers[\\\\\\\"Content-Type\\\\\\\"] = \\\\\\\"application/json\\\\\\\";\\\\n\\\\n//Get responses from remote endpoint using {codeName}.response var initialized by remote endpoint\\\\nproducts_response_data = JSON.parse(getProducts.response.body);\\\\nratings_response_data = JSON.parse(getRatings.response.body);\\\\n\\\\n//Create variable for merged response\\\\nvar merged_response = [];\\\\n\\\\n//Merge responses based on Products and their ratings\\\\nratings_response_data.forEach(function(r){\\\\n  p =  _.findWhere(products_response_data, {\\\\\\\"id\\\\\\\": r.product_id});\\\\n  p.rating = r.rating;\\\\n  merged_response.push(p);\\\\n});\\\\n\\\\n//Return merged response\\\\nresponse.body = JSON.stringify(merged_response);\\\"\\n                    }\\n                ],\\n                \\\"calls\\\": [\\n                    {\\n                        \\\"id\\\": 85,\\n                        \\\"remote_endpoint_id\\\": 52,\\n                        \\\"endpoint_name_override\\\": \\\"\\\",\\n                        \\\"conditional\\\": \\\"\\\",\\n                        \\\"conditional_positive\\\": true,\\n                        \\\"before\\\": [\\n                            {\\n                                \\\"id\\\": 175,\\n                                \\\"type\\\": \\\"js\\\",\\n                                \\\"data\\\": \\\"\\\"\\n                            }\\n                        ],\\n                        \\\"after\\\": [\\n                            {\\n                                \\\"id\\\": 176,\\n                                \\\"type\\\": \\\"js\\\",\\n                                \\\"data\\\": \\\"\\\"\\n                            }\\n                        ]\\n                    },\\n                    {\\n                        \\\"id\\\": 86,\\n                        \\\"remote_endpoint_id\\\": 47,\\n                        \\\"endpoint_name_override\\\": \\\"\\\",\\n                        \\\"conditional\\\": \\\"\\\",\\n                        \\\"conditional_positive\\\": true,\\n                        \\\"before\\\": [\\n                            {\\n                                \\\"id\\\": 177,\\n                                \\\"type\\\": \\\"js\\\",\\n                                \\\"data\\\": \\\"\\\"\\n                            }\\n                        ],\\n                        \\\"after\\\": [\\n                            {\\n                                \\\"id\\\": 178,\\n                                \\\"type\\\": \\\"js\\\",\\n                                \\\"data\\\": \\\"\\\"\\n                            }\\n                        ]\\n                    }\\n                ],\\n                \\\"data\\\": \\\"\\\"\\n            }\\n      ],\\n      \\\"tests\\\":[  \\n\\t\\t\\t\\t\\t{\\n                \\\"id\\\": 31,\\n                \\\"name\\\": \\\"TestCase1\\\",\\n                \\\"methods\\\": [\\n                    \\\"GET\\\"\\n                ],\\n                \\\"route\\\": \\\"/helloworld\\\",\\n                \\\"body\\\": \\\"\\\",\\n                \\\"pairs\\\": [\\n                    {\\n                        \\\"id\\\": 22,\\n                        \\\"type\\\": \\\"header\\\",\\n                        \\\"key\\\": \\\"auth\\\",\\n                        \\\"value\\\": \\\"token\\\"\\n                    },\\n                    {\\n                        \\\"id\\\": 23,\\n                        \\\"type\\\": \\\"get\\\",\\n                        \\\"key\\\": \\\"query\\\",\\n                        \\\"value\\\": \\\"param\\\"\\n                    },\\n                    {\\n                        \\\"id\\\": 24,\\n                        \\\"type\\\": \\\"path\\\",\\n                        \\\"key\\\": \\\"argument\\\",\\n                        \\\"value\\\": \\\"one\\\"\\n                    }\\n                ],\\n                \\\"data\\\": null\\n            }\\n      ]\\n   }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n## How can I add a route when creating a new proxy endpoint?\n\nA proxy endpoint's routes is an array of route objects. Each object containing the following fields:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"key\",\n    \"h-1\": \"type\",\n    \"h-2\": \"description\",\n    \"0-0\": \"id\",\n    \"1-0\": \"path (required)\",\n    \"2-0\": \"methods (required)\",\n    \"3-0\": \"get_method\",\n    \"4-0\": \"put_method\",\n    \"5-0\": \"post_method\",\n    \"6-0\": \"delete_method\",\n    \"7-0\": \"proxy_endpoint_id\",\n    \"0-2\": \"The route identifier\",\n    \"0-1\": \"`number`\",\n    \"1-1\": \"`string`\",\n    \"2-1\": \"`array`\",\n    \"3-1\": \"`boolean`\",\n    \"4-1\": \"`boolean`\",\n    \"5-1\": \"`boolean`\",\n    \"6-1\": \"`boolean`\",\n    \"7-1\": \"`number`\",\n    \"1-2\": \"The url path of the route\",\n    \"2-2\": \"The array of HTTP methods the route accepts. It can be any of the following types: `GET`, `PUT`, `POST`, `DELETE`\",\n    \"3-2\": \"Indicates if the route accepts GET requests\",\n    \"4-2\": \"Indicates if the route accepts PUT requests\",\n    \"5-2\": \"Indicates if the route accepts POST requests\",\n    \"6-2\": \"Indicates if the route accepts DELETE requests\",\n    \"7-2\": \"The identifier of the proxy endpoint the route\"\n  },\n  \"cols\": 3,\n  \"rows\": 8\n}\n[/block]\nHere is an example of a `/geolocation` `GET` route: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{  \\n   \\t.... \\n  \\t\\\"routes\\\":[  \\n      {  \\n         \\\"id\\\":\\\"12\\\",\\n         \\\"path\\\":\\\"/geolocation\\\",\\n         \\\"methods\\\":[  \\n            \\\"GET\\\"\\n         ],\\n         \\\"get_method\\\":true,\\n         \\\"put_method\\\":false,\\n         \\\"post_method\\\":false,\\n         \\\"delete_method\\\":false,\\n         \\\"proxy_endpoint_id\\\":15\\n      }\\n   ],\\n   ....\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n## How can I add a workflow component?\n\nA proxy endpoint's workflow components is an array of component objects. Each object containing the following fields:\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"id\",\n    \"0-2\": \"The component identifier\",\n    \"0-1\": \"`number`\",\n    \"1-0\": \"conditional\",\n    \"2-0\": \"conditional_positive\",\n    \"3-0\": \"type (required)\",\n    \"h-0\": \"key\",\n    \"h-1\": \"type\",\n    \"h-2\": \"description\",\n    \"4-0\": \"data\",\n    \"5-0\": \"before\",\n    \"6-0\": \"before/id\",\n    \"7-0\": \"before/type\",\n    \"8-0\": \"before/data\",\n    \"9-0\": \"after\",\n    \"10-0\": \"after/id\",\n    \"11-0\": \"after/type\",\n    \"12-0\": \"after/data\",\n    \"13-0\": \"call\",\n    \"14-0\": \"calls\",\n    \"15-0\": \"call/id\",\n    \"16-0\": \"call/remote_endpoint_id\",\n    \"17-0\": \"call/endpoint_name_override\",\n    \"18-0\": \"call/conditional\",\n    \"19-0\": \"call/conditional_positive\",\n    \"20-0\": \"call/before\",\n    \"21-0\": \"call/before/id\",\n    \"22-0\": \"call/before/type\",\n    \"23-0\": \"call/before/data\",\n    \"24-0\": \"call/after\",\n    \"25-0\": \"call/after/id\",\n    \"26-0\": \"call/after/type\",\n    \"27-0\": \"call/after/data\",\n    \"1-1\": \"`string`\",\n    \"2-1\": \"`boolean`\",\n    \"3-1\": \"`string`\",\n    \"4-1\": \"`string`\",\n    \"5-1\": \"`array`\",\n    \"6-1\": \"`number`\",\n    \"7-1\": \"`string`\",\n    \"8-1\": \"`string`\",\n    \"9-1\": \"`array`\",\n    \"10-1\": \"`number`\",\n    \"11-1\": \"`string`\",\n    \"12-1\": \"`string`\",\n    \"13-1\": \"`object`\",\n    \"14-1\": \"`array`\",\n    \"15-1\": \"`number`\",\n    \"16-1\": \"`number`\",\n    \"17-1\": \"`string`\",\n    \"18-1\": \"`string`\",\n    \"19-1\": \"`boolean`\",\n    \"20-1\": \"`array`\",\n    \"21-1\": \"`number`\",\n    \"22-1\": \"`string`\",\n    \"23-1\": \"`string`\",\n    \"24-1\": \"`array`\",\n    \"25-1\": \"`number`\",\n    \"26-1\": \"`string`\",\n    \"27-1\": \"`string`\",\n    \"1-2\": \"The type of conditional logic check\",\n    \"2-2\": \"Indicates if the conditional statement is \\\"if\\\" (`true`) or \\\"unless\\\" (`false`). It will default to `false` if the field is not included.\",\n    \"3-2\": \"The type of workflow component. It can be one of the following types: `js`, `single`, `multi`.\",\n    \"4-2\": \"The conditional logic\",\n    \"5-2\": \"The before request logic object\",\n    \"6-2\": \"The before request logic object identifier\",\n    \"7-2\": \"The before request logic type\",\n    \"8-2\": \"The before request logic\",\n    \"9-2\": \"The after request logic object\",\n    \"10-2\": \"The after request logic object identifier\",\n    \"11-2\": \"The after request logic type\",\n    \"12-2\": \"The after request logic\",\n    \"13-2\": \"The remote endpoint call object. This field is required if `type` is `single`.\",\n    \"14-2\": \"The array of remote endpoint call objects\",\n    \"15-2\": \"The remote endpoint call identifier\",\n    \"16-2\": \"The remote endpoint identifier. This field is required if `type` is `single` or `multi`.\",\n    \"17-2\": \"The name overriding the remote endpoint name\",\n    \"18-2\": \"The type of conditional logic\",\n    \"19-2\": \"Indicates if the conditional statement is \\\"if\\\" or \\\"unless\\\"\",\n    \"20-2\": \"The before request logic object\",\n    \"21-2\": \"The before request logic object identifier\",\n    \"22-2\": \"The before request logic type\",\n    \"23-2\": \"The before request logic\",\n    \"24-2\": \"The after request logic object\",\n    \"25-2\": \"The after request logic object identifier\",\n    \"26-2\": \"The after request logic type\",\n    \"27-2\": \"The after request logic\"\n  },\n  \"cols\": 3,\n  \"rows\": 28\n}\n[/block]\n**There are 3 types of workflow components: logic, single call, and multi-call.**\n\n**1. Logic Components**\n\nHere is an example of a logic component that returns a message based on the provided conditional logic:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{  \\n   .... \\n   \\\"components\\\":[  \\n      {  \\n         \\\"id\\\":72,\\n         \\\"conditional\\\":\\\"1 == 1;\\\",\\n         \\\"conditional_positive\\\":true,\\n         \\\"type\\\":\\\"js\\\",\\n         \\\"data\\\":\\\"response.headers[\\\\\\\"Content-Type\\\\\\\"] = \\\\\\\"application/json\\\\\\\";\\\\nresponse.body = JSON.stringify({message: \\\\\\\"Hello world! Your nanoscale.io instance is running correctly.\\\\\\\"});\\\"\\n      }\\n   ],\\n   ....\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n**2. Single Call Components**\n\nHere is an example of a single call component that retrieves a record from a remote mongo database:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{  \\n\\t\\t.... \\n  \\t\\\"components\\\":[  \\n      {  \\n         \\\"id\\\":82,\\n         \\\"conditional\\\":\\\"1 == 1;\\\",\\n         \\\"conditional_positive\\\":true,\\n         \\\"type\\\":\\\"single\\\",\\n         \\\"before\\\":[  \\n            {  \\n               \\\"id\\\":155,\\n               \\\"type\\\":\\\"js\\\",\\n               \\\"data\\\":\\\"var id =  request.vars.id ; \\\\n\\\\nmongo.request = new AP.Mongo.Request();\\\\nlog(id) ; \\\\n\\\\nmongo.request.query('hats',  'find' ,   {\\\\\\\"_id\\\\\\\":{\\\\\\\"_id\\\\\\\":id , \\\\\\\"type\\\\\\\":\\\\\\\"id\\\\\\\"}} ) ;\\\"\\n            }\\n         ],\\n         \\\"after\\\":[  \\n            {  \\n               \\\"id\\\":156,\\n               \\\"type\\\":\\\"js\\\",\\n               \\\"data\\\":\\\"response.statusCode = 200\\\\n\\\\nresponse.body = JSON.stringify(mongo.response.data); \\\\n\\\\n\\\"\\n            }\\n         ],\\n         \\\"call\\\":{  \\n            \\\"id\\\":76,\\n            \\\"remote_endpoint_id\\\":49,\\n            \\\"endpoint_name_override\\\":\\\"\\\",\\n            \\\"conditional\\\":\\\"\\\",\\n            \\\"conditional_positive\\\":true\\n         },\\n         \\\"data\\\":\\\"\\\"\\n      }\\n    ]   \\n\\t\\t....\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n**3. Multi-Call Components**\n\nHere is an example of a multi-call component that calls two remote endpoints in parallel and merges their results.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{  \\n    .... \\n  \\t\\\"components\\\":[  \\n      {  \\n         \\\"id\\\":91,\\n         \\\"conditional\\\":\\\"\\\",\\n         \\\"conditional_positive\\\":true,\\n         \\\"type\\\":\\\"multi\\\",\\n         \\\"before\\\":[  \\n            {  \\n               \\\"id\\\":173,\\n               \\\"type\\\":\\\"js\\\",\\n               \\\"data\\\":\\\"\\\"\\n            }\\n         ],\\n         \\\"after\\\":[  \\n            {  \\n               \\\"id\\\":174,\\n               \\\"type\\\":\\\"js\\\",\\n               \\\"data\\\":\\\"//Set response to JSON string format\\\\nresponse.headers[\\\\\\\"Content-Type\\\\\\\"] = \\\\\\\"application/json\\\\\\\";\\\\n\\\\n//Get responses from remote endpoint using {codeName}.response var initialized by remote endpoint\\\\nproducts_response_data = JSON.parse(getProducts.response.body);\\\\nratings_response_data = JSON.parse(getRatings.response.body);\\\\n\\\\n//Create variable for merged response\\\\nvar merged_response = [];\\\\n\\\\n//Merge responses based on Products and their ratings\\\\nratings_response_data.forEach(function(r){\\\\n  p =  _.findWhere(products_response_data, {\\\\\\\"id\\\\\\\": r.product_id});\\\\n  p.rating = r.rating;\\\\n  merged_response.push(p);\\\\n});\\\\n\\\\n//Return merged response\\\\nresponse.body = JSON.stringify(merged_response);\\\"\\n            }\\n         ],\\n         \\\"calls\\\":[  \\n            {  \\n               \\\"id\\\":85,\\n               \\\"remote_endpoint_id\\\":52,\\n               \\\"endpoint_name_override\\\":\\\"\\\",\\n               \\\"conditional\\\":\\\"\\\",\\n               \\\"conditional_positive\\\":true,\\n               \\\"before\\\":[  \\n                  {  \\n                     \\\"id\\\":175,\\n                     \\\"type\\\":\\\"js\\\",\\n                     \\\"data\\\":\\\"\\\"\\n                  }\\n               ],\\n               \\\"after\\\":[  \\n                  {  \\n                     \\\"id\\\":176,\\n                     \\\"type\\\":\\\"js\\\",\\n                     \\\"data\\\":\\\"\\\"\\n                  }\\n               ]\\n            },\\n            {  \\n               \\\"id\\\":86,\\n               \\\"remote_endpoint_id\\\":47,\\n               \\\"endpoint_name_override\\\":\\\"\\\",\\n               \\\"conditional\\\":\\\"\\\",\\n               \\\"conditional_positive\\\":true,\\n               \\\"before\\\":[  \\n                  {  \\n                     \\\"id\\\":177,\\n                     \\\"type\\\":\\\"js\\\",\\n                     \\\"data\\\":\\\"\\\"\\n                  }\\n               ],\\n               \\\"after\\\":[  \\n                  {  \\n                     \\\"id\\\":178,\\n                     \\\"type\\\":\\\"js\\\",\\n                     \\\"data\\\":\\\"\\\"\\n                  }\\n               ]\\n            }\\n         ],\\n         \\\"data\\\":\\\"\\\"\\n      }\\n   ]   \\n\\t ....\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n## How can I add a test component?\n\nA proxy endpoint's tests is an array of component objects. Each object containing the following fields:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"key\",\n    \"h-1\": \"type\",\n    \"h-2\": \"description\",\n    \"0-0\": \"id\",\n    \"1-0\": \"name (required)\",\n    \"2-0\": \"methods (required)\",\n    \"3-0\": \"route (required)\",\n    \"4-0\": \"body\",\n    \"5-0\": \"pairs\",\n    \"6-0\": \"pair/id\",\n    \"7-0\": \"pair/type\",\n    \"8-0\": \"pair/key\",\n    \"9-0\": \"pair/value\",\n    \"10-0\": \"data\",\n    \"0-1\": \"`number`\",\n    \"1-1\": \"`string`\",\n    \"2-1\": \"`array`\",\n    \"3-1\": \"`string`\",\n    \"4-1\": \"`string`\",\n    \"5-1\": \"`array`\",\n    \"6-1\": \"`number`\",\n    \"7-1\": \"`string`\",\n    \"8-1\": \"`string`\",\n    \"9-1\": \"`string`\",\n    \"10-1\": \"`string`\",\n    \"0-2\": \"The test identifier\",\n    \"1-2\": \"The test name\",\n    \"2-2\": \"The array of HTTP methods the route accepts\",\n    \"3-2\": \"The url path of the route\",\n    \"4-2\": \"The test request body\",\n    \"5-2\": \"The array of test meta data pairs\",\n    \"6-2\": \"The test meta data pair identifier\",\n    \"7-2\": \"The the test meta data pair type (header, query parameter, or type)\",\n    \"8-2\": \"The the test meta data pair key\",\n    \"9-2\": \"The the test meta data pair value\",\n    \"10-2\": \"The test data\"\n  },\n  \"cols\": 3,\n  \"rows\": 11\n}\n[/block]\nHere is a an example of a test component:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{  \\n    .... \\n  \\t\\\"tests\\\":[  \\n      {  \\n         \\\"id\\\":31,\\n         \\\"name\\\":\\\"TestCase1\\\",\\n         \\\"methods\\\":[  \\n            \\\"GET\\\"\\n         ],\\n         \\\"route\\\":\\\"/helloworld\\\",\\n         \\\"body\\\":\\\"\\\",\\n         \\\"pairs\\\":[  \\n            {  \\n               \\\"id\\\":22,\\n               \\\"type\\\":\\\"header\\\",\\n               \\\"key\\\":\\\"auth\\\",\\n               \\\"value\\\":\\\"token\\\"\\n            },\\n            {  \\n               \\\"id\\\":23,\\n               \\\"type\\\":\\\"get\\\",\\n               \\\"key\\\":\\\"query\\\",\\n               \\\"value\\\":\\\"param\\\"\\n            },\\n            {  \\n               \\\"id\\\":24,\\n               \\\"type\\\":\\\"path\\\",\\n               \\\"key\\\":\\\"argument\\\",\\n               \\\"value\\\":\\\"one\\\"\\n            }\\n         ],\\n         \\\"data\\\":null\\n      }\\n   ]   \\n\\t ....\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"apisidproxy_endpoints","type":"endpoint","title":"/proxy_endpoints"}

post/proxy_endpoints


Definition

{{ api_url }}{{ page_api_url }}

Examples


Result Format


Documentation

Creates a single proxy endpoint. Here is a list of fields that can be provided: [block:parameters] { "data": { "h-0": "key", "h-1": "type", "h-2": "description", "0-0": "name (required)", "1-0": "description", "2-0": "active", "3-0": "cors_enabled", "5-0": "environment_id (required)", "6-0": "endpoint_group_id", "7-0": "routes (required)", "8-0": "components", "9-0": "tests", "0-1": "`string`", "1-1": "`string`", "2-1": "`boolean`", "3-1": "`boolean`", "5-1": "`number`", "6-1": "`number`", "7-1": "`array`", "8-1": "`array`", "9-1": "`array`", "0-2": "The name of the proxy endpoint", "1-2": "The description of the proxy endpoint", "2-2": "Indicates if the proxy endpoint is active or inactive, defaults to `false`", "3-2": "Indicates if the proxy endpoint is CORS enabled, defaults to false", "5-2": "The environment identifier", "6-2": "The endpoint group identifier, no endpoint group if `null` is provided", "7-2": "An array of objects representing the routes belonging to the proxy endpoint\n\nExplained [below](http://google.com)", "8-2": "The array of workflow components belonging to the proxy endpoint\n\nExplained [below](http://google.com)", "9-2": "The array of tests\n\nExplained [below](http://google.com)", "4-0": "api_id", "4-1": "`number`", "4-2": "The API identifier" }, "cols": 3, "rows": 10 } [/block] Here is the structure of a complete example: [block:code] { "codes": [ { "code": "{ \n \"proxy_endpoint\":{ \n \"name\":\"TestA\",\n \"description\":\"TestA\",\n \"active\":true,\n \"cors_enabled\":true,\n \"environment_id\":4,\n \"endpoint_group_id\":null,\n \"routes\": [\n {\n \"id\": 4,\n \"path\": \"/helloworld.json\",\n \"get_method\": true,\n \"post_method\": false,\n \"put_method\": false,\n \"delete_method\": false,\n \"proxy_endpoint_id\": 70,\n \"methods\": [\n \"GET\"\n ]\n }\n ],\n \"components\":[\n \t\t// Logic Component\n\t\t\t\t\t\t{\t\t\n \"id\": 72,\n \"conditional\": \"\",\n \"conditional_positive\": true,\n \"type\": \"js\",\n \"data\": \"response.headers[\\\"Content-Type\\\"] = \\\"application/json\\\";\\nresponse.body = JSON.stringify({message: \\\"Hello world! Your nanoscale.io instance is running correctly.\\\"});\"\n },\n \t\t// Single Call Component\n \t\t{\n \"id\": 79,\n \"conditional\": \"//Respond with statusCode 400 and do not make request if latitide and longitude is not passed in\\nresponse.statusCode = 400;\\nrequest.params.latitude \\u0026\\u0026 request.params.longitude;\",\n \"conditional_positive\": true,\n \"type\": \"single\",\n \"before\": [\n {\n \"id\": 149,\n \"type\": \"js\",\n \"data\": \"//Format request to comply with remote endpoint query parameters\\nrequest.query.latlng = request.params.latitude + \\\",\\\" + request.params.longitude;\\n\\n//Remove unneeded query params\\ndelete request.query.latitude;\\ndelete request.query.longitude;\\n\\n\"\n }\n ],\n \"after\": [\n {\n \"id\": 150,\n \"type\": \"js\",\n \"data\": \"//Accept json string response\\nresponse.headers[\\\"Content-Type\\\"] = \\\"application/json\\\";\\n\\n\\nresponse.statusCode = 200;\\nparsed_data = [];\\n\\n//Convert response to json object \\nresponse_data = JSON.parse(response.body);\\n\\n//Format response \\nresponse_data.results.forEach(function(p){\\n var p_data = {};\\n p_data.open_now = {};\\n p_data.latitude = {};\\n p_data.longitude = {};\\n p_data.address = p.formatted_address;\\n p_data.latitude = p.geometry.location.lat;\\n p_data.longitude = p.geometry.location.lng;\\n parsed_data.push(p_data);\\n});\\n\\n//Return json string\\nresponse.body = JSON.stringify(parsed_data);\"\n }\n ],\n \"call\": {\n \"id\": 73,\n \"remote_endpoint_id\": 46,\n \"endpoint_name_override\": \"\",\n \"conditional\": \"\",\n \"conditional_positive\": true\n },\n \"data\": \"\"\n },\n\t\t // Multi-Call Component\n \t\t{\t\t\n \"id\": 91,\n \"conditional\": \"\",\n \"conditional_positive\": true,\n \"type\": \"multi\",\n \"before\": [\n {\n \"id\": 173,\n \"type\": \"js\",\n \"data\": \"\"\n }\n ],\n \"after\": [\n {\n \"id\": 174,\n \"type\": \"js\",\n \"data\": \"//Set response to JSON string format\\nresponse.headers[\\\"Content-Type\\\"] = \\\"application/json\\\";\\n\\n//Get responses from remote endpoint using {codeName}.response var initialized by remote endpoint\\nproducts_response_data = JSON.parse(getProducts.response.body);\\nratings_response_data = JSON.parse(getRatings.response.body);\\n\\n//Create variable for merged response\\nvar merged_response = [];\\n\\n//Merge responses based on Products and their ratings\\nratings_response_data.forEach(function(r){\\n p = _.findWhere(products_response_data, {\\\"id\\\": r.product_id});\\n p.rating = r.rating;\\n merged_response.push(p);\\n});\\n\\n//Return merged response\\nresponse.body = JSON.stringify(merged_response);\"\n }\n ],\n \"calls\": [\n {\n \"id\": 85,\n \"remote_endpoint_id\": 52,\n \"endpoint_name_override\": \"\",\n \"conditional\": \"\",\n \"conditional_positive\": true,\n \"before\": [\n {\n \"id\": 175,\n \"type\": \"js\",\n \"data\": \"\"\n }\n ],\n \"after\": [\n {\n \"id\": 176,\n \"type\": \"js\",\n \"data\": \"\"\n }\n ]\n },\n {\n \"id\": 86,\n \"remote_endpoint_id\": 47,\n \"endpoint_name_override\": \"\",\n \"conditional\": \"\",\n \"conditional_positive\": true,\n \"before\": [\n {\n \"id\": 177,\n \"type\": \"js\",\n \"data\": \"\"\n }\n ],\n \"after\": [\n {\n \"id\": 178,\n \"type\": \"js\",\n \"data\": \"\"\n }\n ]\n }\n ],\n \"data\": \"\"\n }\n ],\n \"tests\":[ \n\t\t\t\t\t{\n \"id\": 31,\n \"name\": \"TestCase1\",\n \"methods\": [\n \"GET\"\n ],\n \"route\": \"/helloworld\",\n \"body\": \"\",\n \"pairs\": [\n {\n \"id\": 22,\n \"type\": \"header\",\n \"key\": \"auth\",\n \"value\": \"token\"\n },\n {\n \"id\": 23,\n \"type\": \"get\",\n \"key\": \"query\",\n \"value\": \"param\"\n },\n {\n \"id\": 24,\n \"type\": \"path\",\n \"key\": \"argument\",\n \"value\": \"one\"\n }\n ],\n \"data\": null\n }\n ]\n }\n}", "language": "json" } ] } [/block] ## How can I add a route when creating a new proxy endpoint? A proxy endpoint's routes is an array of route objects. Each object containing the following fields: [block:parameters] { "data": { "h-0": "key", "h-1": "type", "h-2": "description", "0-0": "id", "1-0": "path (required)", "2-0": "methods (required)", "3-0": "get_method", "4-0": "put_method", "5-0": "post_method", "6-0": "delete_method", "7-0": "proxy_endpoint_id", "0-2": "The route identifier", "0-1": "`number`", "1-1": "`string`", "2-1": "`array`", "3-1": "`boolean`", "4-1": "`boolean`", "5-1": "`boolean`", "6-1": "`boolean`", "7-1": "`number`", "1-2": "The url path of the route", "2-2": "The array of HTTP methods the route accepts. It can be any of the following types: `GET`, `PUT`, `POST`, `DELETE`", "3-2": "Indicates if the route accepts GET requests", "4-2": "Indicates if the route accepts PUT requests", "5-2": "Indicates if the route accepts POST requests", "6-2": "Indicates if the route accepts DELETE requests", "7-2": "The identifier of the proxy endpoint the route" }, "cols": 3, "rows": 8 } [/block] Here is an example of a `/geolocation` `GET` route: [block:code] { "codes": [ { "code": "{ \n \t.... \n \t\"routes\":[ \n { \n \"id\":\"12\",\n \"path\":\"/geolocation\",\n \"methods\":[ \n \"GET\"\n ],\n \"get_method\":true,\n \"put_method\":false,\n \"post_method\":false,\n \"delete_method\":false,\n \"proxy_endpoint_id\":15\n }\n ],\n ....\n}", "language": "json" } ] } [/block] ## How can I add a workflow component? A proxy endpoint's workflow components is an array of component objects. Each object containing the following fields: [block:parameters] { "data": { "0-0": "id", "0-2": "The component identifier", "0-1": "`number`", "1-0": "conditional", "2-0": "conditional_positive", "3-0": "type (required)", "h-0": "key", "h-1": "type", "h-2": "description", "4-0": "data", "5-0": "before", "6-0": "before/id", "7-0": "before/type", "8-0": "before/data", "9-0": "after", "10-0": "after/id", "11-0": "after/type", "12-0": "after/data", "13-0": "call", "14-0": "calls", "15-0": "call/id", "16-0": "call/remote_endpoint_id", "17-0": "call/endpoint_name_override", "18-0": "call/conditional", "19-0": "call/conditional_positive", "20-0": "call/before", "21-0": "call/before/id", "22-0": "call/before/type", "23-0": "call/before/data", "24-0": "call/after", "25-0": "call/after/id", "26-0": "call/after/type", "27-0": "call/after/data", "1-1": "`string`", "2-1": "`boolean`", "3-1": "`string`", "4-1": "`string`", "5-1": "`array`", "6-1": "`number`", "7-1": "`string`", "8-1": "`string`", "9-1": "`array`", "10-1": "`number`", "11-1": "`string`", "12-1": "`string`", "13-1": "`object`", "14-1": "`array`", "15-1": "`number`", "16-1": "`number`", "17-1": "`string`", "18-1": "`string`", "19-1": "`boolean`", "20-1": "`array`", "21-1": "`number`", "22-1": "`string`", "23-1": "`string`", "24-1": "`array`", "25-1": "`number`", "26-1": "`string`", "27-1": "`string`", "1-2": "The type of conditional logic check", "2-2": "Indicates if the conditional statement is \"if\" (`true`) or \"unless\" (`false`). It will default to `false` if the field is not included.", "3-2": "The type of workflow component. It can be one of the following types: `js`, `single`, `multi`.", "4-2": "The conditional logic", "5-2": "The before request logic object", "6-2": "The before request logic object identifier", "7-2": "The before request logic type", "8-2": "The before request logic", "9-2": "The after request logic object", "10-2": "The after request logic object identifier", "11-2": "The after request logic type", "12-2": "The after request logic", "13-2": "The remote endpoint call object. This field is required if `type` is `single`.", "14-2": "The array of remote endpoint call objects", "15-2": "The remote endpoint call identifier", "16-2": "The remote endpoint identifier. This field is required if `type` is `single` or `multi`.", "17-2": "The name overriding the remote endpoint name", "18-2": "The type of conditional logic", "19-2": "Indicates if the conditional statement is \"if\" or \"unless\"", "20-2": "The before request logic object", "21-2": "The before request logic object identifier", "22-2": "The before request logic type", "23-2": "The before request logic", "24-2": "The after request logic object", "25-2": "The after request logic object identifier", "26-2": "The after request logic type", "27-2": "The after request logic" }, "cols": 3, "rows": 28 } [/block] **There are 3 types of workflow components: logic, single call, and multi-call.** **1. Logic Components** Here is an example of a logic component that returns a message based on the provided conditional logic: [block:code] { "codes": [ { "code": "{ \n .... \n \"components\":[ \n { \n \"id\":72,\n \"conditional\":\"1 == 1;\",\n \"conditional_positive\":true,\n \"type\":\"js\",\n \"data\":\"response.headers[\\\"Content-Type\\\"] = \\\"application/json\\\";\\nresponse.body = JSON.stringify({message: \\\"Hello world! Your nanoscale.io instance is running correctly.\\\"});\"\n }\n ],\n ....\n}", "language": "json" } ] } [/block] **2. Single Call Components** Here is an example of a single call component that retrieves a record from a remote mongo database: [block:code] { "codes": [ { "code": "{ \n\t\t.... \n \t\"components\":[ \n { \n \"id\":82,\n \"conditional\":\"1 == 1;\",\n \"conditional_positive\":true,\n \"type\":\"single\",\n \"before\":[ \n { \n \"id\":155,\n \"type\":\"js\",\n \"data\":\"var id = request.vars.id ; \\n\\nmongo.request = new AP.Mongo.Request();\\nlog(id) ; \\n\\nmongo.request.query('hats', 'find' , {\\\"_id\\\":{\\\"_id\\\":id , \\\"type\\\":\\\"id\\\"}} ) ;\"\n }\n ],\n \"after\":[ \n { \n \"id\":156,\n \"type\":\"js\",\n \"data\":\"response.statusCode = 200\\n\\nresponse.body = JSON.stringify(mongo.response.data); \\n\\n\"\n }\n ],\n \"call\":{ \n \"id\":76,\n \"remote_endpoint_id\":49,\n \"endpoint_name_override\":\"\",\n \"conditional\":\"\",\n \"conditional_positive\":true\n },\n \"data\":\"\"\n }\n ] \n\t\t....\n}", "language": "json" } ] } [/block] **3. Multi-Call Components** Here is an example of a multi-call component that calls two remote endpoints in parallel and merges their results. [block:code] { "codes": [ { "code": "{ \n .... \n \t\"components\":[ \n { \n \"id\":91,\n \"conditional\":\"\",\n \"conditional_positive\":true,\n \"type\":\"multi\",\n \"before\":[ \n { \n \"id\":173,\n \"type\":\"js\",\n \"data\":\"\"\n }\n ],\n \"after\":[ \n { \n \"id\":174,\n \"type\":\"js\",\n \"data\":\"//Set response to JSON string format\\nresponse.headers[\\\"Content-Type\\\"] = \\\"application/json\\\";\\n\\n//Get responses from remote endpoint using {codeName}.response var initialized by remote endpoint\\nproducts_response_data = JSON.parse(getProducts.response.body);\\nratings_response_data = JSON.parse(getRatings.response.body);\\n\\n//Create variable for merged response\\nvar merged_response = [];\\n\\n//Merge responses based on Products and their ratings\\nratings_response_data.forEach(function(r){\\n p = _.findWhere(products_response_data, {\\\"id\\\": r.product_id});\\n p.rating = r.rating;\\n merged_response.push(p);\\n});\\n\\n//Return merged response\\nresponse.body = JSON.stringify(merged_response);\"\n }\n ],\n \"calls\":[ \n { \n \"id\":85,\n \"remote_endpoint_id\":52,\n \"endpoint_name_override\":\"\",\n \"conditional\":\"\",\n \"conditional_positive\":true,\n \"before\":[ \n { \n \"id\":175,\n \"type\":\"js\",\n \"data\":\"\"\n }\n ],\n \"after\":[ \n { \n \"id\":176,\n \"type\":\"js\",\n \"data\":\"\"\n }\n ]\n },\n { \n \"id\":86,\n \"remote_endpoint_id\":47,\n \"endpoint_name_override\":\"\",\n \"conditional\":\"\",\n \"conditional_positive\":true,\n \"before\":[ \n { \n \"id\":177,\n \"type\":\"js\",\n \"data\":\"\"\n }\n ],\n \"after\":[ \n { \n \"id\":178,\n \"type\":\"js\",\n \"data\":\"\"\n }\n ]\n }\n ],\n \"data\":\"\"\n }\n ] \n\t ....\n}", "language": "json" } ] } [/block] ## How can I add a test component? A proxy endpoint's tests is an array of component objects. Each object containing the following fields: [block:parameters] { "data": { "h-0": "key", "h-1": "type", "h-2": "description", "0-0": "id", "1-0": "name (required)", "2-0": "methods (required)", "3-0": "route (required)", "4-0": "body", "5-0": "pairs", "6-0": "pair/id", "7-0": "pair/type", "8-0": "pair/key", "9-0": "pair/value", "10-0": "data", "0-1": "`number`", "1-1": "`string`", "2-1": "`array`", "3-1": "`string`", "4-1": "`string`", "5-1": "`array`", "6-1": "`number`", "7-1": "`string`", "8-1": "`string`", "9-1": "`string`", "10-1": "`string`", "0-2": "The test identifier", "1-2": "The test name", "2-2": "The array of HTTP methods the route accepts", "3-2": "The url path of the route", "4-2": "The test request body", "5-2": "The array of test meta data pairs", "6-2": "The test meta data pair identifier", "7-2": "The the test meta data pair type (header, query parameter, or type)", "8-2": "The the test meta data pair key", "9-2": "The the test meta data pair value", "10-2": "The test data" }, "cols": 3, "rows": 11 } [/block] Here is a an example of a test component: [block:code] { "codes": [ { "code": "{ \n .... \n \t\"tests\":[ \n { \n \"id\":31,\n \"name\":\"TestCase1\",\n \"methods\":[ \n \"GET\"\n ],\n \"route\":\"/helloworld\",\n \"body\":\"\",\n \"pairs\":[ \n { \n \"id\":22,\n \"type\":\"header\",\n \"key\":\"auth\",\n \"value\":\"token\"\n },\n { \n \"id\":23,\n \"type\":\"get\",\n \"key\":\"query\",\n \"value\":\"param\"\n },\n { \n \"id\":24,\n \"type\":\"path\",\n \"key\":\"argument\",\n \"value\":\"one\"\n }\n ],\n \"data\":null\n }\n ] \n\t ....\n}", "language": "json" } ] } [/block]