Making Variable Requests

The variable operations provide a programmatic way to manage service and servicecoll variables. Read this page to find out how to use variable operations, and try out the operations using cURL.

Note: You cannot use the MEP Expression Language inside the value of variables created or updated through these operations.

If you need to find out more about service and servicecoll variables, see Variables.

Before we begin

Before beginning, you'll need a MEP account provisioned. Other than this, you do not need any specific MEP user roles set to use these operations.

Retrieve the ID for services and service collections

To use these operations, you will need to retrieve the service ID or service collection IDs of any services that you are working with.

To obtain a service ID:

  1. Navigate to the Services tab.
  2. Expand the Service Collection that contains the desired service. The "ID" column shows the service ID of each service.

Services home page with Service IDs indicated

For service collection IDs, you will need to contact your OpenMarket account manager.

Create a variable

(Operation: Create or Update a Variable)

Note: The examples on this page create and manage a service variable, but you can also follow the same examples if you want to manage a servicecoll variable.

Now that you've got a service ID, you can start using the API operations. In the cURL call, you'll need to change the:

  • username and password to your own details
  • example service ID 1A2B3C4D5E6F to the ID of your own service

This creates a variable service.rewardToday with a value of free medium coffee.

curl -D - -X GET "https://cmx2api.openmarket.com/variableapi/set?username=MyUsername&password=P4S5W0Rd&id=1A2B3C4D5E6F&scope=service&key=rewardToday&value=free+medium+coffee"

If your request is successful, OpenMarket will return a synchronous response, similar to the following.

HTTP/1.1 200 OK
Date: Tue, 15 Mar 2016 18:02:57 GMT
Server: Apache-Coyote/1.1
Content-Length: 2
Content-Type: text/plain

OK

The service now has the variable available. In the MEP UI, you can view the newly created variable by going to the edit screen for the service, and selecting View Service Variables (or by clicking the Legacy Editor button, and then clicking the Variables button).

Screenshot showing the newly created variable in the MEP UI

Get the variable's value

(Operation: Get a Variable's Value)

Let's make a call to see the variable's value, programmatically. In the cURL call, you'll need to change the:

  • username and password to your own details
  • example service ID 1A2B3C4D5E6F to the ID of your own service
curl -D - -X GET https://cmx2api.openmarket.com/variableapi/get?username=MyUsername&password=P4S5W0Rd&id=1A2B3C4D5E6F&scope=service&key=rewardToday

If your request is successful, OpenMarket will return a synchronous response, similar to the following.

HTTP/1.1 200 OK
Date: Tue, 15 Mar 2016 18:02:57 GMT
Server: Apache-Coyote/1.1
Content-Length: 3
Content-Type: text/plain

free medium coffee

Update the variable

(Operation: Create or Update a Variable)

To update a variable's value, make the same API call as you did to create it (but with the new value included). In the cURL call, you'll need to change the:

  • username and password to your own details
  • example service ID 1A2B3C4D5E6F to the ID of your own service
curl -D - -X GET "https://cmx2api.openmarket.com/variableapi/set?username=MyUsername&password=P4S5W0Rd&id=1A2B3C4D5E6F&scope=service&key=rewardToday&value=free+large+muffin"

If your request is successful, OpenMarket will return a synchronous response, similar to the following.

HTTP/1.1 200 OK
Date: Tue, 15 Mar 2016 18:02:57 GMT
Server: Apache-Coyote/1.1
Content-Length: 2
Content-Type: text/plain

OK

Delete the variable

(Operation: Delete a Variable)

Lastly, lets remove the variable entirely from the service. In the cURL call, you'll need to change the:

  • username and password to your own details
  • example service ID 1A2B3C4D5E6F to the ID of your own service
curl -D - -X GET "https://cmx2api.openmarket.com/variableapi/delete?username=MyUsername&password=P4S5W0Rd&id=1A2B3C4D5E6F&scope=service&key=rewardToday"

If your request is successful, OpenMarket will return a synchronous response, similar to the following.

HTTP/1.1 200 OK
Date: Tue, 15 Mar 2016 18:02:57 GMT
Server: Apache-Coyote/1.1
Content-Length: 2
Content-Type: text/plain
OK