How do I download build artifacts (IPA, APK) using the Codemagic API?

Context

If you want to download build artifacts such as IPA or APK files from Codemagic using the API, you cannot download them directly in a single request. The process requires a few steps to first locate the build and then retrieve a downloadable URL for the artifacts.

Answer

To download build artifacts via the Codemagic API, follow these three steps:

  1. Get the Build ID – List your team's builds and filter by status and/or tag to find the relevant build. Replace <team_id>, <tag_name>, and <api_key> with your actual values.

    curl 'https://codemagic.io/api/v3/teams/<team_id>/builds?status=finished&tag=<tag_name>' \
      --header 'Accept: application/json' \
      --header 'x-auth-token: <api_key>'
  2. Get the Artifact URLs – Use the Build ID retrieved in the previous step to fetch the artifact URLs.

    curl \
      -H "x-auth-token: <api_key>" \
      https://api.codemagic.io/builds/<id> | jq -r ".build.artefacts[].url"
  3. Generate a Public Download URL and Download the Artifact – Use the artifact URL from the previous step to generate a public URL, then download the artifact.

    # Define hours you want to add
    HOURS=24
    
    # Calculate Unix timestamp: current time + (3600 seconds/hour * number of hours)
    EXPIRY=$(($(date +%s) + (3600 * HOURS)))
    
    # Then use it in your curl command
    curl -H "Content-Type: application/json" \
      -H "x-auth-token: <api_key>" \
      -d "{\"expiresAt\": $EXPIRY}" \
      -X POST <artifact_url>/public-url
    
    OR
    
    curl -H "Content-Type: application/json" \
      -H "x-auth-token: <api_key>" \
      -d '{"expiresAt": <unix_timestamp>}' \
      -X POST <artifact_url>/public-url

    Replace <unix_timestamp> with the expiry time for the public URL (e.g., 1780396267), and <artifact_url> with the URL obtained in Step 2.

Once you have the public URL from Step 3, you can use it to download the artifact directly.