How to use the @shopify/network.Method.Post function in @shopify/network

To help you get started, we’ve selected a few @shopify/network examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Shopify / quilt / packages / koa-shopify-auth / src / verify-request / verify-token.ts View on Github external
return async function verifyTokenMiddleware(
    ctx: Context,
    next: NextFunction,
  ) {
    const {session} = ctx;

    if (session && session.accessToken) {
      ctx.cookies.set(TOP_LEVEL_OAUTH_COOKIE_NAME);
      // If a user has installed the store previously on their shop, the accessToken can be stored in session.
      // we need to check if the accessToken is valid, and the only way to do this is by hitting the api.
      const response = await fetch(
        `https://${session.shop}/admin/metafields.json`,
        {
          method: Method.Post,
          headers: {
            [Header.ContentType]: 'application/json',
            'X-Shopify-Access-Token': session.accessToken,
          },
        },
      );

      if (response.status === StatusCode.Unauthorized) {
        redirectToAuth(routes, ctx);
        return;
      }

      await next();
      return;
    }
github Shopify / quilt / packages / koa-shopify-webhooks / src / register.ts View on Github external
export async function registerWebhook({
  address,
  topic,
  accessToken,
  shop,
  apiVersion,
}: Options) {
  const response = await fetch(
    `https://${shop}/admin/api/${apiVersion}/graphql.json`,
    {
      method: Method.Post,
      body: buildQuery(topic, address),
      headers: {
        [WebhookHeader.AccessToken]: accessToken,
        [Header.ContentType]: 'application/graphql',
      },
    },
  );

  const result = await response.json();

  if (
    result.data &&
    result.data.webhookSubscriptionCreate &&
    result.data.webhookSubscriptionCreate.webhookSubscription
  ) {
    return {success: true, result};
github Shopify / quilt / packages / react-performance / src / performance-report.ts View on Github external
timeout.current = setTimeout(async () => {
      if (timeout.current) {
        clearTimeout(timeout.current);
        timeout.current = undefined;
      }

      try {
        await fetch(url, {
          method: Method.Post,
          headers: {
            [Header.ContentType]: 'application/json',
          },
          body: JSON.stringify({
            connection: serializableClone((navigator as any).connection),
            events: events.current,
            navigations: navigations.current.map(navigation => ({
              details: navigation.toJSON({removeEventMetadata: false}),
              metadata: navigation.metadata,
            })),
            pathname: window.location.pathname,
          }),
        });
      } catch (error) {
        if (onError) {
          onError(error);