linkedin-apilinkedin-jsapi

Target Audience Count in LinkedIn API


LinkedIn API v1 had an api endpoint to count the number of selected target audience. The later apis has this endpoint only for Ads-API

Now, I am trying to share posts using targeting criteria (Share API). I want to restrict posting if size of audience is less than 300. (As LinkedIn has a limit (audience size must be at least 300), I have to do a check first.) how do I count the size of target? (Note that, I have the count of individual categories with this endpoint: but these audiences might have intersection, so the sum of these counts aren't accurate.)

How does others use targeting api without this? Or am I missing something?


Solution

  • You can use the Audience Counts API, where you can pass the targetingCriteria as a list, as example:

    curl \
       -H "Authorization:Bearer <the_token>" \
       -H "Content-Type:application/json" \
       -H "X-Restli-Protocol-Version: 2.0.0" \
       "https://api.linkedin.com/v2/audienceCountsV2?q=targetingCriteriaV2&targetingCriteria=(include:(and:List((or:(urn%3Ali%3AadTargetingFacet%3AinterfaceLocales:List(urn%3Ali%3Alocale%3Aen_US))),(or:(urn%3Ali%3AadTargetingFacet%3Alocations:List(urn%3Ali%3Aregion%3A5636))))))"
    

    Will return something like:

    {
      "elements": [
        {
          "total": 1100000,
          "active": 0
        }
      ],
      "paging": {
        "count": 10,
        "start": 0,
        "links": []
      }
    }
    

    Take care of the correct encoding as described in the doc also.

    UPDATE

    In order to calculate organic post on a companyPage, you should add the followedCompanies criteria, as described in the doc here:

    The audience you target for your share must be greater than 300 members. Use the audienceCountsV2 API to calculate the approximate size of your audience. Make sure to pass in your company URN in the followedCompanies field of the targetingFacet parameter so your audience count will be filtered down to only members who follow your company.

    So referring to the previous example, for targeting a companyPage of ID = 123:

    curl \
       -H "Authorization:Bearer token" \
       -H "Content-Type:application/json" \
       -H "X-Restli-Protocol-Version: 2.0.0" \
       "https://api.linkedin.com/v2/audienceCountsV2?q=targetingCriteriaV2&targetingCriteria=(include:(and:List((or:(urn%3Ali%3AadTargetingFacet%3AfollowedCompanies:List(urn%3Ali%3Aorganization%3A123))),(or:(urn%3Ali%3AadTargetingFacet%3AinterfaceLocales:List(urn%3Ali%3Alocale%3Aen_US))),(or:(urn%3Ali%3AadTargetingFacet%3Alocations:List(urn%3Ali%3Aregion%3A5636))))))"
    

    Hope this help