• Creator
  • #4142561

    Powershell SOAP for ServiceNow


    by srikanthbollu1707 ·

    I am trying to use Powershell SOAP to create a ticket in ServiceNow. I have valid XML that I have successfully tested with the SoapUI tool using basic auth. But when I try to post that same XML to ServiceNow via Powershell I get an error. I’m not sure if its a problem with the auth header (same creds in both SoapUI and PS) or something else because I’m getting a 500 error from the post, which doesn’t sound auth related.

All Answers

  • Author
    • #4154606

      Reply To: Powershell SOAP for ServiceNow

      by shelly5990 ·

      In reply to Powershell SOAP for ServiceNow

      Troubleshooting SOAP requests and responses can be a bit complex, but let’s break down the common issues and steps you can take to troubleshoot the problem.

      1. Check Request Headers and Body: Ensure that the headers you’re sending in PowerShell are correctly formatted and match the headers you successfully used in SoapUI. Also, double-check that the XML payload is exactly the same as the one that worked in SoapUI.

      2. Debugging PowerShell Script: Add detailed debugging output to your PowerShell script so you can examine the request and response more closely. This can help you identify where the issue might be. You can use Invoke-RestMethod with the -Debug flag to get verbose debugging information.

      powershellCopy code

      $Headers = @{
      “Authorization” = “Basic ” + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(“username:password”))
      “Content-Type” = “text/xml; charset=utf-8″

      $XMLPayload = @”
      <!– Your XML content here –>

      $url = “;

      $response = Invoke-RestMethod -Uri $url -Method Post -Headers $Headers -Body $XMLPayload -Debug

      3. Check HTTP Status Codes: The 500 Internal Server Error doesn’t necessarily mean it’s not an authentication issue. It can indicate a server-side issue, but it can also be due to incorrect XML format or other problems with the request. Make sure to analyze the full response, including the headers and the response body, to get more insight.

      4. Authentication: Although you mentioned that you’re using the same credentials in both SoapUI and PowerShell, make sure you’re constructing the “Authorization” header correctly. The format should be Basic base64(username:password).

      5. Error Handling: Wrap your PowerShell code in a try-catch block to capture any errors that might occur during the request and response handling. This will help you catch any exceptions and display more meaningful error messages.

      powershellCopy code

      try {
      # Your SOAP request code here
      } catch {
      Write-Host “An error occurred: $_”

      6. Contact ServiceNow Support: If you’ve tried all the above steps and are still encountering the issue, it might be worth reaching out to ServiceNow support. They can provide specific guidance on any known issues or configuration details that could be causing the problem.

      Remember that troublesh

    • #4177341

      Reply To: Powershell SOAP for ServiceNow

      by zeeshansharif587 ·

      In reply to Powershell SOAP for ServiceNow

      Check XML Format: Ensure that the XML you are sending via PowerShell is well-formed and matches the expected format for creating a ticket in ServiceNow. It should include all required elements and attributes.

      Error Response: Review the specific error message you receive in the 500 response. ServiceNow typically provides detailed error messages in the response. This can help you pinpoint the issue. To see the response content, you can use PowerShell to capture and display it.
      $response = Invoke-WebRequest -Uri $serviceNowURL -Method Post -Headers $headers -Body $xml
      Write-Host $response.Content
      Check ServiceNow Logs: Access the ServiceNow instance and check its logs for more information about the error. ServiceNow often logs detailed error messages in its logs.

      ServiceNow Instance Configuration: Ensure that your ServiceNow instance is correctly configured to receive SOAP requests. Check if there are any restrictions or limitations on creating tickets via SOAP in your ServiceNow instance.

      SOAP Headers: Verify that you’re setting the SOAP headers correctly, especially the Content-Type and SOAPAction headers. They must match the expected values for your specific ServiceNow instance.

      Authentication: Double-check your authentication method. If you’re using Basic Authentication, make sure your credentials are correctly encoded and sent in the headers.
      $username = “yourUsername”
      $password = “yourPassword”
      $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((“${username}:${password}”))
      $headers = @{
      “Authorization” = “Basic ” + $base64AuthInfo
      “Content-Type” = “text/xml”
      “SOAPAction” = “createTicket”
      Firewall or Proxy Issues: Ensure there are no firewall or proxy issues that might be blocking the request from PowerShell but not from SoapUI.

      ServiceNow Instance URL: Verify that the URL you are using to send the request matches your ServiceNow instance and is accessible from your network.

      ServiceNow Instance Version: Ensure that your ServiceNow instance and API version are compatible with the SOAP request you are making.

      API Permissions: Check if the user account you’re using has the necessary permissions to create tickets in ServiceNow.

      Note: irrelevant link removed by moderator.

      • This reply was modified 7 months, 1 week ago by Avatar photokees_b.
Viewing 1 reply thread