Bid modifier deletion is inefficient when associated to other objects

Posted in General by Jamie Phelps Tue Feb 26 2019 16:12:09 GMT+0000 (Coordinated Universal Time)·2·Viewed 271 times

When deleting a bid modifier, if there is an associated line_item or campaign, the deletion fails. But the resulting data does not give an indication of what associated objects must be corrected before the deletion can proceed. ## Currently I issue the following request: ``` DELETE /rest/bid_modifier/25106 HTTP/1.1 Content-Type: application/json; charset=utf-8 Cookie: PHPSESSID=COOKIE_SESSION_IDENTIFIER; accountnamesbx_buzz_cookie=COOKIE_SESSION_IDENTIFIER Host: accountnamesbx.api.beeswax.com Connection: close User-Agent: Paw/3.1.8 (Macintosh; OS X/10.14.3) GCDHTTPRequest Content-Length: 2 {} ``` and I get a response like this: ``` HTTP/1.1 406 Not Acceptable Date: Tue, 26 Feb 2019 15:38:56 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: close Server: nginx Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache X-Buzz-Request-Id: 3128232fb3db10274bc9b348084c1214 Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS, DELETE Access-Control-Allow-Headers: Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With X-Frame-Options: DENY { "success": false, "payload": [ { "id": 25106, "success": false, "error_code": "BID_MODIFIER_CANNOT_DELETE", "message": [ "ERROR: Bid Modifier cannot be deleted since it is associated with one or more Line Items" ] } ], "errors": [ "ERROR: Bid Modifier cannot be deleted since it is associated with one or more Line Items", "ERROR: bid_modifier deletion: 0 deleted successfully, 1 with errors" ] } ``` Now, because a Bid Modifier can be associated to a Campaign and/or a Line Item, I must request from each of those endpoints a list of objects that are associated with the Bid Modifier I want to delete, resulting in the following requests and responses: ``` GET /rest/campaign HTTP/1.1 Content-Type: application/json; charset=utf-8 Cookie: PHPSESSID=COOKIE_SESSION_IDENTIFIER; accountnamesbx_buzz_cookie=COOKIE_SESSION_IDENTIFIER Host: accountnamesbx.api.beeswax.com Connection: close User-Agent: Paw/3.1.8 (Macintosh; OS X/10.14.3) GCDHTTPRequest Content-Length: 27 {"bid_modifier_id":"25106"} HTTP/1.1 200 OK Date: Tue, 26 Feb 2019 15:41:48 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: close Server: nginx Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache X-Buzz-Request-Id: 9ed6f88ff1947e873bbc0881ae33d18c Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS, DELETE Access-Control-Allow-Headers: Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With X-Frame-Options: DENY { "success": true, "payload": [ ], "message": "No campaign found with that criteria" } GET /rest/line_item/5 HTTP/1.1 Content-Type: application/json; charset=utf-8 Cookie: PHPSESSID=COOKIE_SESSION_IDENTIFIER; accountnamesbx_buzz_cookie=COOKIE_SESSION_IDENTIFIER Host: accountnamesbx.api.beeswax.com Connection: close User-Agent: Paw/3.1.8 (Macintosh; OS X/10.14.3) GCDHTTPRequest Content-Length: 25 {"bid_modifier_id":25106} HTTP/1.1 200 OK Date: Tue, 26 Feb 2019 15:42:47 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: close Server: nginx Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache X-Buzz-Request-Id: 0d0bf632a310de16532ed6599269bba3 Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS, DELETE Access-Control-Allow-Headers: Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With X-Frame-Options: DENY { "success": true, "payload": [ { "line_item_id": 5, "campaign_id": 1, "advertiser_id": 1, "line_item_type_id": 0, "targeting_template_id": null, "bid_modifier_id": 25106, "max_bid": 8, "line_item_version": 1, "line_item_name": "campaign_1_a", "line_item_budget": 100, "daily_budget": null, "budget_type": 0, "currency": "USD", "line_item_spend": 0, "frequency_cap": [ ], "bidding": { "bidding_strategy": "cpm", "values": { "cpm_bid": 1.23 }, "pacing": "none", "custom": false }, "creative_weighting_method": "RANDOM", "pacing": null, "revenue_type": null, "revenue_amount": null, "last_active": "2019-02-25 16:30:05", "start_date": "2019-02-25 21:30:35", "end_date": null, "push_status": 0, "push_update": true, "account_id": 1, "create_date": "2019-02-25 16:30:05", "update_date": "2019-02-26 10:34:14", "alternative_id": null, "notes": null, "active": false, "buzz_key": "accountnamesbx" } ] } ``` So, at this point, I need to extract the list of ids for Line Items that have this bid modifier associated with them and make additional PUT requests to update each one: ``` PUT /rest/line_item/5 HTTP/1.1 Content-Type: application/json; charset=utf-8 Cookie: PHPSESSID=COOKIE_SESSION_IDENTIFIER; accountnamesbx_buzz_cookie=COOKIE_SESSION_IDENTIFIER Host: accountnamesbx.api.beeswax.com Connection: close User-Agent: Paw/3.1.8 (Macintosh; OS X/10.14.3) GCDHTTPRequest Content-Length: 39 {"bid_modifier_id":null,"max_bid":null} // REPEAT FOR EACH LINE ITEM AND/OR CAMPAIGN ``` ## Suggestion At a minimum, it would be useful if the 406 response body for the failed delete included the associated objects that prevented the deletion. Something like this: ``` HTTP/1.1 406 Not Acceptable Date: Tue, 26 Feb 2019 15:57:51 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: close Server: nginx Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache X-Buzz-Request-Id: 9bcf89f6011b690abafa06ea990e0b8f Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET, PUT, POST, OPTIONS, DELETE Access-Control-Allow-Headers: Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With X-Frame-Options: DENY { "success": false, "payload": [ { "id": 25107, "success": false, "error_code": "BID_MODIFIER_CANNOT_DELETE", "message": [ "ERROR: Bid Modifier cannot be deleted since it is associated with one or more Line Items" ] "refs": { "line_item_ids": [123], "campaign_ids": [] } ], "errors": [ "ERROR: Bid Modifier cannot be deleted since it is associated with one or more Line Items", "ERROR: bid_modifier deletion: 0 deleted successfully, 1 with errors" ] } ``` At least in this way, there would only be an additional N PUT calls to disassociate the Bid Modifier from the other objects (where N is the number of IDs). ## Additional Improvement If the PUT requests for Line Item and Campaign could accept an Array in addition to a Number for `entity_type_id:`, then it could be a convenient way to update them in a batch, something like this. Given a PUT payload to `/line_item` of: ``` {"line_item_id": [1, 2, 3], "bid_modifier_id":null,"max_bid":null} ``` the SQL could handle this directly in a single query: ``` UPDATE line_items li SET bid_modifier_id = NULL WHERE li.id IN (1, 2, 3) ```
Feb 26, 2019

I just found that the PUT documentation does indicate that multiple primary keys are acceptable, so my last section with "Additional Improvement" is moot.

Feb 26, 2019

Thanks for the feedback, definitely good points. I will forward to the product/eng team.

  
Markdown is allowed