Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Improve "Private App" API usage

Chiusa
#151 44 commenti 22 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
php
Ambito
api, backend

Direzione di ricerca

Inizia da src/Clients/Rest.php intorno all’header del token di accesso e segui Context::initialize e i relativi controlli di inizializzazione. Conferma il flusso diretto desiderato Rest($domain, $storeApiToken), inclusi i valori predefiniti elencati e il comportamento del logging, quindi verifica che il comportamento esistente dell’API e i test continuino a superare i controlli.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Overview/summary

Currently using this library when connecting to a private app is confusing.

It takes quite a long time to work out what you are doing, when it feels like it could be really simple.

Motivation

In our usecase, we only want to consume the Shopify admin api via REST, with a private app access token.

Currently to do that you have to have the following code:

Context::initialize(
  'xxx',                                          // Not used
  'yyy',                                          // Not used
  'read_orders, write_orders',                    // Not used
  'http://localhost',                             // Not used
  new FileSessionStorage('/tmp/php_sessions'),    // Not used
  'latest',
  false,                                          // Not used
  false,                                          // Needs to (incorrectly) be set to false
);

$rest = new Rest($domain, $storeApiToken);

This is not helped by the fact that there is a bug on this line:

https://github.com/Shopify/shopify-php-api/blob/main/src/Clients/Rest.php#L46

So you actually have to Context::initialize with "privateApp" to to false, so it uses the access token not the secret key.

       $headers[HttpHeaders::X_SHOPIFY_ACCESS_TOKEN] =
            Context::$IS_PRIVATE_APP ? Context::$API_SECRET_KEY : $this->accessToken;

There is barely any point in having to call Context::initialize, the only reason for doing it is to:

  • Set Context::$IS_INITIALIZED (to prevent an exception)
  • Default Context::$HTTP_CLIENT_FACTORY = new HttpClientFactory();

In an ideal situation I would just need to do this:

$rest = new Rest($domain, $storeApiToken);
Possible Improvements
  • Remove the need to call Context::initialize
  • Default the API version to 'unstable'
  • Default the initialization of $HTTP_CLIENT_FACTORY if null
  • Don't throw an exception during log if not initialized

Happy to contribute these changes, if you are welcome to receive them.

Lingua principale
PHP
Stelle
473
Fork
193
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.