New to SOAP, no clue what I'm doing

Matthew Glenn
Kilo Sage

TLDR; Given a provided SOAP Message Function from a downloaded WSDL, how do I successfully add in message headers?

First time working with SOAP and I'm completely lost on what is going on. Why the heck can't everyone supply a REST API...?

Anyways, I'm having an issue where I can't figure out how to add a header into some SOAP Message Functions that were created via a downloaded WSDL from Dell.

I have scoured the Wiki and Community posts for a few days and have made no headway whatsoever. I've even gone as far as manually constructing the SOAP message (using info found here), but with no luck.

I'm able to successfully send my messages using 3rd party apps like SoapUI, where I'm given a UI to specify header information, but unfortunately their app doesn't show me how the header is constructed before being sent. At least not in a way that I can translate into ServiceNow. This tells me that the content is correct, I just don't know how to structure it.

Can anyone provide any help or guidance? I can provide the WSDL/Functions and script usage if necessary.

Thanks in advance!

1 ACCEPTED SOLUTION

Hi,



You can do it in 2 ways


1. Add the header value in SOAP Message -> Operations



1.PNG


Now select the SOAP Message function from the list down, you will see following screen, where you can edit the SOAP request. You can add the API key header as you have done in SOAP UI


2.PNG


Thats it



2. The second way is doing via script


2.1. Create a SOAP Message in ServiceNow.


2.2. While using the created SOAP message while triggering the request, you can add the APPI key as a header with the help of ServiceNow api.


SOAPMessageV2 API - ServiceNow Wiki



4.12 setRequestHeader(String headerName, String headerValue)

Set an HTTP header in the SOAP message to the specified value.


Parameters:


  • headerName - (String) the name of the header.
  • headerValue - (String) the value to assign to the specified header.

Returns:


void

View solution in original post

5 REPLIES 5

tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Matthew,



What headers have you added via SOAPUI?


Could you give some info on what headers seem to be required by the far end?



Best Regards



Tony


Hey Tony,



I'm trying to pass the apikey header through, which is the only required header. Everything else is passed as a parameter.



I'm easily able to add the header via SoapUI using the GUI seen below. The Soap Function below was downloaded directly from a Dell provided WSDL. The only changes I made were to the Login and Password parameters



Screen Shot 2015-11-27 at 10.54.01 PM.png



Once I click on the play button in the upper left (the green arrow), I'm then shown the constructed header (image below). What Im confused on is how do I pass, in SN, the apikey header similar to what SoapUI is doing



Screen Shot 2015-11-27 at 11.05.27 PM.png


Hi,



You can do it in 2 ways


1. Add the header value in SOAP Message -> Operations



1.PNG


Now select the SOAP Message function from the list down, you will see following screen, where you can edit the SOAP request. You can add the API key header as you have done in SOAP UI


2.PNG


Thats it



2. The second way is doing via script


2.1. Create a SOAP Message in ServiceNow.


2.2. While using the created SOAP message while triggering the request, you can add the APPI key as a header with the help of ServiceNow api.


SOAPMessageV2 API - ServiceNow Wiki



4.12 setRequestHeader(String headerName, String headerValue)

Set an HTTP header in the SOAP message to the specified value.


Parameters:


  • headerName - (String) the name of the header.
  • headerValue - (String) the value to assign to the specified header.

Returns:


void

I originally saw 'setRequestHeader' on the Wiki, but ignored it since it's listed on a Fuji-specific page and I'm still on Eureka. It's exactly what I needed though.



thanks!