Adding an endpoint with the Post method type

Use the POST method type to send data via an API to a back end.

  1. Sign in to the Rhythm website as a site editor or tenant administrator.
  2. Click the Menu button.
  3. Click the Control Panel tab.
  4. Click Generic API.
  5. Click the name of the API.
  6. Click Add Endpoint.
  7. In the Incoming URL field, specify the last part of the URL that the generic wrapper uses to identify the endpoint. This value must be unique in the tenant.
  8. Click the Post method type.
  9. In the Body Template field, specify the json code use in the POST call. You can use one or more of these types:
    Lookup
    Use this replacement type to look up a value from another API to use in the POST call.
    {
        "customerID": {
            "type": "lookup",
            "call": "/delegate/ecom-api/users/current",
            "path": "$.activeUserGroup.customerNumber"
        }
    }

    In the sample code, /delegate/ecom-api/users/current is called. In the results, the user ID that was passed from the API wrapper is searched for in the activeUserGroup key. The value in the customerNumber key is returned. If the value in the customerNumber key is ABC-123, then the template results in this json:

    {
    "customerID": "ABC-123"
    }
    This table shows the components of the sample json template:
    Component Description
    "customerID" The key to use for the result of the json call.
    "type" The type of replacement. Specify "type":"lookup".
    "call" The call to the API that you are using to look up information. The value that you specify is appended to the base URL for your Rhythm server.
    "path" The json path expression to use to look up a value in the result of the call. Specify an expression that returns one result.
    Input
    Use this replacement type to input a value from the data that was passed from the API wrapper.
    {
        "itemID": {
            "type": "input",
            "path": "$.itemNumber"
        }
    }

    In the sample code, the data that was passed from the API wrapper is searched for the itemNumber key. If the value in the itemNumber key is 12345, then the template results in this json:

    {
    "itemID": "12345"
    }
    This table shows the components of the sample json template:
    Component Description
    "itemID" The key to use for the result of the json call.
    "type" The type of replacement. Specify "type":"input".
    "path" The json path expression to use to look up a value in the data sent in the API wrapper. Specify an expression that returns one result.
    Static value
    Use this template to send a specific value in the API call.
    {
        "color": "blue"
    }

    In the sample code, blue is also sent in the color key.

  10. In the Outgoing Endpoint field, specify the endpoint. If you included lookup and input types in the body, the result of the lookup and input is used in the json. For example, presume you specified this json in the Body Template field.
    {
        "customerID": {
            "type": "lookup",
            "call": "/delegate/ecom-api/users/current",
            "path": "$.activeUserGroup.customerNumber"
        },
        "emailAddress": {
            "type": "lookup",
            "call": "/delegate/ecom-api/users/current",
            "path": "$.email"
        },
        "itemID": {
            "type": "input",
            "path": "$.itemNumber"
        },
        "color": "blue"
    }
    

    The lookup and input types are replaced with values, for example:

    {
        "customerID": "ABC-123",
        "emailAddress": "user@example.com",
        "itemID": "12345",
        "color": "blue"
    }
    
  11. Click Save.