To update a trainer's name, we must first find out the ID of the trainer. This can be done by accessing the GET /v1/trainers/names/:trainer_id
endpoint:
curl \
-H 'Authorization: Bearer <access_token>' \
https://api.pkmnapi.com/v1/trainers/names/34
Now we know that BROCK has a trainer ID of 34.
To update BROCK's name, we must send a request to the POST /v1/trainers/names/:trainer_id
endpoint with the :trainer_id
of 34:
curl \
-X POST \
-H 'Authorization: Bearer <access_token>' \
-H 'X-Patch-Description: Change BROCK to ROCK' \
-H 'Content-Type: application/json' \
-d '{
"data": {
"type": "trainer_names",
"attributes": {
"name": "ROCK"
}
}
}' \
https://api.pkmnapi.com/v1/trainers/names/34
You should receive the following error:
{
"data": {
"id": "error_not_found",
"type": "errors",
"attributes": {
"message": "Trainer name length mismatch: should be exactly 5 characters, found 4"
}
}
}
Because of how some data is stored, the updated data must be either 1) exactly the same length, or 2) no bigger than the data it is replacing.
To circumvent this constraint, let's instead update BROCK's name to "ROCK " (with a trailing space) to get the exact same length:
curl \
-X POST \
-H 'Authorization: Bearer <access_token>' \
-H 'X-Patch-Description: Change BROCK to ROCK' \
-H 'Content-Type: application/json' \
-d '{
"data": {
"type": "trainer_names",
"attributes": {
"name": "ROCK"
}
}
}' \
https://api.pkmnapi.com/v1/trainers/names/34
Success!
Let's see if our change is reflected by requesting BROCK's (now ROCK's) name again:
curl \
-H 'Authorization: Bearer <access_token>' \
https://api.pkmnapi.com/v1/trainers/names/34
Should return:
{
"data": {
"id": "34",
"type": "trainer_names",
"attributes": {
"name": "ROCK "
},
"links": {
"self": "https://api.pkmnapi.com/v1/trainers/names/34"
}
},
"links": {
"self": "https://api.pkmnapi.com/v1/trainers/names/34"
}
}
That rocks!