phpgoogle-apigoogle-oauthgoogle-api-php-clientandroid-pay

"Missing resource" error returned when creating new offerClass via googleapis/google-api-php-client


UPDATE: I have now just about worked out how to do this. I'm in the process of building a library to clear up the process flow and will link it here once it's in a state to start maintaining on Github.

Apologies for such a basic question, however I'm completely stuck and I can't seem to find any documentation that can help. I'll list the documentation I'm reading below.

The problem: I am following this guide that tells me to make a POST request to https://walletobjects.googleapis.com/walletobjects/v1/loyaltyClass in order to define a new class for my pass object to extend. In my case I'm actually using offerClass (https://walletobjects.googleapis.com/walletobjects/v1/offerClass) but I have tried with the other endpoint too.

However, the response returned is always the following:

{
  "error": {
    "code": 400,
    "message": "Missing resource.",
    "errors": [
      {
        "message": "Missing resource.",
        "domain": "walletobjects",
        "reason": "invalidResource"
      }
    ]
  }
}

and for the life of me I can't work out why. I must be missing something fundamental here.

I happened to also find this documentation that states "The request body contains an instance of OfferClass." referenced here -- the confusing part is that there is no OfferClass I can instantiate in the library, nor any sign of one on the internet. So I mocked one up myself with a simple array just to see if anything happened, it didn't.

What am I doing wrong? Why can't I make a successful POST request to this endpoint? I am able successfully make authorised requests to the API, but I'm just not getting the desired response. My code is below, which note is a Laravel console command, but it's not far from vanilla PHP:

public function handle(): void
{
    /** @var \Google\Client $this->client (for SO's benefit) */
    $this->client->setApplicationName('App name removed');

    $this->client->setScopes(
        [
            'https://www.googleapis.com/auth/wallet_object.issuer',
        ]
    );

    $credentialsPath = __DIR__ . '/service-accounts-credentials-8d8d4123ea65.json';

    $this->client->setAuthConfig($credentialsPath);

    $response = $this->client->authorize()->post('https://walletobjects.googleapis.com/walletobjects/v1/offerClass', [
        'form_params' => [
           $this->getOfferClass(), // returns the simple array mockup of OfferClass
        ]
    ]);

    dd($response->getBody()->getContents());
}

Any help would be greatly appreciated. I'm really stuck on this.

UPDATE: I have now found this repo which has some examples in, and I'm now getting a "Invalid resource ID" error. I can't find in any docs what the resource id should be. But perhaps this is progress.

UPDATE: I have foudn in the docs what the resource ID should be (I think) though it's just called "id" here I now get a "Permission denied" error!


Solution

  • I have now finished the enormous reorganising of the Google API example code, which had a 10k+ line file with 100s of classes inside of it. You can find my version of the library here, along with example usage: https://github.com/maxanstey/php-modern-google-pay