Unable to update criteria for an existing subscription

Not Yet Reviewed

I am running into an issue where I keep getting a "400" error response from the xM API when I try to update the criteria property of a subscription. 

I have tried about a half dozen different type of data structures for my payload, I will post below some of the ones I have tried. 

I am sending this request to the "/subscriptions" endpoint. Some of my payloads have looked like this, each of which getting this same exact error:

Syntax error in request body

Payloads Tried:

 

*** Btw, this is POWERSHELL Code ***

## Tried mimicking the response payload of a subscription object
{
  "id": "[SUB UUID]",
  "criteria": {
    "total": 1,
    "count": 1,
    "data": [
      {
        "operator": "IS_ONE_OR_MORE_OF",
        "name": "Line of Business",
        "value": [
          "CFO: Dividend Management 2"
        ]
      }
    ]
  }
}
## Tried wrapping criteria in "data" array and making criteria a hash
{
  "id": "[SUB UUID]",
  "criteria": {
    "data": [
      {
        "operator": "IS_ONE_OR_MORE_OF",
        "name": "Line of Business",
        "values": ["CFO: Dividend Management 2"]
      }
    ]
  }
}

## BASED ON THE #CREATE from API Docs
{
  "id": "[SUB UUID]",
  "criteria": [
    {
      "operator": "IS_ONE_OR_MORE_OF",
      "name": "Line of Business",
      "values": ["CFO: Dividend Management 2"]
    }
  ]
}

 

Can anyone provide insight on this issue? Very confused...

 

 

0

Comments

4 comments
Date Votes

Please sign in to leave a comment.

  • Howdy. 

       Do you have the rest of the response body? I was playing with this and I got a couple different responses depending on what was wrong. I did successfully update the list of criteria with this payload:

    {
    "id": "UUIDHERE",
    "criteria": [
    {
    "name": "Fruits",
    "operator": "IS_ONE_OR_MORE_OF",
    "values": [ "Cherymoya" ]
    }
    ]
    }

     

    When I tried this payload, with criteria as an object instead of an array of objects:

    {
    "id": "1350d8d9-ecf7-4437-ad10-c6fcc3ee657b",
    "criteria": {
    "data": [
    {
    "name": "Fruits",
    "operator": "IS_ONE_OR_MORE_OF",
    "values": [
    "Blueberry"
    ]
    }
    ]
    }
    }

     

    I got this message:

    {"code":400,"message":"Syntax error in request body. Line:4 Column:19","reason":"Bad Request"}

    But when I had an invalid value, I got this:

    {"code":400,"message":"The field criteria.value cannot contain the value asdf.","reason":"Bad Request","subcode":"validation.common.field.invalid","arguments":["criteria.value","asdf"]}

     

    But I can confirm, your payload from the create subscription looks to be correct, so getting the rest of your response body would be helpful. The only other thing I would check is that the value exists in the list in the properties in the workflow and doesn't have any extra characters. 

     

     

    0
  • Ugh. Thanks Travis. The first example you gave was exactly what I tried initially, with one critical thing missing. Unlike Javascript, where a simple `[]` is an array and a simple `{}` is a hash, in PowerShell an Array is `@()` while variables are assigned instead of using `var or let` it uses `$`. It looks like my payload was exaclty like yours except the `VALUES` field was initialized with a `$` rather than an `@`, which caused it to be a STRING rather than an ARRAY, thereby breaking in the process.

    Thanks for the extra set of eyes :)

    0
  • For anyone using PowerShell and curious, this was my final form of the code. 

     

    ### $content is the formatted response of a subscription pulled from the API

    $rename = @{
    'CFO: Dividend Management' = 'CFO: Dividend Management 2' ## Example of old name (left) and new name (right)
    }

    $payload = @{
    id = $content.id
    criteria = @(
    @{
    name = $content.criteria.data.name
    operator = $content.criteria.data.operator
    values = @($rename[$content.criteria.data.values])
    }
    )
    }

    $payload = $payload | ConvertTo-Json -Depth 10
    $path = 'https://xxxxxxxx-np.xmatters.com/api/xm/1/subscriptions'
    0
  • Coding:

    95% banging your head on the table and cursing your job,
    5% sweet sweet working code and a moment of joy. 

    Happy to help, thanks for sharing your solution!

    0

Didn't find what you were looking for?

New post