• Getting Started
    • Mobile Integration (Android/IOS)
      Enterprise Solutions
      Accept Payments
      Process Payments
      Disbursals
      API References
      Webhooks
      Testing
      Refunds
      Guides
      Other Processes
      Mini Program Platform
        Website Integration

      getAccessToken API

      Use Case


      Using this API merchant can get the access token corresponding to a Auth Code (received from the App side in earlier step). For the same merchant backend needs to make a S2S call with Paytm backend. This token can be used to fetch the User details in the getUserInfo API.


      Request Attributes

      API Content format: JSON

      Head

      AttributeDescriptionMandatory
      AuthorizationThis is a base64 encoded string of “clientId:clientSecret”Yes

      Body

      AttributeDescriptionExample
      grant_typeIt contains authorization_codeYWxhZGRpbjpvcGVuc2VzYW1
      codeAuth code you get in response from paytmFetchAuthCode bridgerwtw-fsdfk-vcvx-tweq
      client_idClient ID provided during onboarding your mini programmerchant-abc
      scopescope of the mini programbasic

      Response Attributes

      Head

      AttributeDescriptionExample
      statusstatus of response200

      Success:

      ParameterDescriptionExample Value
      scopescope of the mini programpaytm
      access_tokenaccess token of the user sent by paytm7522b293-cad6-4ed8-bdc6-7c3bc3637100
      expiresexpiration time1570465786000
      resourceOwnerIdResource owner IDXXXXXXX

      Error Responses:

      ParameterDescriptionExample Value
      errorerror nameInternal error
      error_descriptionerror messageSomething went wrong

      ERROR CODES

      StatusError
      400Internal Error
      400unsupported_grant_type
      400invalid_grant
      401NO RESPONSE BODY


      Endpoints

      UAT: https://accounts-uat.paytm.com/oauth2/v2/token

      Production: https://accounts.paytm.com/oauth2/v2/token

      Request CodeResponse JSON
      
                  const url="https://accounts.paytm.com/oauth2/v2/token"
      
                    const data =  {
                        "grant_type" : "authorization_code",
                        "code": "rwtw-fsdfk-vcvx-tweq",
                        "client_id" : "mercha-abc",
                        "scope" : "basic"
                   }
      let formBody=[]; for (var property in data) {     var encodedKey = encodeURIComponent(property);     var encodedValue = encodeURIComponent(data[property]);     formBody.push(encodedKey + "=" + encodedValue); } const requestBody = formBody.join("&"); const otherParams={  headers: {    "Content-Type": "x-www-form-urlencoded",    "Authorization": "Basic YWxhZGRpbjpvcGVuc2VzYW1l"    },  body: requestBody,  method: "POST"     }; fetch(url, otherParams) .then(res => res.json()) .then(res => console.log(res)) .catch(err => console.log(err))