Search code examples
azure-pipelinesmultipartform-data

Using InvokeRestAPI to send form data


Trying to send form data in Azure DevOps's InvokeRestAPI task which looks like the following:

ADO Pipeline Task

but the endpoint (https://login.microsoftonline.com/xxxxxxxxxxxx) keeps coming back with this message:

Response: An error was encountered while processing request. Exception: {"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.

How to format the InvokeRestAPI task for the endpoint to see it as an actual form-data?

Thanks


Solution

  • I tested to modify the Content-Type as application/x-www-form-urlencoded and edited the request body as in the sample YAML below; I managed to call the Rest API.

    jobs:
    - job:
      pool: server
      steps:
      - task: InvokeRESTAPI@1
        inputs:
          connectionType: 'connectedServiceName'
          serviceConnection: 'AzureAPISvcCnn'
          method: 'POST'
          headers: |
            {
            "Content-Type": "application/x-www-form-urlencoded"
            }
          body: 'grant_type=client_credentials&client_id=$(CLIENT_ID)&client_secret=$(CLIENT_SECRET)&resource=https://storage.azure.com/'
          waitForCompletion: 'false'
    
    

    Invoke Rest API