kalkun-sms / Kalkun

Open Source Web based SMS Manager
https://kalkun.sourceforge.io/
GNU General Public License v2.0
211 stars 129 forks source link

REST_API - Missing or invalid default region #475

Closed rusyag closed 2 years ago

rusyag commented 2 years ago

Hello! Sending SMS via REST_API works fine if you log in directly to kalkun before that. But, if this is not done, the request leads to an error.

An uncaught Exception was encountered

Type: libphonenumber\NumberParseException

Message: Missing or invalid default region.

Filename: /var/www/vendor/giggsey/libphonenumber-for-php/src/PhoneNumberUtil.php

Line Number: 1659

Backtrace:

File: /var/www/vendor/giggsey/libphonenumber-for-php/src/PhoneNumberUtil.php
Line: 3108
Function: parseHelper

File: /var/www/application/helpers/kalkun_helper.php
Line: 371
Function: parse

File: /var/www/application/models/gateway/Gammu_model.php
Line: 192
Function: phone_format_e164

File: /var/www/application/models/gateway/Gammu_model.php
Line: 163
Function: _send_message_route

File: /var/www/application/models/Message_model.php
Line: 42
Function: send_messages

File: /var/www/application/plugins/rest_api/controllers/Rest_api.php
Line: 49
Function: __call

File: /var/www/application/plugins/rest_api/libraries/REST_Controller.php
Line: 182
Function: send_sms_get

File: /var/www/index.php
Line: 315
Function: require_once
tenzap commented 2 years ago

What is the exact URL you use (with parameters) for the REST call?

You must use a phone number in international format when using REST api. Since the Region set in the settings is user dependent, and since indeed you cannot be logged in when using REST, the phone number must be in international format (leading + with country code, like +111111111). Maybe that's the problem.

https://github.com/kalkun-sms/Kalkun/blob/b18e4feb508be626bdafa50c196ce0deef5b0633/application/helpers/kalkun_helper.php#L357 https://github.com/kalkun-sms/Kalkun/blob/b18e4feb508be626bdafa50c196ce0deef5b0633/application/helpers/kalkun_helper.php#L358

rusyag commented 2 years ago

Yes, I know, and I use the number in the international format.

image

By the way, if I log in to kalkun before using REST_API, then in the xml response I see a number not in international format.

image
tenzap commented 2 years ago

I updated the wiki https://github.com/kalkun-sms/Kalkun/wiki/Plugin:-REST-Api Please follow it again and tell me if that fixes your issues.

rusyag commented 2 years ago

Thank you for the tip. The issue was fixed.