Expand my Community achievements bar.

SOLVED

Updating segment definition via Adobe Analytics API 2.0

Avatar

Level 3

Hi all,

 

Has anyone successfully updated the segment definition via the AA API 2.0? I can update the name, description and owner but not the definition.

I get an 400 response when trying the below JSON with "definition" added and a 200 response when removing "definition" and just having "container" : {...}. But the definition does not update.

 

Request:

 

PUT_URL = f'https://analytics.adobe.io/api/{GLOBAL_COMPANY_ID}/segments/{SEGMENTID}?locale=en_US&expansion=definition'
response = requests.put(url=PUT_URL, headers=HEADER, data=json.dumps(data))

 

 

Here's an example data JSON

 

definition_update = {
    "name": "Test Segment",
    "description": "Test Segment description",
    "definition": {  
        "container": {
            "context": "visitors",
            "func": "container",
            "pred": {
                "func": "exists",
                "val": {
                    "func": "attr",
                    "name": "variables/page"
                }
            }            
        },
        "func": "segment",
        "version": [1, 0, 0]
    }
}

 

 

Error message with "definition" added:

 

Segment validation failed. HTTP 400 Bad Request - Segment validation failed, validation response was {\\"validator_version\\":\\"1.1.25\\",\\"message\\":[\\"Definition validation error\\"],\\"errors\\":[{\\"location\\":\\"version\\",\\"error\\":16,\\"message\\":\\"Unsupported Version: An unsupported version is given in the segment function...

 

 

I've already gone through these documentations but it doesn't actually show you an example of the data JSON passed into the PUT request to update a definition.

https://developer.adobe.com/analytics-apis/docs/2.0/guides/endpoints/segments/

https://adobedocs.github.io/analytics-2.0-apis/

https://github.com/AdobeDocs/analytics-2.0-apis/blob/master/segments-guide.md 

 

Thank you,

Vernon

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

hey @Vernon_H I have tested this endpoint and it works. Here's what I tried:

 

Segment Definition: Before update ->

fhusain_0-1729778683744.png

Then, in the endpoint, I used the below Body and got 200 response:

 

{"rsid":"reportsuiteId","definition":{"container":{"func":"container","context":"hits","pred":{"func":"and","preds":[{"func":"streq","str":"Bus Demo 1.0 (1)","val":{"func":"attr","name":"variables/mobileappid"},"description":"App Id"},{"func":"eq","num":1,"val":{"func":"total","evt":{"func":"event","name":"metrics/pageviews"}},"description":"Page Views"}]}},"func":"segment","version":[1,0,0]}}

 

fhusain_1-1729778876547.png

Segment Definition, after running the API endpoint:

fhusain_2-1729778903152.png

 

 

 

 

View solution in original post

2 Replies

Avatar

Correct answer by
Employee Advisor

hey @Vernon_H I have tested this endpoint and it works. Here's what I tried:

 

Segment Definition: Before update ->

fhusain_0-1729778683744.png

Then, in the endpoint, I used the below Body and got 200 response:

 

{"rsid":"reportsuiteId","definition":{"container":{"func":"container","context":"hits","pred":{"func":"and","preds":[{"func":"streq","str":"Bus Demo 1.0 (1)","val":{"func":"attr","name":"variables/mobileappid"},"description":"App Id"},{"func":"eq","num":1,"val":{"func":"total","evt":{"func":"event","name":"metrics/pageviews"}},"description":"Page Views"}]}},"func":"segment","version":[1,0,0]}}

 

fhusain_1-1729778876547.png

Segment Definition, after running the API endpoint:

fhusain_2-1729778903152.png

 

 

 

 

Avatar

Level 3

Thank you @fhusain! It seems the error must be with how I've nested the containers. After modification, it works now.