servicecallout.{policy-name}.target.url returns null

Not applicable

Hi Everyone,

Why I am getting null when trying to access the context variable servicecallout.{policy-name}.target.url.

My service callout policy detail:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="serviceCallout_RestAPI">
    <DisplayName>serviceCallout_RestAPI</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="serviceCallout.Request">
        <Set>
            <QueryParams>
                <QueryParam name="channel">Something</QueryParam>
            </QueryParams>
            <Verb>POST</Verb>
            <Payload contentType="application/json">{"some":"thing","here":"and here"}</Payload>
        </Set>
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    </Request>
    <Response>calloutResponse</Response>
    <HTTPTargetConnection>
        <Properties/>
        <URL>http://example.com/something</URL>
    </HTTPTargetConnection>
</ServiceCallout>

When I tried to get the target.url of the for this servicecallout policy

print(context.getVariable("servicecallout.serviceCallout_RestAPI.target.url"));

I am getting null. Why?

I am using the below context variable to get the complete URL but still I need to know why the above is giving null.

context.getVariable("serviceCallout.Request.url"); // this one works for me.
Solved Solved
2 5 754
1 ACCEPTED SOLUTION

Is this a matter of mis-aligned expectations?

Is it true that servicecallout.POLICYNAME.target.url is a read/write variable?

I was under the impression that a policy could SET that variable prior to the ServiceCallout policy execution, in order to override the URL for the HTTPTargetConnection in that ServiceCallout.

I was not aware that it was documented to hold the eventual value that was used, after execution of the SC policy completes.

I thought that the serviceCallout.Request.url was the variable for that purpose.

EDIT

You can READ these variables after the ServiceCallout to retrieve information:

# var name meaning example
1. servicecallout.requesturi path of URL + query /v1/whatever
2. servicecallout.POLICY_NAME.target.url full url (scheme + host + port (if any) + query) https://api.hostname.net/v1/whatever
3. REQUEST_VARIABLE.url full url (scheme + host + port (if any) + query) https://api.hostname.net/v1/whatever

Some notes:

  1. the #2 variable gets set if and only if you use a template for the URL in the SC policy. like this:
      <HTTPTargetConnection>
        <URL>https://{sc_host}{sc_path}</URL>
      </HTTPTargetConnection>
    	
  2. the #3 variable gets set if and only if you use a named request in your ServiceCallout. like this:
    <ServiceCallout name='SC-SendRequest'>
      <Request variable='REQUEST_VARIABLE'> <!-- your var here -->
        <Set>
          <Payload .../>
    
    	

View solution in original post

5 REPLIES 5

Thank you @Andy for highlighting same. I can able to reproduce above issue. Looks like a bug for me. I am following up with engineering team. We will keep you posted.

@docs Any idea regarding same ? Does it use to work earlier when we documented same in the policy docs ?

I have opened a ticket with Engineering Team, ~~MGMT-4051~~
b/67143961

Thanks @Anil!

I hope if this is fixed I might get a way to get access the target.sent.end.timestamp and target.recieved.end.timestamp for service callout.

servicecallout.{policy-name}.target.url.

I have raised a new question for service callout request and response timestamp (here).

Hi @Anandhu - Thanks for posting this. Yeah, looks like it might be a bug. Stick with what works for now while we investigate. I'll update the docs as needed. Thanks for filing the ticket, @Anil Sagar!

Thank You @Floyd Jones!

Is this a matter of mis-aligned expectations?

Is it true that servicecallout.POLICYNAME.target.url is a read/write variable?

I was under the impression that a policy could SET that variable prior to the ServiceCallout policy execution, in order to override the URL for the HTTPTargetConnection in that ServiceCallout.

I was not aware that it was documented to hold the eventual value that was used, after execution of the SC policy completes.

I thought that the serviceCallout.Request.url was the variable for that purpose.

EDIT

You can READ these variables after the ServiceCallout to retrieve information:

# var name meaning example
1. servicecallout.requesturi path of URL + query /v1/whatever
2. servicecallout.POLICY_NAME.target.url full url (scheme + host + port (if any) + query) https://api.hostname.net/v1/whatever
3. REQUEST_VARIABLE.url full url (scheme + host + port (if any) + query) https://api.hostname.net/v1/whatever

Some notes:

  1. the #2 variable gets set if and only if you use a template for the URL in the SC policy. like this:
      <HTTPTargetConnection>
        <URL>https://{sc_host}{sc_path}</URL>
      </HTTPTargetConnection>
    	
  2. the #3 variable gets set if and only if you use a named request in your ServiceCallout. like this:
    <ServiceCallout name='SC-SendRequest'>
      <Request variable='REQUEST_VARIABLE'> <!-- your var here -->
        <Set>
          <Payload .../>