Hi,

Thank you for the detailed question, and you highlight an important
use case for the valudateOnly header.  We are still working on
developing a clear example of ad validation in our client libraries,
but I can provide some guidance in the mean time.

As for the reason field, since it is not a part of the base ApiError
object it is not easy to access it in strongly typed languages like
Java.  As you mentioned it would involve testing and casting the
ApiError for each subtype, which is a heavy handed solution.  One
workaround would be to use reflection to test if the object has the
field (or method getReason() in this case), and if so read it's value.

The only link between an ApiError and the offending operation is the
fieldPath field.  The OGNL expression indicates exactly which field in
the input contained the error.  Although a full OGNL parser would be
ideal, you should be able to use a simple regular expression to
determine which operation (and hence ad) caused the error.  I am not
sure if an operation can lead to more than one API error.

Best,
- Eric Koleda, AdWords API Team

On Dec 21, 6:19 pm, "j.e.frank" <[email protected]> wrote:
> I am migrating code from v13 to v2009.  One portion of my application
> is used to add ImageAds to multiple Campaigns and AdGroups at once.
> I'm interested in rewriting the code to take advantage of the
> validateOnly capability, so that I can validate all the ads before
> trying to add them, and report back to the user for any validation
> errors.
>
> I'm looking for some code samples that use validation like this (in
> Java).  I see the simple example on the AdWords API Blog about the
> validateOnly header, but I am not sure how to adapt it for a more
> general and robust use case.  I can do some trial-and-error coding,
> but before I do that, I'm sure that someone else has already done it,
> and so I'd love to piggy back on that.
>
> The first issue is that I don't want to have to test the inner
> ApiError to see if it is one of about 25 specific subclasses, in order
> to let the user know what kind of thing went wrong.  Probably I will
> just report back the ApiErrorType field, which is common to all,
> although it would be nice to be able to get at the more specific
> "reason" field that exists in some of the subclasses.  Is there a
> recommended way to deal with this issue?
>
> The second issue is that it is not clear to me how to match up the
> ApiError in the ApiException.getErrors array with the particular Ad
> that fails validation.  Let's say I pass in 10 Ad objects to mutate
> (using the Validation version of the service), and the Ad in position
> 3 doesn't pass for some reason.  Will the getErrors array have just
> one ApiError (assuming all other Ads were fine), and if so how can I
> tell which Ad it applies to?  Also, is it possible to have multiple
> ApiErrors for a single Ad, for example if it has multiple problems?
> Again I am not sure how to match up the error(s) with the offending Ad
> (s).  I can see that the "fieldPath" property would be useful here,
> but I don't want to write an OGNL parser to deal with it, although
> there may be a simpler way of using this information that I haven't
> thought of.  I could restructure my code to only try one Ad at a time,
> so that it is clear what Ad the errors apply to, but then I get more
> round-trips and more latency.  What is the recommended way to handle
> this issue?

--

You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/adwords-api?hl=en.


Reply via email to