Je dois attacher le fichier XLSX ou CSV à un incident particulier via une API de repos de neige à l'aide d'un script PowerShell. J'ai essayé avec le code ci-dessous: Lorsque j'exécute le script ci-dessus, je reçois l'erreur ci-dessous: P>
Invoke-RestMethod : The remote server returned an error: (415) Unsupported
Media Type.
At C:\Users\suganthanraj.p\Desktop\SNOW-UploadAttachment.ps1:39 char:21
+ ... oadResult = Invoke-RestMethod -Uri $Upload_snow_url -Credential $scr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
3 Réponses :
Essayez de changer de type de contenu sur "Multipart / Form-Data"
$headers.Add('Content-Type','multipart/form-data') $UploadBody = @{ 'table_name'='incident'; 'record_sys_id'=$sys_id; 'uploadFile' = 'C:\Users\suganthanraj.p\Documents\Servers.csv' }
Invoke-RestMethod: Le serveur distant a renvoyé une erreur: (400) mauvaise demande. Chez c: \ users \ users \ suganthanraj.p \ dektop \ neige-attachement.ps1: 38 Char: 21 + ... OADRESULT = INVOKE-RESTMETHOD -URI $ UPLOWATION_SNOW_URL -Credential $ ... + ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CatégorieInfo: InvalidOperation: (System.net.httpwebrequest: httpwebrequest) [Invoke-RestMethod], WebException + PullalifeRorrorid: webcmdletweebreseException, microsoft.powershell.chands.VokerestMethodcomm
Votre meilleure option serait de tirer parti de l'oob API de pièce jointe en servicene. Vous devrez faire un appel de PowerShell. PowerShell a deux options pour ce Invoke-reposmethod et Invoke-Webrequest . J'ai eu mieux de chance avec ce dernier lors de la tentative de poster. Vous pouvez également créer une première construire votre appel à Postman Assurez-vous de pouvoir obtenir la pièce jointe à Servicenow, puis vous inquiétez écrire votre PS.
$Body = @{ User = 'jdoe' password = 'P@S$w0rd!' } $LoginResponse = Invoke-WebRequest 'http://www.contoso.com/login/' - SessionVariable 'Session' -Body $Body -Method 'POST' $Session $ProfileResponse = Invoke-WebRequest 'http://www.contoso.com/profile/' -`WebSession $Session $ProfileResponse`
Je reçois toujours la même erreur d'appel-reposmethod: le serveur distant renvoya une erreur: (400) mauvaise demande. Chez c: \ users \ users \ suganthanraj.p \ dektop \ neige-attachement.ps1: 38 Char: 21 + ... OADRESULT = INVOKE-RESTMETHOD -URI $ UPLOWATION_SNOW_URL -Credential $ ... + ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CatégorieInfo: InvalidOperation: (System.net.httpwebrequest: httpwebrequest) [Invoke-RestMethod], WebException + entièrementqualifeRorrorid: webcmdletweebreSonException, microsoft.powershell.commands.VokerestMethodcomm.com et -
Enfin j'ai trouvé la réponse du lien ci-dessous
https: // Communauté. Servicenow.com/community?id=Community_Question&sys_id=D3707023DBACEB8023F4A345CA961949 et ci-dessous est le code: p>