Class: WalmartApIs::TokenApi

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/walmart_ap_is/apis/token_api.rb

Overview

TokenApi

Constant Summary

Constants inherited from BaseApi

BaseApi::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseApi

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseApi

#initialize, #new_parameter, #new_request_builder, #new_response_handler, user_agent, user_agent_parameters

Constructor Details

This class inherits a constructor from WalmartApIs::BaseApi

Instance Method Details

#token_api(wm_partner_id, wm_consumer_channel_type, wm_qos_correlation_id, wm_svc_name, accept, grant_type, code, redirect_uri, refresh_token) ⇒ ApiResponse

Obtain access tokens for API authentication using OAuth 2.0 by providing Client ID and Client Secret. This endpoint supports multiple grant types for different authentication scenarios - Client Credentials Grant, Authorization Code Grant, Refresh Token Grant. An access token expires after a certain interval, so you will have to refresh a user’s access token. You could use refresh token, obtained from the token API call using authorization code grant type, to get a new access token. Token Lifetimes<br /><ul><li>Access Token: 15 minutes (900 seconds)</li><li>Refresh Token: 1 year (365 days)</li></ul><br /> <a href=“developer.walmart.com/us-marketplace/docs/get-an-access-toke n”>Get an access token using Token API</a> <a href=“developer.walmart.com/us-marketplace/docs/get-started-as-a-s eller”>Get started as a seller</a> <a href=“developer.walmart.com/us-marketplace/docs/get-started-as-a-s olution-provider”>Get started as a solution provider</a> <a href=“developer.walmart.com/us-marketplace/docs/oauth-20-authoriza tion”>OAuth2.0 authorization</a> in Walmart marketplace to identify a seller account. <br /> This field is required when ‘grant_type` is `authorization_code` or `refresh_token`. to track the consumer request by channel. Use the Consumer Channel Type received during onboarding. identifies each API call and is used to track and debug issues. Use a randomly generated GUID for this ID. Walmart service being called. requested. <br /> **Available grant types:** `authorization_code`, `refresh_token` and `client_credentials` your redirect URI, obtained by your client app when the seller authorizes your app to access the seller resource. <br /> This field is required when **grant_type: authorization_code**. match one of the URIs registered for your client app, which was provided while registering the app. <br /> This field is required when **grant_type: authorization_code**. as response of Authentication API with authorization_code grant type. Use it to exchange for a new access token when the current one expires. <br /> This field is required when **grant_type: refresh_token**.

Parameters:

  • wm_partner_id (Integer)

    Required parameter: Partner ID registered

  • wm_consumer_channel_type (String)

    Required parameter: A unique ID

  • wm_qos_correlation_id (String)

    Required parameter: A unique ID that

  • wm_svc_name (String)

    Required parameter: Specifies the name of the

  • accept (String)

    Required parameter: TODO: type description here

  • grant_type (String)

    Required parameter: Type of OAuth2.0 grant

  • code (String)

    Required parameter: Authorization code returned to

  • redirect_uri (String)

    Required parameter: Redirect URI must exactly

  • refresh_token (String)

    Required parameter: Refresh token received

Returns:

  • (ApiResponse)

    Complete http response with raw body and status code.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/walmart_ap_is/apis/token_api.rb', line 58

def token_api(wm_partner_id,
              wm_consumer_channel_type,
              wm_qos_correlation_id,
              wm_svc_name,
              accept,
              grant_type,
              code,
              redirect_uri,
              refresh_token)
  @api_call
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/token',
                                 Server::SERVER_1)
               .header_param(new_parameter(wm_partner_id, key: 'WM_PARTNER.ID')
                              .is_required(true))
               .header_param(new_parameter(wm_consumer_channel_type, key: 'WM_CONSUMER.CHANNEL.TYPE')
                              .is_required(true))
               .header_param(new_parameter(wm_qos_correlation_id, key: 'WM_QOS.CORRELATION_ID')
                              .is_required(true))
               .header_param(new_parameter(wm_svc_name, key: 'WM_SVC.NAME')
                              .is_required(true))
               .header_param(new_parameter(accept, key: 'Accept')
                              .is_required(true))
               .form_param(new_parameter(grant_type, key: 'grant_type')
                            .is_required(true))
               .form_param(new_parameter(code, key: 'code')
                            .is_required(true))
               .form_param(new_parameter(redirect_uri, key: 'redirect_uri')
                            .is_required(true))
               .form_param(new_parameter(refresh_token, key: 'refresh_token')
                            .is_required(true))
               .header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type'))
               .auth(Single.new('basic')))
    .response(new_response_handler
                .deserializer(APIHelper.method(:custom_type_deserializer))
                .deserialize_into(TokenApiClientCredentials.method(:from_hash))
                .is_api_response(true))
    .execute
end