oauth-2.0postmancontent-typehttp-status-code-415clientcredential

Is there a way to change the Content Type for a Postman OAuth 2 Client Credentials request?


I'm trying to use the built in tool to get an OAuth 2.0 token for my requests. This seems pretty straightforward when reading the documentation and I set it up like this: screenshot from postman request

The issue is that the request for the token is sent with a content type of application/x-www-form-urlencoded. So the response I'm getting from the server is a 415 Unsupported Media Type I do not see a way to change the request content-type to application/json.

screenshot of postman console log

Am I missing something or is the only way to create a custom pre-request script?


Solution

  • https://github.com/oauthjs/node-oauth2-server/issues/92

    application/x-www-form-urlencoded , is the supported content-type for Oauth

    https://www.rfc-editor.org/rfc/rfc6749#section-4.1.3

    If you want to create , you can use pre-requisite script something like:

    https://gist.github.com/madebysid/b57985b0649d3407a7aa9de1bd327990

    // Refresh the access token and set it into environment variable
    pm.sendRequest({
        url:  pm.collectionVariables.get("zoho_accounts_endpoint") + "/oauth/v2/token", 
        method: 'POST',
        header: {
            'Accept': 'application/json',
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        body: {
            mode: 'urlencoded',
            urlencoded: [
                {key: "client_id", value: pm.collectionVariables.get("zoho_client_id"), disabled: false},
                {key: "client_secret", value: pm.collectionVariables.get("zoho_client_secret"), disabled: false},
                {key: "refresh_token", value: pm.collectionVariables.get("zoho_refresh_token"), disabled: false},
                {key: "grant_type", value: 'refresh_token', disabled: false}
            ]
        }
    }, function (err, res) {
        pm.collectionVariables.set("zoho_access_token", 'Zoho-oauthtoken ' + res.json().access_token);
    });
    

    Change it to JSON or what ever you want and store the value to a variable and use that as bearer {{token}}