How to send excel file on Invoke-Restmethod.

Welcome Forums General PowerShell Q&A How to send excel file on Invoke-Restmethod.

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
6 months ago.

  • Author
    Posts
  • #100728

    Participant
    Points: 0
    Rank: Member

    I am trying to upload an excel file, while trying the same from postman it is working fine but while trying it from power shell it is not working.

    Here are the below details I am using on postman
    Methode : POST
    URL : https://localhost/api/v1/boarding/validate
    In the header section
    authorization: 09368290_0d9227327d291d8a
    body section "
    Type : form-data:
    filename: "C:\\Users\\Desktop\\Template.xlsx"
    Content-Type :application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
    Content-Disposition : form-data

    any thoughts on this ?

  • #100732

    Participant
    Points: 3
    Rank: Member

    Can you post the PowerShell code you are trying to use?

  • #100780

    Participant
    Points: 0
    Rank: Member

    $validationBody = (
    'Content-Disposition: form-data','name = file',`
    'filename=C:\Users\Template.xlsx',`
    'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    )
    Invoke-RestMethod -Method Post `
    -Uri $ValidatorAPI `
    -Headers @{"Authorization" = $ResNew ; "accept" = "application/json"} `
    -ContentType "multipart/form-data" `
    -Body $validationBody

  • #100783

    Participant
    Points: 0
    Rank: Member

    While sending the same thing on postman it is working fine

The topic ‘How to send excel file on Invoke-Restmethod.’ is closed to new replies.