Skip to content

MessageBird\Objects\Lookup::getFormats(): Return value must be of type ?array, stdClass returned #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
abbasjaber opened this issue Aug 8, 2022 · 3 comments

Comments

@abbasjaber
Copy link

Hello, I'm trying getFormats() function, I'm using Lookup Api and Laravel 9, and I got this error
MessageBird\Objects\Lookup::getFormats(): Return value must be of type ?array, stdClass returned

$lookup = $messageBird->lookup->read($phone[$i]);
$formats= $lookup->getFormats();
@Developer-lab
Copy link

Is there a update regarding this issue? I got the same problem.

@abbasjaber
Copy link
Author

@Developer-lab Actually I implemented the API without using package

 public function getRequest($phone)
    {
        try {
            $client             = new Client();
            $url                = 'https://rest.messagebird.com/lookup/' . $phone;
            $headers = [
                'Authorization' => 'AccessKey ' . Token::where('key', 'token')->first()->value,
            ];
            $response       = $client->request('GET', $url, [
                'headers'   => $headers
            ]);
            if ($response->getStatusCode()) {
                return ['statusCode' => 200, 'data' => json_decode($response->getBody()->getContents(), true)];
            } else return ['statusCode' => 400];
        } catch (Exception $ex) {
            return ['statusCode' => 400];
        }
    }
 $resp = $this->getRequest($phone[$i]);
if ($resp['statusCode'] == 200) {
                    $data = $resp['data'];
                    $excelData = SomeData::find($id);
                    $excelData->phoneCountryCode = $data['countryCode'];
                    $excelData->phoneLineType = $data['type'];
                    $excelData->phoneE164Format = $data['formats']['e164'];
                    $excelData->phoneInternationalFormat = $data['formats']['international'];
                    $excelData->phoneLocalFormat = $data['formats']['national'];
                    $excelData->save();
                }

and you need to use GuzzleHttp\Client;

CoolGoose pushed a commit that referenced this issue Jan 5, 2023
CoolGoose pushed a commit that referenced this issue Jan 5, 2023
CoolGoose pushed a commit that referenced this issue Jan 5, 2023
@CoolGoose
Copy link
Contributor

CoolGoose commented Jan 5, 2023

@Developer-lab will bump a patch release tomorrow to fix the difference in types. It will be a stdClass as per the new loading format, it is now fixed in the master branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants