Link does not exist or invalid, API Facebook ADS / creating Javascript ad

0

I'm creating the creative ad like this:

FB.api(act_xxxxxxx  + '/adcreatives', 'POST', {
        name: vlName,
        title: vlTitle,
        body: vlBody,
        image_url: vlImage_url,            
        object_id: vlObject_id

    }, function (response) {
        if (response && !response.error) {
            var x = response.id;
            document.getElementById("txtIdRetornoAdsCreative").value = x;
            console.log(response);
        } else {
            document.getElementById("txtIdRetornoAdsCreative").value = "ERROR!";
            console.log(response);
        }
    }); 

Then I try to create the ADS, which I understand to be the final ad, like this:

 FB.api(act_xxxxxxx + '/ads', 'POST', {
            creative: { creative_id: document.getElementById("txtIdRetornoAdsCreative").value },
            name: 'TESTEFixo',
            status: 'PAUSED',
            adset_id: document.getElementById("idConjuntoAd").value

        }, function (response) {

            if (response && !response.error) {
                var x = response.id;
                document.getElementById("txtIdRetornoAdsCreative").value = x;
                console.log(response);
            } else {
                document.getElementById("txtIdRetornoAdsCreative").value = "ERROR2!";
                console.log(response);
            }

        });

I get the following error:

{
  "error": {
    "message": "Invalid parameter",
    "type": "OAuthException",
    "code": 100,
    "error_subcode": 1815520,
    "is_transient": false,
    "error_user_title": "Ad Creative Does Not Use Valid Link",
    "error_user_msg": "The link in this ad is either missing or invalid 
     

for Link Click Ads optimization. This could be because this ad   needs to link external content (e.g., an advertiser's website), but   this ad does not (e.g., it links to a Facebook page). Fix this error   by making the link valid. ",           "fbtrace_id": "ACX1uAPPDFE"         }       }

    
asked by anonymous 21.05.2018 / 23:34

1 answer

0

I found the problem, in the creative parameter it was missing one more value, thus:

FB.api(act_xxxx '/ads', 'POST', {
            name: 'TESTEFixo',
            status: 'PAUSED',
            adset_id: xxxxx,
            creative: {
                object_story_spec: {
                    page_id: xxxxxx,
                    link_data: {

                        link: 'https://link.com.br', 

                    }
                }
            },
        }
    
22.05.2018 / 15:22