Profiles / Profile API |
Use PATCH to create or update a profile. There are two available PATCH syntaxes: attributes and changes.
If a profile for the given customer already exists, only the attributes specified in the request body will be modified. Other profile attributes in the same record will not be affected.
You cannot mix the two syntaxes in the same request.
Successful calls of either syntax return 202 Accepted. If some of the provided assignments or changes are not valid, the response will contain an ignored_changes field, comprising an array of objects describing which changes were ignored, and for what reason.
If the request contains no valid assignments or changes, the API will return 400 Bad Request.
When using the attributes syntax, provide key/value pairs. The special value null is used to delete key/value pairs from the profile.
PATCH https://profile.localytics.com/v1/profiles/Isa Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== Content-Type: application/json { "attributes": { "name": "Bob", "cats": ["Ofelia", "Mittens", "Spot", "Schrödinger"], "age": 30, "lucky numbers": [1, 48, -100, 13], "birthday": "1983-01-01", "delete me": null } }
When using the changes syntax, provide an array of diff objects, each specifying an update to a profile attribute. Each diff object takes one of the following forms.
Remove a key/value pair | {"op": "delete", | "attr": "foo"} | |
Set a value | {"op": "assign", | "attr": "foo", | "value": <some-value>} |
Increment/decrement an integer | {"op": "increment", | "attr": "foo", | "value": <some-integer-value>} |
Add values to set | {"op": "set-add", | "attr": "foo", | "value": <some-values>} |
Remove values from set | {"op": "set-remove", | "attr": "foo", | "value": <some-values>} |
PATCH https://profile.localytics.com/v1/profiles/Bob Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== Content-Type: application/json { "changes": [ {"op": "assign", "attr": "name", "value": "Robert"}, {"op": "increment", "attr": "age", "value": -1}, {"op": "set-remove", "attr": "cats", "value": ["Spot", "Schrödinger"]} ] }
If the two above updates are applied in order, the resulting profile is below.
{ "attributes": { "name": "Robert", "cats": ["Ofelia", "Mittens"], "age": 29, "lucky numbers": [1, 48, -100, 13], "birthday": "1983-01-01", } }