This topic was automatically generated from Slack. You can find the original thread here.
Hello pipedream crew. It’s been a while! I have a question regarding my pipedream/shopify private app. I’m trying to access write_checkouts scope with a shipping rate quote and it seems it’s not possible via a private app and I need to create a sales channel. Is this something likely to be integrated with pipedream, do I need to do it myself, or have I misunderstood something along the way…?
So it seems I need to connect the Storefront API instead of the Admin API. I investigated there and my only options were for “unauthenticated_write_checkouts” but nothing for “write_checkouts” was available so I guess I’m missing some level of authentication?
OK. I’m in. I pasted in the raw access code to the storefront API in my code. I’m not sure if the pipedream authentication step has access/delivered the storefront access code?
Hi Issue Summary:
While implementing a feature to update checkout details using the Shopify Storefront API within a Pipedream workflow, I encountered an authentication challenge. The core of the issue revolved around the need to use the X-Shopify-Storefront-Access-Token for authenticating API requests to Shopify’s Storefront API. This token is essential for performing operations such as creating or updating checkouts via the Storefront API, which requires specific permissions (scopes).
Initial Approach:
The initial code setup attempted to dynamically inject the Storefront API access token into the HTTP request headers using Pipedream’s platform variables:
However, this approach led to an authentication error, indicating that the token was not correctly applied or recognized in the request, resulting in a 401 Unauthorized response from Shopify’s API.
Resolution:
To overcome this authentication hurdle, I had to manually paste the Storefront API access token directly into the code instead of relying on Pipedream’s dynamic variable replacement. This manual insertion of the token successfully authenticated the request, allowing the API call to proceed and perform the intended actions on Shopify’s platform.
Underlying Problem:
The crux of the problem appears to be a discrepancy or issue with how Pipedream handles or injects the X-Shopify-Storefront-Access-Token into the API request. Instead of seamlessly applying the token stored in the shopify_developer_app app configuration, manual intervention was required to include the token explicitly in the code to authenticate the request successfully.
So from what I understanding, the Shopify API requires Admin API Access Token for Admin API, and StoreFront Access Token for StoreFront. But currently Pipedream’s Shopify Developer App does not allow you to input StoreFront Access Token right?
export default defineComponent({
props: {
shopify_developer_app: {
type: “app”,
app: “shopify_developer_app”,
}
},
async run({steps, $}) {
// Define GraphQL mutation for updating a checkout with a shipping line
const mutation = mutation checkoutShippingLineUpdate($checkoutId: ID!, $shippingRateHandle: String!) { checkoutShippingLineUpdate(checkoutId: $checkoutId, shippingRateHandle: $shippingRateHandle) { checkout { id webUrl shippingLine { handle title priceV2 { amount currencyCode } } } checkoutUserErrors { code field message } } } ;
// Variables for your GraphQL mutation
const variables = {
checkoutId: "Z2lkOi8vc2hvcGlmeS9DaGVja291dC8=", // This should be the Base64 encoded checkout ID
shippingRateHandle: "fedex_international_connect_plus-18.27" // Constructed handle, typically from previous shipping rate query
};
// Construct the data payload for the GraphQL request
const data = {
query: mutation,
variables: variables,
};
return await axios($, {
method: "post",
url: `https://${this.shopify_developer_app.$auth.shop_id}.[myshopify.com/api/2022-01/graphql](http://myshopify.com/api/2022-01/graphql)`,
headers: {
"X-Shopify-Storefront-Access-Token": `${this.shopify_developer_app.$auth.storefront_access_token}`, // Use the Storefront API access token here
"Content-Type": "application/json",
},
data: JSON.stringify(data),
})