Invoking REST web service

jansi rani krishnan 601 Reputation points
2021-05-11T18:57:38.407+00:00

I am working on an integration project, in which I have written powershell code which retrieves Incident information and converted to JSON format as required by ServiceNow ITSM tool. I tried to make a web service call using the command “Invoke_RESTmethod”.

$Responseobject=invoke-RESTMethod -method 'POST' -uri $URL -body $JsonBody

I am getting an error (415) unsupported media type. I googled about the error and got the below details about the error.

The 415 (Unsupported Media Type) status code indicates that the
origin server is refusing to service the request because the payload
is in a format not supported by this method on the target resource.
The format problem might be due to the request's indicated
Content-Type or Content-Encoding, or as a result of inspecting the
data directly.

Is there anything wrong am doing here. Appreciate if anyone can throw inputs on this.

Regards,
Jansi

System Center Orchestrator
System Center Orchestrator
A family of System Center products that provide an automation platform for orchestrating and integrating both Microsoft and non-Microsoft IT tools.
215 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 97,566 Reputation points MVP
    2021-05-11T20:32:44.03+00:00

    Hi @jansi rani krishnan ,

    what are you trying to achieve with the REST web service call?

    Query ServiceNow Incident: https://chen.about-powershell.com/2018/07/tip-query-servicenow-incident-record-using-powershell-and-rest-api/
    Create a ServiceNow Incident: https://www.alanps1.io/powershell/servicenow-create-an-incident-ticket-using-powershell-via-rest-api/

    In the first example the Invoke-RestMethod command is used. The second example is using the Invoke-WebRequest command.
    Both commands can be used to interact with a REST web service.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten