GetMediaByIds Service Operation - Campaign Management

Gets the specified media from an account's media library.

Note

This operation only supports media identifiers for location ad extensions. For getting image ad extension media, you should use GetMediaMetaDataByIds.

Request Elements

The GetMediaByIdsRequest object defines the body and header elements of the service operation request. The elements must be in the same order as shown in the Request SOAP.

Request Body Elements

Element Description Data Type
AccountId The identifier of the account that owns the media library. long
MediaIds The identifiers of the media to get.

You can specify a maximum of 10 media identifiers in a single call.
long array

Request Header Elements

Element Description Data Type
AuthenticationToken The OAuth access token that represents a Microsoft Account user who has permissions to Bing Ads accounts. string
CustomerAccountId The identifier of the account that owns the entities in the request. This header element must have the same value as the AccountId body element when both are required. string
CustomerId The identifier of the customer that contains and owns the account. If you manage an account of another customer, you should use that customer ID instead of your own customer ID. string
DeveloperToken The developer token used to access the Bing Ads API. string
Password The Bing Ads managed user's sign-in password. string
UserName The Bing Ads managed user's sign-in name. You must not set this element to a Microsoft account or email address. string

Important

The UserName and Password header elements are deprecated. In future versions of the API, Bing Ads will transition exclusively to Microsoft Account (email address) authentication. For more information, see Authentication with OAuth. UserName and Password are still required for Bing Ads managed credentials, but they are not applicable for Microsoft account authentication. To authenticate a Microsoft account, use the AuthenticationToken] header instead of UserName and Password.

Note

The CustomerAccountId and CustomerId are required for most service operations, and as a best practice you should always specify them in the request.

Response Elements

The GetMediaByIdsResponse object defines the body and header elements of the service operation response. The elements are returned in the same order as shown in the Response SOAP.

Response Body Elements

Element Description Data Type
Media The specified media from the library. Media array

Response Header Elements

Element Description Data Type
TrackingId The identifier of the log entry that contains the details of the API call. string

Request SOAP

The following template shows the order of the body and header elements for the SOAP request.

<s:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header xmlns="https://bingads.microsoft.com/CampaignManagement/v11">
    <Action mustUnderstand="1">GetMediaByIds</Action>
    <ApplicationToken i:nil="false">ValueHere</ApplicationToken>
    <AuthenticationToken i:nil="false">ValueHere</AuthenticationToken>
    <CustomerAccountId i:nil="false">ValueHere</CustomerAccountId>
    <CustomerId i:nil="false">ValueHere</CustomerId>
    <DeveloperToken i:nil="false">ValueHere</DeveloperToken>
    <Password i:nil="false">ValueHere</Password>
    <UserName i:nil="false">ValueHere</UserName>
  </s:Header>
  <s:Body>
    <GetMediaByIdsRequest xmlns="https://bingads.microsoft.com/CampaignManagement/v11">
      <AccountId>ValueHere</AccountId>
      <MediaIds i:nil="false" xmlns:a1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        <a1:long>ValueHere</a1:long>
      </MediaIds>
    </GetMediaByIdsRequest>
  </s:Body>
</s:Envelope>

Response SOAP

The following template shows the order of the body and header elements for the SOAP response.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header xmlns="https://bingads.microsoft.com/CampaignManagement/v11">
    <TrackingId d3p1:nil="false" xmlns:d3p1="http://www.w3.org/2001/XMLSchema-instance">ValueHere</TrackingId>
  </s:Header>
  <s:Body>
    <GetMediaByIdsResponse xmlns="https://bingads.microsoft.com/CampaignManagement/v11">
      <Media d4p1:nil="false" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">
        <Media d4p1:type="-- derived type specified here with the appropriate prefix --">
          <Id d4p1:nil="false">ValueHere</Id>
          <MediaType d4p1:nil="false">ValueHere</MediaType>
          <Type d4p1:nil="false">ValueHere</Type>
          <!--This field is applicable if the derived type attribute is set to Image-->
          <Data d4p1:nil="false">ValueHere</Data>
        </Media>
      </Media>
    </GetMediaByIdsResponse>
  </s:Body>
</s:Envelope>

Code Syntax

The example syntax can be used with Bing Ads SDKs. See Bing Ads Code Examples for more examples.

public async Task<GetMediaByIdsResponse> GetMediaByIdsAsync(
    long accountId,
    IList<long> mediaIds)
{
    var request = new GetMediaByIdsRequest
    {
        AccountId = accountId,
        MediaIds = mediaIds
    };

    return (await CampaignManagementService.CallAsync((s, r) => s.GetMediaByIdsAsync(r), request));
}
static GetMediaByIdsResponse getMediaByIds(
    java.lang.Long accountId,
    ArrayOflong mediaIds) throws RemoteException, Exception
{
    GetMediaByIdsRequest request = new GetMediaByIdsRequest();

    request.setAccountId(accountId);
    request.setMediaIds(mediaIds);

    return CampaignManagementService.getService().getMediaByIds(request);
}
static function GetMediaByIds(
    $accountId,
    $mediaIds)
{

    $GLOBALS['Proxy'] = $GLOBALS['CampaignManagementProxy'];

    $request = new GetMediaByIdsRequest();

    $request->AccountId = $accountId;
    $request->MediaIds = $mediaIds;

    return $GLOBALS['CampaignManagementProxy']->GetService()->GetMediaByIds($request);
}
response=campaignmanagement_service.GetMediaByIds(
    AccountId=AccountId,
    MediaIds=MediaIds)

Requirements

Service: CampaignManagementService.svc v11
Namespace: https://bingads.microsoft.com/CampaignManagement/v11