cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1694
Views
5
Helpful
7
Replies

CCX Make REST Call Headers troubleshooting

Hi Everyone,

 

I am doing a second Make REST Call that is passing the received token value from first REST Call step as an Header. I do receive some JSON object, but not the correct one from the CRM server. So the second Make REST step is not failing. Debugging script shows values sent in REST call step and received JSON response but I do not see the Headers.

 

Is there any way to see what Header value is passed from CCX during script execution and if so which logs to look? Attached REST step properties for reference.

 

I generally look at CLI logs to trace the steps, but I am not finding anything specific to Header values processed by script. Appreciate any help in suggesting where to look for this.

 

1 Accepted Solution

Accepted Solutions

Anthony Holloway
Cisco Employee
Cisco Employee

It looks like the Make REST Call step does not expose the response headers to you. Therefore, you will need to do this the manual Java way. Since I am not a Java programmer, I had to google how to do this in pure Java, and I found this link:

https://mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/

Now, with UCCX, you cannot use java in the editor in the typical java way, so you have to UCCXify the examples you find the on the internet a bit, so here is what the post example from that website would look like if you were to put it inside of a Do step:

{
	java.net.URL url = new java.net.URL("https://postman-echo.com/post");
	java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
	conn.setDoOutput(true);
	conn.setRequestMethod("POST");
	conn.setRequestProperty("Content-Type", "text/plain");
conn.setRequestProperty("Authorization", "Basic Y2lzY286Y2lzY28="); String input = "Hello from UCCX"; java.io.OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); http_status = conn.getResponseCode(); http_headers = conn.getHeaderFields(); java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader((conn.getInputStream()))); String output; while ((output = br.readLine()) != null) { http_response += output; } conn.disconnect(); }

Now, in order for you to set the Do step to that code, you first need to create three new variables in the script:

String http_response = ""
int http_status = 0
Map http_headers = null

From there, you should be able to run an Active Debug (F10) with a single Do step in your script to test out the postman echo test URL I have supplied. The status code should be 200, the response body should be JSON and the headers should be a mapping of all header names and values.

To get a single header value from a map, you can use the .get() method of the http_headers variable in a Set step after the Do step like so, assuming I created a new variable to hold it's value:

Set http_header_server = http_headers.get("Server")

Here is a screenshot of a working example so you can see it all together.

3ed41c13-81d5-451a-a58b-f20e79cc2046.PNG

View solution in original post

7 Replies 7

Anthony Holloway
Cisco Employee
Cisco Employee

It looks like the Make REST Call step does not expose the response headers to you. Therefore, you will need to do this the manual Java way. Since I am not a Java programmer, I had to google how to do this in pure Java, and I found this link:

https://mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/

Now, with UCCX, you cannot use java in the editor in the typical java way, so you have to UCCXify the examples you find the on the internet a bit, so here is what the post example from that website would look like if you were to put it inside of a Do step:

{
	java.net.URL url = new java.net.URL("https://postman-echo.com/post");
	java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
	conn.setDoOutput(true);
	conn.setRequestMethod("POST");
	conn.setRequestProperty("Content-Type", "text/plain");
conn.setRequestProperty("Authorization", "Basic Y2lzY286Y2lzY28="); String input = "Hello from UCCX"; java.io.OutputStream os = conn.getOutputStream(); os.write(input.getBytes()); os.flush(); http_status = conn.getResponseCode(); http_headers = conn.getHeaderFields(); java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader((conn.getInputStream()))); String output; while ((output = br.readLine()) != null) { http_response += output; } conn.disconnect(); }

Now, in order for you to set the Do step to that code, you first need to create three new variables in the script:

String http_response = ""
int http_status = 0
Map http_headers = null

From there, you should be able to run an Active Debug (F10) with a single Do step in your script to test out the postman echo test URL I have supplied. The status code should be 200, the response body should be JSON and the headers should be a mapping of all header names and values.

To get a single header value from a map, you can use the .get() method of the http_headers variable in a Set step after the Do step like so, assuming I created a new variable to hold it's value:

Set http_header_server = http_headers.get("Server")

Here is a screenshot of a working example so you can see it all together.

3ed41c13-81d5-451a-a58b-f20e79cc2046.PNG

Hi Anthony,

 

Appreciate the detailed response. I will have to read up more to understand the java steps better and then I will run this again in a test environment. I was trying to test against CCX API, which got me stuck with authentication error 401. Can you please suggest how to introduce basic authentication in those java commands? Also, though we see what header is configured in a Make REST Call step, is there any way to check the actual request header sent out in a POST?

I added Basic Auth to the example now. For laziness you will just encode your own user:pass in base64.

I don't think there is anyway to see the request headers from the Make REST Call step, no. You'd have to keep using the Java based method for more powerful features like that.

Thanks, Anthony.

 

Using your code, I was able to debug the Request Headers for a local json-server with no authentication.

 

However, with CCX Admin API it came back with 415 error. I believe the authentication is going through, I got Base64 encoded format of my server's username:password from online tool (https://www.url-encode-decode.com/base64-encode-decode/) and provided it in "conn.setRequestProperty("Authorization", "Basic encodedvalue");" Looks like something else that is sent out to CCX is triggering the error. If you see anything glaring from the attached debug picture, please let me know. Thank you.

 

 

 

Considering a 415 is unsupported media type, I would see if switching your content-type header to application/xml solves that.

I forgot to mention, I did try with both application/xml and application/json earlier that resulted same error with CCX API. Not a showstopper, but I will try reworking on this after learning some more concepts. I appreciate all your help so far. Thank you, Anthony.

Ok, sounds good. I have never used this method, only just discovered it to help answer the question, so I cannot speak from experience. I can give it a try too and see what I come up with.