Method: WhatsAppCloudApi::PhoneNumbersController#request_verification_code

Defined in:
lib/whats_app_cloud_api/controllers/phone_numbers_controller.rb

#request_verification_code(phone_number_id, code_method, locale) ⇒ SuccessResponse

Used to request a code to verify a phone number’s ownership. You need to verify the phone number you want to use to send messages to your customers. Phone numbers must be verified through SMS/voice call. The verification process can be done through the Graph API calls specified below. Chosen method for verification. “en_US”.

Parameters:

  • phone_number_id (String)

    Required parameter: Example:

  • code_method (RequestVerificationCodeMethodEnum)

    Required parameter:

  • locale (String)

    Required parameter: Your locale. For example:

Returns:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/whats_app_cloud_api/controllers/phone_numbers_controller.rb', line 102

def request_verification_code(phone_number_id,
                              code_method,
                              locale)
  # Prepare query url.

  _query_builder = config.get_base_uri
  _query_builder << '/{Phone-Number-ID}/request_code'
  _query_builder = APIHelper.append_url_with_template_parameters(
    _query_builder,
    'Phone-Number-ID' => { 'value' => phone_number_id, 'encode' => true }
  )
  _query_url = APIHelper.clean_url _query_builder

  # Prepare headers.

  _headers = {
    'accept' => 'application/json'
  }

  # Prepare form parameters.

  _parameters = {
    'code_method' => code_method,
    'locale' => locale
  }
  _parameters = APIHelper.form_encode_parameters(_parameters)

  # Prepare and execute HttpRequest.

  _request = config.http_client.post(
    _query_url,
    headers: _headers,
    parameters: _parameters
  )
  OAuth2.apply(config, _request)
  _response = execute_request(_request)
  validate_response(_response)

  # Return appropriate response type.

  decoded = APIHelper.json_deserialize(_response.raw_body)
  SuccessResponse.from_hash(decoded)
end