I've created a custom connector to GET and POST images to the Media Library from Wordpress.
This is the endpoint: https://mywebsite/wp-json/wp/v2/media
The function that I created is Wordpress.UploadImages(imagefile).
My goal is to upload images to the Wordpress Media library using the Camera Control and then connect them to the Woocommerce product that is being edited in Power Apps. The Product ID is found by using a unique number (the SKU) of the product.
I want to upload two collections: colExistingImages (the already existing images in Woocommerce for the product) and the colNewProductImages (images that are collected via the Camera Control).
I use the ImagesIds to put the collections together (I don't know if there is a better way to do this, but this worked for me).
When I try to upload the images via the Custom Connector I get the error "JSON-parse error: Array was expected, but object is received". The images are uploaded correctly, but Power Apps doesn't seem to be able to obtain the response correctly. What can I do to receive the single objects from the response and put them in a collection?
I've also added the custom connector swagger.json.
Any help is appreciated!
//Get product ID based on Text input (SKU)
Set(varProduct;WoocommerceAPI.GetProductID(varCurrentRecord.SKU));;
Set(varProductId;First(varProduct).id);;
//Get existing product images
Set(varProductImages;WoocommerceAPI.GetImagesFromProduct(varProductId));;
ClearCollect(colExistingImages;varProductImages.images);;
//Add camera photos to VarNewProductImages collection
Collect(
colNewProductImages;
ForAll(
colCameraPhotos;
Wordpress.UploadImages(ThisRecord.Base64String)
)
);;
//Design the structure of ImagesIds collection
ClearCollect(
ImagesIds;
{
name: "text";
images: [{id: 0}]
}
);;
//Collect Image ID's from Camera Control and from Existing Product images in ImagesIds collection
ClearCollect(
ImagesIds;
ForAll(
colExistingImages;
ThisRecord.id
);
ForAll(
colNewProductImages;
ThisRecord.id
)
);;
//Add Image ID's to the specific product
WoocommerceAPI.AddImagesToProduct(
varProductId;
{
images: ForAll(
ImagesIds;
{id: ThisRecord.Value}
)
}
)