JSON API Connector

API Connector

The standard BaaS is used to hit JSON based HTTP endpoints. For example:

{
  "Alias": "phoneNumberValidate",
  "Body": {},
  "Endpoint": "https://password-reset.herokuapp.com/validatePhoneNumber",
  "Headers": {
    "Authorization": "************************",
    "Content-Type": "application/json"
  },
  "Method": "POST",
  "RequestMapping": {
    "telephoneNumber": {
      "inputPath": "$.telephoneNumber",
      "requestBodyPath": "$.telephoneNumber",
      "type": "requestBody"
    }
  },
  "ResponseMapping": {
    "telephoneNumber": {
      "outputPath": "$.telephoneNumber",
      "responseBodyPath": "$.telephoneNumber",
      "type": "responseBody"
    }
  },
  "RestrictionGroup": "12345678-1234-1234-1234-123456789012" //optional, see Restriction Groups
}

*Note If you wish to send basic authentication, you will need to create your id/token secret in the Secret Vault, and include this in your Request Mappings. For example:

  "security": {
    "type": "requestBasicAuth",
    "secret": "srn:vault::acme:secretdoc:twiliobasicauth"
  },

Substitute the org/token values above to correspond with your token.

This BaaS will hit the endpoint called out in the Endpoint parameter with a POST from the Method parameter. The Authorization and Content-Type headers will be added to the request and the RequestMapping and ResponseMapping will work per the next section of this document.

When using the application/x-www-form-urlencoded Content-Type in your Headers, you can specify all of your parameters in the Endpoint using the requestURL type in your RequestMapping

{
    "Method": "POST",
    "Endpoint": "https://httpbin.org/post?keyone=${keyone}&keytwo=${keytwo}",
    "Headers": {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    "Alias": "urlencodedUsingRequestUrl",
    "RequestMapping": {
      "keyoneEntry": {
        "inputPath": "$.keyone",
        "requestParameter": "keyone",
        "type": "requestURL"
      },
      "keytwoEntry": {
        "inputPath": "$.keytwo",
        "requestParameter": "keytwo",
        "type": "requestURL"
      }
    },
    "ResponseMapping": {
    },
    "Type": "api-connector",
    "Body": {}
  }

Alternatively if you have a lot of request parameters and don’t want to build up a large Endpoint manually, you can specify a base Endpoint, and pass in key, value pairs to the body using the requestBody type in your RequestMapping.

{
  "Method": "POST",
  "Endpoint": "https://httpbin.org/post",
  "Headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "Alias": "urlencodedUsingRequestBody",
  "RequestMapping": {
    "keyoneEntry": {
      "inputPath": "$.keyone",
      "requestBodyPath": "$.keyone",
      "type": "requestBody"
    },
    "keytwoEntry": {
      "inputPath": "$.keytwo",
      "requestBodyPath": "$.keytwo",
      "type": "requestBody"
    }
  },
  "ResponseMapping": {
  },
  "Type": "api-connector",
  "Body": {}
}