3

Converting a very simple Plaid API curl data request to a powershell invoke-webrequest

what works:

    curl -X POST https://tartan.plaid.com/balance \
  -d client_id=client-id-value \
  -d secret=secret-value \
  -d access_token=access-token-value

What I'm trying unsuccessfully in Powershell

#test powershell api call

$hash = @{  client_id    = "client-id-value";
            secret = "secret-value"
            access_token = "access-token-value"
            }

$JSON = $hash | convertto-json

#Invoke-WebRequest -uri "https://tartan.plaid.com/balance" -Method POST -Body $JSON

This returns a plaid error 1100 (client id missing), so I know some API functionality is working, but it's not parsing input data correctly.

My biggest misunderstanding is how to translate a "curl -data" value into the proper Powershell parameter.

Is this a header value, body value? etc.

2
  • 1
    Skip the convertto-json step Commented Jul 8, 2017 at 22:12
  • Changing to the following appears to have worked, though I've learned my access token is expired. $post_values = @{client_id='value';secret='value2';access_token='value3'} Invoke-WebRequest -Uri https://tartan.plaid.com/balance -Method POST -Body $post_values Commented Jul 8, 2017 at 22:39

1 Answer 1

1

Unless the target url expects the POST body to be in JSON format, skip the ConvertTo-JSON step completely.

When the chosen HTTP method is POST, Invoke-WebRequest will automatically take all the keys in the hashtable supplied to the -Body parameter and construct a body payload similar to that of curl -d:

$POSTParams = @{
    client_id    = "client-id-value"
    secret       = "secret-value"
    access_token = "access-token-value"
}

Invoke-WebRequest -Uri "https://tartan.plaid.com/balance" -Method POST -Body $POSTParams
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.