cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1824
Views
15
Helpful
7
Replies

CCX REST API call how to pass dynamic variables in Request Body

Hi Everyone,

 

Looking for some help with configuration of REST API call step in a CCX script.

 

I am using an array string variable here and inputting the variable values into one array variable instead of creating 8 different variables for every field in a Make REST call step. Excellent recommendation from @Anthony Holloway 

 

1) CRM does authentication by requiring username and password sent in Request Body. Since these values are going to be static, I was able to get them mapped and added into the string array variable used on the first Make REST Call.

 

2) Next another Make REST Call is required to be sent to search for a record based on either a Member # or SSN entered by a caller. These numbers are going to be dynamic each time for a call and they need to be sent in Request Body. I am unable to figure out how to send dynamic variable values in the Body of a REST Call. 

 

 

 

 

1 Accepted Solution

Accepted Solutions

The value for your set step should look something like this:

u"{\"ssn\":" + SSN + u",\"class\":\"Individual\", \"entity\":\"Business\"}"

This is assuming your SSN is held in a variable named SSN.

View solution in original post

7 Replies 7

Anthony Holloway
Cisco Employee
Cisco Employee

I would recommend that you construct the body outside of the Make REST Call step, using like a Set step for example.

E.g.,

Steps
Set REST[4] = "<ssn>" + ssn + "</ssn>" Make REST Call (using REST[4] in Body field)

 

Alternatively, you can setup your body as a template string and use String.replace to add the SSN

E.g.,

Variables
body_template = "<ssn>%SSN%</ssn>"

Steps Set REST[4] = body_template.replace("%SSN%", ssn) Make REST Call (using REST[4] in Body field)

 

It is possible to perform the replacement in the Make REST Call step too, which saves you the one Set step, you just don't use the REST[4] like previously.

E.g.,

body_template.replace("%SSN%", ssn)

 

Or if you like to use the REST[4] for debugging or whatever reason, you can do this in the Body field too:

E.g.,

{ return REST[4] = body_template.replace("%SSN%", ssn); }

 

Hi Anthony,

 

Thanks for your response. Being new to programming, this is my first attempt at any programming, please pardon my ignorance.

 

Since, I need to send two other static name:value pairs along with this dynamic ssn value, I was trying to figure out how to include that in the set step. And, with my limited understanding, I thought the data is getting sent in xml format while we need to send in json format starting with the curly brace. I tried with few attempts in creating a set step for sending json data. The editor took following but I am not sure if it is correct. Could you please confirm? Once I get this correct, I plan to test with debugging of the script initially and then later using a RESTClient on Firefox with CRM application.

 

 

The value for your set step should look something like this:

u"{\"ssn\":" + SSN + u",\"class\":\"Individual\", \"entity\":\"Business\"}"

This is assuming your SSN is held in a variable named SSN.

Thank you, Anthony. That variable worked. Tried to read up on the JSON syntax, I couldn't find any explanation on the use of u character at the beginning, looks to be CCX specific. Could you please explain a little on that?

It means the String is an extended String, and thus can have escape characters inside of it. It's how you include the doublequote character inside of the string, since JSON requires all keys and values to be wrapped in quotes.

Thank you, Anthony. Much appreciated.

You are very welcome! Thanks for asking questions. Without people like you, this forum would be boring and quiet. :)
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: