Google Cloud DNS invalidZoneApex while trying to delete NS and SOA - google-cloud-dns

Using the DNS API I am trying to delete the NS and SOA record but I am getting this message:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidZoneApex",
"message": "The resource record set 'entity.change.deletions[0]' is invalid because a zone must contain exactly one resource record set of type 'SOA' at the apex."
},
{
"domain": "global",
"reason": "invalidZoneApex",
"message": "The resource record set 'entity.change.deletions[1]' is invalid because a zone must contain exactly one resource record set of type 'NS' at the apex."
}
],
"code": 400,
"message": "The resource record set 'entity.change.deletions[0]' is invalid because a zone must contain exactly one resource record set of type 'SOA' at the apex."
}
}
Via the google web console, I can update/modify the records and this helps me to add my custom NS and SOA so that I can use my own vanity name.
Besides that if I want to add a new NS or SOA I get an alreadyexists error.
How could totally manipulate the zone via the DNS API?

You can't delete the NS and SOA records because they are system-managed and required by the specifications for DNS - the error message says essentially this. You can't add a new one because you can only have one RRSet of a particular type at a particular name.
In general you can replace record sets by deleting and re-adding them in the same transaction. Which is to say, having a deletions and an additions in the same Changes.create call. I'm not sure offhand whether you can do this for the NS and SOA types at will, but if it works in the Cloud Console it will work on the API as the console just makes normal API calls.

Related

WSO2IS GET tenant by domain response does not contain the tenant id

Running WSO2IS v5.11.0. After creating a tenant with domain "example.com" using the addTenant endpoint, I execute the following REST call to retrieve it
GET https://host:port/t/carbon.super/api/server/v1/tenants/domain/example.com
Contrary to what is documented in the docs, the response does not contain the tenant's id. Here is the response:
{
"domain": "example.com",
"owners": [
{
"username": "test#example.com"
}
],
"createdDate": "2021-02-04T14:43:53.598Z",
"lifecycleStatus": {
"activated": true
}
}
Why is the id not included in the response? Am I doing something wrong or is this a bug?
Seems it is a bug in IS-5.11.0. If you try the latest milestone release 5.12.0-m9 you can retrieve the tenant id in your request.
The fix https://github.com/wso2/carbon-kernel/pull/2869 should have resolved that issue in the recent milestone versions. So you can patch this into 5.11.0 and use.
In IS-5.11.0,
If you create a tenant using POST request and retrieve the tenant by its domain GET https://host:port/api/server/v1/tenants/domain/example.com the tenant UUID will not return.
If you follow the following steps:
create a tenant using POST request
Find the Location header in the response header and get the tenant UUID
Get the tenant by GET /tenants/{tenant-id}
Next get the tenant by domain GET https://host:port/api/server/v1/tenants/domain/example.com - now you will get the tenant UUID (tenant object may be cached with its unique id due to the request in 3rd step)
So it's not an API level issue. Above mentioned carbon-kernel fix should have fixed the core level issue.

Foreign key constraint in REST API

I'm designing RESTful API for trip planner application and don't know how to enforce foreign key constraint on resource creation. I have two resources: Trip and User. Trip resource looks like this:
{
"id": 1,
//some other attributes
"tripParticipants":[
{
"id": 1
}
]
}
where tripParticipants is collection of User ids. TripParticipants should only contain created Users (by created I mean stored in database).
I have trouble with endpoint POST /trips/{id}/tripParticipants to add elements to the collection.
What should I return when User with given id doesn't exist in my database? Returning HTTP 404 status code for POST operation looks weird. Does REST standard defines some solutions to this use case?
There are two HTTP status codes that can be used in this situation:
422 Unprocessable entity
409 Conflict
Both are correct for your scenario. Personally I'd go with 422.
For Rest you follow the Http standard status codes, so 404 is the appropriate code for Rest.
These are the status codes you could be using https://www.restapitutorial.com/httpstatuscodes.html

Update Stock_level in OCAPI

How I can update the inventory (stock_level) using (business manager API).
I use the business manager API to retrieve products. I am able to retrieve the products but I am not sure how I can set its stock (stock_level).
I have a special requirement where product quantity cannot exceed 1, so for that I need to set it in an inventory so that I can test it.
I have tried to see if I can set inventory level using product but that doesn't seem possible.
When I try to get inventory following is the error
{
"_v": "18.8",
"fault": {
"arguments": {
"method": "GET",
"path": "/data/v18_8/inventory_lists/*"
},
"type": "ClientAccessForbiddenException",
"message": "Access to resource 'GET /data/v18_8/inventory_lists/*' is not allowed for the current client."
}
}
There is actually a DATA API endpoint that can be used to update inventory. It is called the ProductInventoryRecords resource.
You can update a product inventory record with a PATCH eg:
PATCH /inventory_lists/{inventory_list_id}/product_inventory_records/{product_id}
With a ProductInventoryRecordAllocation payload as such:
{
"_resource_state" : "847f9c3c5867f641470b3046aeec31f07757991b792d722e10079926f7a289fb",
"allocation": {
"amount": 2000,
"reset_date": "2016-03-31T14:05:40.872Z"
}
}
See more about this document type here.
Please note that the best practice is to pass the _resource_state key to ensure that the record is properly updated. OCAPI checks to see if this value is the same as the current state of the record if that attribute provided.
So systems should first check the record to get the _resource_state by performing a GET on the same resource.
Edit Note that you'll need an authorization token that grants you access to the API in order to make this kind of call.
your question is not crystal clear but I will try to answer. Commerce Cloud has three distinct (OCAPI) APIs:
Shop API (provides similar access as a customer on the site)
Data API (provides similar access as a merchant using business manager)
Meta API (describes the API from a functional perspective)
To get availability of a product in the inventory use below call: {{shop_url}}/products/701644676568M/availability and look at ATS in the response.
To set the stocklevel go into to business manager or use business manager import utility. There is no out-of-the-box API to update the stocklevel.

