Working with affinity group producer codes

A closed affinity group is typically associated with one or more producer codes. There is a separate set of endpoint for working with an affinity group's producer codes.

Querying for an affinity group's producer codes

To query for an affinity group's producer codes, use the following endpoint:

  • GET /admin/v1/affinity-groups/{affinityGroupId}/producer-codes

For example, the following request queries for the producer codes for affinity group pc:909. Note that it has two producer codes: 100-002541 (pc:7) and 501-002542 (pc:7).

GET /admin/v1/affinity-groups/pc:909

{
    "count": 2,
    "data": [
        {
            "attributes": {
                "id": "pc:6",
                "producerCode": {
                    "displayName": "100-002541",
                    "id": "pc:6"
                }
            },
            ...
        },
        {
            "attributes": {
                "id": "pc:7",
                "producerCode": {
                    "displayName": "501-002542",
                    "id": "pc:7"
                }
            },
            ...
            }
        }
    ],
    ...
}

Identifying producer code REST IDs

To associate a producer code with an affinity group, you must know the producer code's REST ID. There are two endpoints you can use to retrieve producer codes and their IDs - one in the Account API and one in the Admin API. These endpoints are:

  • GET /account/v1/producer-codes
  • GET /admin/v1/producer-codes

The Admin API version returns all producer codes, regardless of their status. The Account API version returns only the producer codes available to the caller. The Account API version omits producer codes that the caller cannot use (such as producer codes that are inactive or that are not available to the specific caller).

Associating a producer code with an affinity group

To associate a producer code with an affinity group, use the following endpoint:

  • POST /admin/v1/affinity-groups/{affinityGroupId}/producer-codes

This endpoint does not create a new producer code. Rather, it creates an association between the affinity group and an existing producer code.

For example, the following request associates producer code 501-002543 (pc:8) with affinity group pc:909.

POST /admin/v1/affinity-groups/pc:909/producer-codes

{
  "data": {
    "attributes": {
        "producerCode": {
            "id": "pc:8"
        }       
    }
  }
}

A closed affinity group can have multiple producer codes. However, each POST can associate only one producer code with the affinity group.

Removing a producer code from an affinity group

To remove a producer code from an affinity group, use the following endpoint:

  • DELETE /admin/v1/affinity-groups/{affinityGroupId}/producer-codes/{producerCode}

This endpoint does not delete the producer code. Rather, it deletes the association between the affinity group and the producer code.

For example, the following request removes producer code 501-002543 (pc:8) from affinity group pc:909.

DELETE /admin/v1/affinity-groups/pc:909/producer-codes/pc:8

<no request body>