Building insta access that we discussed last night. The pipedream “build comopnent/GPT” feature gave me:
[edit: Apologies, it was I was talking to about it last night]
"First, you’ll need to create a Pipedream app for Instagram and Shopify. Here’s the code for the Instagram and Shopify apps:
javascript
// Instagram App
export default defineApp({
type: "app",
app: "instagram",
propDefinitions: {
accessToken: {
type: "string",
secret: true,
label: "Access Token",
description: "Your Instagram access token.",
},
},
methods: {
async postImage(imageUrl, caption) {
return await axios(this, {
method: "POST",
url: "https://graph.instagram.com/me/media",
params: {
image_url: imageUrl,
caption,
access_token: this.accessToken,
},
});
},
},
});
// Shopify App
export default defineApp({
type: "app",
app: "shopify",
propDefinitions: {
apiKey: {
type: "string",
secret: true,
label: "API Key",
description: "Your Shopify API key.",
},
apiSecret: {
type: "string",
secret: true,
label: "API Secret",
description: "Your Shopify API secret.",
},
storeDomain: {
type: "string",
label: "Store Domain",
description: "Your Shopify store domain (e.g., [mystore.myshopify.com](http://mystore.myshopify.com)).",
},
},
methods: {
async getNewReleases() {
const url = `https://${this.storeDomain}/admin/api/2022-01/products.json`;
const auth = {
username: this.apiKey,
password: this.apiSecret,
};
const response = await axios(this, {
method: "GET",
url,
auth,
});
return response.products;
},
},
});
Now, create a Pipedream component that uses the Instagram and Shopify apps to post images from new releases in your Shopify store:
javascript
import { axios } from "@pipedream/platform";
export default defineComponent({
props: {
instagram: {
type: "app",
app: "instagram",
},
shopify: {
type: "app",
app: "shopify",
},
},
async run({ $ }) {
const newReleases = await this.shopify.getNewReleases();
for (const product of newReleases) {
const imageUrl = product.images[0]?.src;
const caption = `New release: ${product.title} - ${product.vendor}`;
if (imageUrl) {
await this.instagram.postImage(imageUrl, caption);
}
}
},
});
This component will fetch new releases from your Shopify store and post the images with a caption to your Instagram account. Note that you’ll need to provide the Instagram access token and Shopify API credentials when configuring the component in Pipedream."