Upload Assets by REST API from client browser

84 views
Skip to first unread message

Maciej Bobrowski

unread,
Jul 8, 2024, 1:37:11 AM7/8/24
to Google's Campaign Manager 360 API Forum
Hi,

I want to upload an image via API to CM360 by JS in browser (by fetch). How should I do this? Currently I trying two methods, but neither works. With the first one I get an error: "100010 : Creative asset insert request does not contain any data." 
And with the 2nd:
"errors": [
 {
     "message": "19020 : The image type of file \"\" is not supported.",
     "domain": "global",
     "reason": "invalid"
 },
 {
     "message": "19004 : Invalid file name specified.",
     "domain": "global",
     "reason": "invalid"
 },
 {
     "message": "19017 : The name of the file can only contain the following characters: A-Z a-z 0-9 . = - _",
     "domain": "global",
     "reason": "invalid"
 }
 ]"

First:


const file = FILES[0];

fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${result.access_token}`,
},
body: formData
});

Second:

const file = FILES[0];
const fileBase64: any = await toBase64(file);

const media = {
mimeType: 'image/png', // zmień na odpowiedni typ MIME
body: fileBase64,
};

fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${result.access_token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
profileId: 'XXXXXXX',
advertiserId: 'XXXXXX',
media: media,
assetIdentifier: {
name: 'name.png',
type: 'IMAGE'
},
})
});

Best Regards
Maciej

DCM API (DoubleClick Campaign Mgr)

unread,
Jul 8, 2024, 4:06:32 AM7/8/24
to mabob...@gmail.com, google-doubleclick-...@googlegroups.com
Hi Maciej,

Thank you for reaching out to the DCM API support team.

From the shared information, I understand that you are facing issues while inserting the creative assets using the DCM API. Would you be able to try to change the 'Content-Type':"image/png" to Content-Type: image/jpeg as shown in this example of simple upload? We would also suggest to try a simple file name with no special characters just to narrow down the issue.

Below is a workable curl request that our team tested:

"""

curl -H "X-Goog-Upload-Protocol: multipart" -H "multipart/related" -F"metadata=@/usr/local/google/home/test/Desktop/data/upload.txt;type=application/json" -F "image=@/usr/local/google/home/test/Desktop/testAsset.jpeg;type=image/jpeg" https://test.com:0000/upload/dfareporting/v4/userprofiles/000000/creativeAssets/000000/creativeAssets

"""

test:data$ cat upload.txt

{

 "assetIdentifier": {

  "name": "testAsset.jpeg",

  "type": "HTML_IMAGE"

 }

}

You may try on your end if it will work for you. Just know that I have replace some of the private information to test and other details as well as domain name, account id, profile id and asset id for privacy purposes. You may change that accordingly as necessary.

However, if it still does not work for you. We would highly recommend reaching out to developers specialist support team as they are the ones who maintains our client library and would be best route to assist you with node js samples.

This message is in relation to case "ref:!00D1U01174p.!5004Q02tJkx0:ref" (ADR-00245444)

Thanks,
 
Google Logo DCM API Team


Maciej Bobrowski

unread,
Jul 8, 2024, 6:30:41 AM7/8/24
to Google's Campaign Manager 360 API Forum
Thanks for the answer.

The request itself looks like it's working because I get the following response:

{
"assetIdentifier": {
"type": "HTML_IMAGE",
"name": "07082024-032211945-image.jpeg"
},
"id": "885384971",
"richMedia": false,
"kind": "dfareporting#creativeAssetMetadata",
"mediaRequestInfo": {
"requestId": "ACJd0NokBpp...",
"notificationType": "END",
"currentBytes": "8397",
"totalBytes": "8397",
"totalBytesIsEstimated": false,
"customData": "",
"diffObjectVersion": "",
"finalStatus": 0,
"requestReceivedParamsServingInfo": ""
}
}

However, I cannot find the images in the CM360 panel. Is there anything else I should do?

And I have an additional question: can metadata be transferred in a different way than by uploading an additional file?

DCM API (DoubleClick Campaign Mgr)

unread,
Jul 8, 2024, 7:22:55 AM7/8/24
to mabob...@gmail.com, google-doubleclick-...@googlegroups.com
Hello,

Thank you for getting back to us.

If you are receiving the success code 200 while inserting the creatives then, please share the following details to investigate further:
  • DCM Account ID.
  • Complete JSON request and response logs.
  • Advertiser ID / Campaign ID.
  • The user email / service account email used for authenticating the API query.
From the documentation, the only possible way is to upload through the file. You may send the requested details privately via "Reply To Author" option.
Reply all
Reply to author
Forward
0 new messages