I need some help with the google ad manager API. I am trying to delete a lineitem with the following:
from googleads import ad_manager
client = ad_manager.AdManagerClient.LoadFromStorage()
def test(id):
line_item_service = client.GetService('LineItemService',version='v202002')
line_item_name = str(id)
statement = (ad_manager.StatementBuilder(version='v202002').Where('OrderId = :OrderId').WithBindVariable('OrderId',app.config['AD_MANAGER']['ORDER_ID']))
response = line_item_service.performLineItemAction(line_item_service.DeleteLineItems(),statement.ToStatement())
My problem lies with DeleteLineItems() as I am not sure how to call it correctly. I am not able to find clear usage examples, hence my attempt above. Below are the docs I could find. The error of my current attempt is:
{success: false, error: "<class 'googleads.errors.GoogleAdsValueError'>", message: "Service DeleteLineItems not found"}
https://developers.google.com/ad-manager/api/reference/v202011/LineItemService.DeleteLineItems
https://developers.google.com/ad-manager/api/reference/v202011/LineItemService#performLineItemAction
So I finally found the answer.
The performLineItemAction takes in 2 parameters. The first one is the LineItemAction and the second is a Statement. I found the docs a little confusing because I thought the LineItemAction was a method of the LineItem object. It turns out that the first parameter is actually a dictionary.
line_item_service.performLineItemAction({'xsi_type':'ArchiveLineItems'},statement.ToStatement())
As a side note, once a line item is being delivered we cannot delete it. We can either pause it or archive it. In this case I've chosen to archive it. The different types of line item actions can be found here.
https://developers.google.com/ad-manager/api/reference/v202011/LineItemService#performLineItemAction
Related
I'm making a logging system with discord.py. For now, I'm trying to get the number of messages were deleted from a single audit log entry (since sometimes the audit logs updates an entry instead of creating a new one), so I tried with "entry.action.count". Here's my code
#client.command()
#commands.has_permissions(administrator=True)
async def deletecount(ctx):
async for entry in ctx.guild.audit_logs(limit=1, action=discord.AuditLogAction.message_delete):
print(entry.action.count)
But instead of printing the number of messages deleted, it just prints
<built-in method count of _EnumValue_AuditLogAction object at 0x000001FF9769C640>
From this screenshot, in this case the latest entry has 5 deleted messages. I'm trying to print out that "5". So how do I get the number of message deleted from the latest audit log entry? The documentation doesn't have further information on how to use the extra attribute for entry.action.
I should also add that I have asked someone about this, they suggested to try print(entry.action.count()), but I got
TypeError: tuple.count() takes exactly one argument (0 given)
What is the argument that should be given there? Thanks in advance.
It is possible, use the extra attribute and it will return a dict with the data you want (the docs don't give you a lot of information about it because the return value differs from the type of action):
async for entry in ctx.guild.audit_logs(limit=1, action=discord.AuditLogAction.message_bulk_delete):
count = entry.extra['count']
The return value of AuditLogEntry.extra varies depending on the type of event, the example above will only work with message_bulk_delete
PS: You were using the wrong action in the iterator, it should be AuditLogAction.message_bulk_delete not AuditLogAction.message_delete
References:
AuditLogEntry.extra
For context, I'm someone with zero experience in Ruby - I just asked my Senior Dev to copy-paste me some of his Ruby code so I could try to work with some APIs that he ended up putting off because he was too busy.
So I'm using an API wrapper called zoho_hub, used as a wrapper for Zoho APIs (https://github.com/rikas/zoho_hub/blob/master/README.md).
My IDE is VSCode.
I execute the entire length of the code, and I'm faced with this:
[Done] exited with code=0 in 1.26 seconds
The API is supposed to return a paginated list of records, but I don't see anything outputted in VSCode, despite the fact that no error is being reflected. The last 2 lines of my code are:
ZohoHub.connection.get 'Leads'
p "testing"
I use the dummy string "testing" to make sure that it's being executed up till the very end, and it does get printed.
This has been baffling me for hours now - is my response actually being outputted somewhere, and I just can't see it??
Ruby does not print anything unless you tell it to. For debugging there is a pretty printing method available called pp, which is decent for trying to print structured data.
In this case, if you want to output the records that your get method returns, you would do:
pp ZohoHub.connection.get 'Leads'
To get the next page you can look at the source code, and you will see the get request has an additional Hash parameter.
def get(path, params = {})
Then you have to read the Zoho API documentation for get, and you will see that the page is requested using the page param.
Therefore we can finally piece it together:
pp ZohoHub.connection.get('Leads', page: NNN)
Where NNN is the number of the page you want to request.
how can I get ALL records from route53?
referring code snippet here, which seemed to work for someone, however not clear to me: https://github.com/aws/aws-sdk-ruby/issues/620
Trying to get all (I have about ~7000 records) via resource record sets but can't seem to get the pagination to work with list_resource_record_sets. Here's what I have:
route53 = Aws::Route53::Client.new
response = route53.list_resource_record_sets({
start_record_name: fqdn(name),
start_record_type: type,
max_items: 100, # fyi - aws api maximum is 100 so we'll need to page
})
response.last_page?
response = response.next_page until response.last_page?
I verified I'm hooked into right region, I see the record I'm trying to get (so I can delete later) in aws console, but can't seem to get it through the api. I used this: https://github.com/aws/aws-sdk-ruby/issues/620 as a starting point.
Any ideas on what I'm doing wrong? Or is there an easier way, perhaps another method in the api I'm not finding, for me to get just the record I need given the hosted_zone_id, type and name?
The issue you linked is for the Ruby AWS SDK v2, but the latest is v3. It also looks like things may have changed around a bit since 2014, as I'm not seeing the #next_page or #last_page? methods in the v2 API or the v3 API.
Consider using the #next_record_name and #next_record_type from the response when #is_truncated is true. That's more consistent with how other paginations work in the Ruby AWS SDK, such as with DynamoDB scans for example.
Something like the following should work (though I don't have an AWS account with records to test it out):
route53 = Aws::Route53::Client.new
hosted_zone = ? # Required field according to the API docs
next_name = fqdn(name)
next_type = type
loop do
response = route53.list_resource_record_sets(
hosted_zone_id: hosted_zone,
start_record_name: next_name,
start_record_type: next_type,
max_items: 100, # fyi - aws api maximum is 100 so we'll need to page
)
records = response.resource_record_sets
# Break here if you find the record you want
# Also break if we've run out of pages
break unless response.is_truncated
next_name = response.next_record_name
next_type = response.next_record_type
end
I'm trying to add a new member of a groupOfUniqueNames object but I get an "ENTRY_ALREADY_EXISTS" error.
The server is ApacheDS, and my code is Ruby, using using net-ldap:
ldap.add(dn: 'cn=janitors,dc=tidy,dc=example,dc=com',
attributes:
{
:objectclass => "groupOfUniqueNames",
:uniqueMember =>
"uid=broom001,o=users,dc=tidy,dc=example,dc=com"
}
)
There is already one member in janitors -- mop99 . When I call ldap.add, I get (reformatted slightly for readability):
ldap.response: ERR_250_ENTRY_ALREADY_EXISTS cn=janitors,dc=tidy,dc=example,dc=com already exists!
OpenStruct {
:code => 68,
:error_message => "ENTRY_ALREADY_EXISTS: failed for MessageType : ADD_REQUEST
Message ID : 2
Add Request :
Entry
dn[n]: cn=janitors,dc=tidy,dc=example,dc=com
objectclass: groupOfUniqueNames
uniqueMember: uid=mop99,o=users,dc=tidy,dc=example,dc=com
: ERR_250_ENTRY_ALREADY_EXISTS cn=janitors,dc=tidy,dc=example,dc=com already exists!
",
:matched_dn => "",
:message => "Entry Already Exists"
}
I've tried changing ldap.add() to ldap.modify(), but that just replaces mop99 with broom001, leaving only one janitor. What I need is to add broom001, to end up an ever-growing army of janitors.
I could read the existing list from LDAP, append the new entry to the list in Ruby, and then write the list back to LDAP...but that introduces a race condition where a janitor could be lost when two try to add at the same time. My janitors are too valuable, so that is unacceptable.
I've searched the web extensively without finding much, and nothing related to net-ldap. I did find https://www.openldap.org/lists/openldap-software/199912/msg00164.html which describes a solution WRT .LDIF files, but I don't know how to translate that to net-ldap.
What am I missing?
Adding the object class doesn't make sense. It's already there.
Just add the unique member value.
Ok...I feel a little dumb. Here is the correct answer:
ldap.add_attribute(dn, attribute, value)
Or specifically for my new janitor:
ldap.add_attribute('cn=janitors,dc=tidy,dc=example,dc=com',
'uniqueMember',
'uid=broom001,o=users,dc=tidy,dc=example,dc=com')
Ba-boom. That's it. Just what I needed. blush
I'm leaving my previous ridiculous answer, as it is one way of populating a list from scratch, and might be useful in some scenarios.
I'm also leaving this whole embarrassing question, in case anyone else overlooks add_attribute() in the documentation and gets frustrated trying to search for this problem.
One remaining frustration with ruby-net-ldap that seems to remain is that delete_attribute() does NOT accept a third argument -- namely, the value to be deleted from the group. You can only use delete_attribute to delete the entire group, not individual entries. But I don't need to delete only a single value from the group, so la-ti-da...
I have a Meal object that stores pointers to n created objects "FoodInfo" using the key "MealItems".
When I query for the meal I take advantage of the [query includeKey:#"MealItems"] to fetch the items pointed to while fetching the "Meal".
This works swimmingly if the objects are created while online (ie. all are stored in the cloud db).
However, since I cannot assume access to the cloud at all time for this app I am now trying to enable the local datastore so I've changed my queries to use:
[query fromLocalDatastore];
and I've changed all of my objects' save methods to pinInBackgroundWithBlock followed by (assuming success of local save) saveInBackgroundWithBlock followed by (assuming failure) saveEventually.
To test this, I:
turned off wifi
ran the code to create a meal and then add newly created foods to it. This works with no error codes.
ran a report that then queries for the meal just created. This fails with the following:
Error: Error Domain=Parse Code=121
"include is invalid for non-ParseObjects" UserInfo=0x60800007f400 {
error=include is invalid for non-ParseObjects,
NSLocalizedDescription=include is invalid for non-ParseObjects,
code=121
} {
NSLocalizedDescription = "include is invalid for non-ParseObjects";
code = 121;
error = "include is invalid for non-ParseObjects";
}
Is this scenario not supported?
When I re-enable wifi, the meal is successfully added to the online db, but the query failure still happens when I run the query with the includeKey locally.
Am I missing something here? I'm quite surprised to see this failing. It seems like a really basic feature that should work whether local or cloud based.
Parse objects are not created until you save them. Try using saveEventually first before using pinInBackgroundWithBlock.