How can I retrieve a large number of DELETED Campaigns, Adsets, Ads?

Task
I'm trying to retrieve all Ad Campaign, Adsets and Ads from various accounts associated with our Business Manager.
Issue
The specific endpoints that I'm accessing are:
https://graph.facebook.com/v2.8/act_xxxxxxxxxxxxx/campaigns
https://graph.facebook.com/v2.8/act_xxxxxxxxxxxxx/adsets
https://graph.facebook.com/v2.8/act_xxxxxxxxxxxxx/ads
When I query some of these accounts for all Campaigns using the filter parameter,
[{'operator': 'IN',
'field': 'ad.effective_status',
'value': [
'ACTIVE',
'PAUSED',
'DELETED',
'PENDING_REVIEW',
'DISAPPROVED',
'PREAPPROVED',
'PENDING_BILLING_INFO',
'CAMPAIGN_PAUSED',
'ARCHIVED',
'ADSET_PAUSED']}]
the Facebook API always returns this error:
{"error":{"code":1,"message":"Please reduce the amount of data you're asking for, then retry your request"}}
Troubleshooting
I've used various values for the filter parameter such as 1, 25, 50, 100, 500.
I've tried limiting the date using the date_preset parameters (this seems irrelevant).
I've tried limiting the queries by filtering down to individual campaigns by including {'operator': 'IN','field':'campaign.id','value':['xxxxxxxxxxxxx']} as an additional filter in the filter parameter.
I've attempted batch requests and querying the /insights endpoint, but I haven't had one work yet.
Other Details
When I only include ACTIVE campaigns in the filter, the query works. This has allowed me to deduce that the DELETED campaigns are the problem. In other words, these accounts have a ton of DELETED campaigns.
I'm making my requests using Postman Version 5.0.0 (5.0.0).
I imagine if I can figure out how to get the Campaigns, the Adsets and Ads will be similar. How do I go about resolving this?
The reason is that the API does not actually support querying for deleted objects for certain endpoints. I tried to obtain all campaigns for a certain account and this is the response.
Method: GET
Path:
https://graph.facebook.com/v2.10/act_XXXX/campaigns
Params: {'effective_status': '["ACTIVE","PAUSED","DELETED","ARCHIVED"]', 'fields': 'id,name,status', 'summary': 'true'}
Response:
{
"error": {
"code": 100,
"is_transient": false,
"error_subcode": 1815001,
"error_user_msg": "Requesting for deleted objects is not supported in this endpoint.",
"error_user_title": "Cannot Request for Deleted Objects",
"message": "Invalid parameter",
"type": "OAuthException",
"fbtrace_id": "FYDwMABcwxj"
}
}
After looking at the documentation I discovered this
https://developers.facebook.com/docs/marketing-api/best-practices/storing_adobjects
And here they state
If you keep the deleted object id, you can continue to retrieve the
stats or object details by individually querying the object ID.
However you cannot retrieve the deleted objects as a connection object
from a non deleted node/object.

REST: How to update a row and create zero or more of other resource on same request?

I'll try to make this as simple as possible, it may be sort of dumb question.
I'm rewriting an 7 years old web application (help desk software). It is required to make it a REST API to be consumed by different clients web browser and mobile app. Also required to keep the business logic as close as possible to the original which for now have been working well.
The current struggle about REST:
What I need is to update the a resource lets say /tickets/47321
If the status_id of the this resource is changed a record of this change need to be saved, both in the same DB transaction because it need to be all-or-nothing. this is how the original application worked and we would like to keep this behavior.
So question is:
Can I PUT to tickets/47321 the whole resource or partial state representation to update the resource residing in server and create the new record of the history change (if status_id is different) and return them both back to client as JSON:
{
ticket: {}, // new ticket state
history: {} // the new created record of history change
}
This way the client can update the ticket and add the history to a list of history changes if there is any being return?
Technically, yes, you can do this. However, it might not be as straightforward as simply returning 2 objects, side by side; looking at the Richardson Maturity Model (Level 1), one would expect to receive the same type of resource after
calling (PUT) an api endpoint.
That being said, you could either embed the additional resource (append a history change to a ticket, following the Hypertext Application Language (HAL) proposed draft specification), or better yet (if you're aiming towards REST level 3), provide a link relationship, in conformity with the "Target IRI" defined in Web Linking specification (RFC 5988) from the ticket:
/api:history?ticketId=47321 would return all the history records belonging to that ticket, paged and sorted by created date, for example (and you can just select the latest)
/api:history?id=123 you would do some work on the server to ensure this points straight to the latest history record (related to that ticket id)
Regarding the partial update, looking at the RFC 6902 (which defines the Patch standard), from the client's perspective the API could be called like
PATCH /ticket/47321
[
{ "op": "replace", "path": "/author", "value": "David"},
{ "op": "replace", "path": "/statusId", "value": "1"}
]
More examples can be found here.