# Choose a provider photo

Source: https://docs.musicnerd.net/api-reference/artist-images/choose-photo

Choose a provider photo

## PATCH /api/artist/photo-choice

Full OpenAPI specification: https://docs.musicnerd.net/spec/artist-images.json

## Authentication

This operation requires one of the security alternatives in the specification below. Security scheme definitions are included where present in the published specification.

[Authentication guide](https://docs.musicnerd.net/authentication)

## Operation and referenced schemas

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Music Nerd API: artist images",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://musicnerd-api.vercel.app",
      "description": "Production"
    },
    {
      "url": "https://musicnerd-api-staging.vercel.app",
      "description": "Staging (staging database)"
    }
  ],
  "paths": {
    "/api/artist/photo-choice": {
      "patch": {
        "summary": "Choose a provider photo",
        "operationId": "choosePhoto",
        "security": [
          {
            "privyBearer": []
          }
        ],
        "description": "Sets the artist's profile photo to one of the provider photos from [Photo choices](/api-reference/artist-images/photo-choice). The write is refused when the artist's current photo, the linked provider ID or the provider's photo changed since the choices were loaded. A changed photo clears the saved header position unless it was set for this same image.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PhotoChoice"
              },
              "example": {
                "artistId": "aab92f80-f9e1-4299-aa33-7dd85c8de5d3",
                "source": "deezer",
                "imageUrl": "https://e-cdns-images.dzcdn.net/images/artist/0a1b2c3d4e5f/1000x1000-000000-80-0-0.jpg",
                "expectedCustomImage": null,
                "providerId": "5590"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The photo was saved. `Cache-Control: no-store`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PhotoChosen"
                },
                "example": {
                  "status": "ok",
                  "success": true,
                  "imagePath": "https://e-cdns-images.dzcdn.net/images/artist/0a1b2c3d4e5f/1000x1000-000000-80-0-0.jpg",
                  "position": 0
                }
              }
            }
          },
          "400": {
            "description": "The body isn't a valid photo choice: unknown fields, a non-UUID `artistId`, a `source` other than `deezer` or `spotify`, or a bad `imageUrl`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "Invalid photo choice"
                }
              }
            }
          },
          "401": {
            "description": "No token, an invalid or expired token, or no Music Nerd user for it. `Cache-Control: no-store`, like every answer on this path.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "Not signed in"
                }
              }
            }
          },
          "403": {
            "description": "The user is neither the artist's claimant nor an admin, or the artist's claim changed while the write ran.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "notAuthorized": {
                    "summary": "Not the claimant or an admin",
                    "value": {
                      "status": "error",
                      "error": "Not authorized for this artist"
                    }
                  },
                  "ownershipChanged": {
                    "summary": "The claim changed during the write",
                    "value": {
                      "status": "error",
                      "error": "Artist ownership changed"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "No artist with that ID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "Artist not found"
                }
              }
            }
          },
          "409": {
            "description": "The choice is stale: the artist's current photo or linked provider ID differs from `expectedCustomImage` / `providerId`, or the provider now serves a different photo than `imageUrl`. Reload the choices.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "profileChanged": {
                    "summary": "The artist's photo or provider ID changed",
                    "value": {
                      "status": "error",
                      "error": "The profile changed. Close and reopen photo choices."
                    }
                  },
                  "providerPhotoChanged": {
                    "summary": "The provider's photo changed",
                    "value": {
                      "status": "error",
                      "error": "That provider photo changed. Close and reopen photo choices."
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "The write failed, or the token could not be checked. The current photo is unchanged.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "Could not save photo. Your current photo is unchanged."
                }
              }
            }
          },
          "503": {
            "description": "The provider has no photo for that ID right now. The current photo is unchanged.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "status": "error",
                  "error": "That photo is unavailable. Your current photo is unchanged."
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PhotoChoice": {
        "type": "object",
        "required": [
          "artistId",
          "source",
          "imageUrl",
          "expectedCustomImage",
          "providerId"
        ],
        "additionalProperties": false,
        "properties": {
          "artistId": {
            "type": "string",
            "format": "uuid",
            "description": "The artist's ID."
          },
          "source": {
            "$ref": "#/components/schemas/PhotoSource"
          },
          "imageUrl": {
            "type": "string",
            "format": "uri",
            "maxLength": 4096,
            "description": "The option's `imageUrl` as the choices returned it. The server re-resolves the photo and refuses the write if it differs."
          },
          "expectedCustomImage": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 4096,
            "description": "The `expectedCustomImage` the choices returned."
          },
          "providerId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "description": "The option's `providerId`."
          }
        }
      },
      "PhotoChosen": {
        "type": "object",
        "required": [
          "status",
          "success",
          "imagePath",
          "position"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok"
            ]
          },
          "success": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "imagePath": {
            "type": "string",
            "description": "The artist's new `customImage`: the provider photo URL as the server resolved it."
          },
          "position": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "description": "The header position's `y` after the change: kept when it was set for this same image, otherwise 0."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "status",
          "error"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "error"
            ]
          },
          "error": {
            "type": "string"
          }
        }
      },
      "PhotoSource": {
        "type": "string",
        "enum": [
          "deezer",
          "spotify"
        ],
        "description": "Which provider the photo comes from."
      }
    },
    "securitySchemes": {
      "privyBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Access token",
        "description": "The signed-in user's access token. Copy it at https://musicnerd.net/access after signing in. The user must be the artist's approved claimant or a Music Nerd admin."
      }
    }
  }
}
```
