Src is empty when setting theme src to a Github release zipball_url with the REST Admin theme API
Issue summary
When using the REST Admin theme API to create a new theme, setting the theme.src to a Github release zipball_url returns a {src: [ 'is empty' ]} error. Example code provided below:
*Note: the url I am using contains the DAWN theme
import {Theme} from '@shopify/shopify-api/dist/rest-resources/2022-04/index.js';
import { Shopify } from "@shopify/shopify-api";
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
// Api Call Below
// ...
const session = await Shopify.Utils.loadCurrentSession(req, res);
const ghZipballUrl = "https://api.github.com/repos/ndefie/release-test/zipball/v2.0.0"; // Release zipball_url I am using for testing
const theme = new Theme({session});
theme.name = "Github Release Name";
theme.src = ghZipballUrl;
theme.role = "unpublished";
await theme.save({});
// ...
Expected behavior
The new theme should be created with the Github release's theme without any errors.
Actual behavior
The api call returns a {src: [ 'is empty' ]} error. I have double checked and ensure that the url is returning a zip binary file that has the theme file content.
Steps to reproduce the problem
- Create a release and get the url to the specified release zipball url using the github api. Feel free to use
https://api.github.com/repos/ndefie/release-test/zipball/v2.0.0if it will help. - Create a new theme using the Shopify Rest Admin Create Theme API. Specify it's source to be the aforementioned github zipball url.
Checklist
- [x] I have described this issue in a way that is actionable (if possible)
Hi, @ndefie
I do not know much about theme api but your zip url is not an actual url that could be a problem.
https://codeload.github.com/ndefie/release-test/legacy.zip/refs/tags/v2.0.0 is an actual zip url which is the destination redirecting from https://api.github.com/repos/ndefie/release-test/zipball/v2.0.0
❯ wget https://api.github.com/repos/ndefie/release-test/zipball/v2.0.0
--2022-05-09 19:02:47-- https://api.github.com/repos/ndefie/release-test/zipball/v2.0.0
Resolving api.github.com (api.github.com)... 13.230.158.120
Connecting to api.github.com (api.github.com)|13.230.158.120|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/ndefie/release-test/legacy.zip/refs/tags/v2.0.0 [following]
--2022-05-09 19:02:47-- https://codeload.github.com/ndefie/release-test/legacy.zip/refs/tags/v2.0.0
Resolving codeload.github.com (codeload.github.com)... 52.68.31.213
Connecting to codeload.github.com (codeload.github.com)|52.68.31.213|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/zip]
Saving to: ‘v2.0.0’
v2.0.0 [ <=> ] 679.43K 3.56MB/s in 0.2s
2022-05-09 19:02:48 (3.56 MB/s) - ‘v2.0.0’ saved [695732]
so https://codeload.github.com/ndefie/release-test/legacy.zip/refs/tags/v2.0.0 might solve the problem you are facing now.
const session = await Shopify.Utils.loadCurrentSession(req, res);
const ghZipballUrl = "https://codeload.github.com/ndefie/release-test/legacy.zip/refs/tags/v2.0.0"
const theme = new Theme({session});
theme.name = "Github Release Name";
theme.src = ghZipballUrl;
theme.role = "unpublished";
await theme.save({});
@tomoyukikashiro Hi, thanks for replying. Unfortunately the new URL you provided does not make a difference in the result. However after calling the API multiple times consecutively with the zipball url (6++ times out of desperation) , it seems to finally work and is creating the new theme for me. So I modified the code to loop up to 10 times and break when the new theme is created successfully - this seems to work for me. I also managed to replicate this error behaviour and solution on a new release that I made https://api.github.com/repos/ndefie/release-test/zipball/v2.0.1.
While I have a temporary solution here, I still find this behaviour very weird and we shouldn't need to do the API call multiple times (other than for poor connection handling, which is usually 3 times). I'm not sure if I should keep this open or closed. For now I'll keep it open until more people takes a look into this and see if this is replicable and/or this is categorizes as Github's api issue/behaviour or the REST Admin Theme API fetch handling issue.
Thanks a lot 👍
@ndefie I found the answer in the document. https://shopify.dev/api/admin-rest/2022-01/resources/theme#post-themes
The theme will be published only after all of its files have been extracted and stored by Shopify, which might take a couple of minutes.
Theme create api is to save the zip file to shopify only the zip file needs to be extracted that would be exceeded asynchronously.
theme.save({}) method returns theme id then you need to check the status using theme get api.
await Theme.find({ session,id});
@ndefie Did you read / understand the comment above ?? Could you close this issue if you solve your problem.
This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.
We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.
If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines
Thank you!