Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in inserting CreativeAssets #101

Open
Mangeshr94 opened this issue Dec 21, 2023 · 2 comments
Open

Error in inserting CreativeAssets #101

Mangeshr94 opened this issue Dec 21, 2023 · 2 comments

Comments

@Mangeshr94
Copy link

Hi GCM Team,

I am getting below error when I am trying to insert the image file as creative Asset.

|USER_DEBUG|[57]|DEBUG|Error in insert CreativeAsset: {
"error": {
"code": 400,
"message": "19020 : The image type of file "" is not supported.",
"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"
}
]
}
}

I am passing the request body as below,

requestBodyJson==>{
"assetIdentifier":{
"type":"IMAGE",
"name":"Banner1.png"
},
"assetData":"aVZCT1J3MEtHZ29BQUFBTlNVaEVVZ0FBQVZ3QUFBRG9DQVlBQUFDak9sejdBQUFBQVhOU1IwSUFyczRjNlFBQUFBUm5RVTFCQUFDeGp3djhZUVVBQUFBSmNFaFpjd0FBRmlVQUFCWWxBVWxTSlBBQUFQK2xTVVJCVkhoZTdQMTNnS1ZaV2U0TnI2cE8weE82ZTRhUm5BVkJVQUVWRlJWRVBDb21VSUdENFJnUUF3cW9tRkFSTVNDaUlsa1VqS2hnUWxFOGlFZFJVUEdnb29DU00rZ0FBNU9uWjZaejEzZjlydnUrbnIxcVQvWEFPZS83ZmYvdzNWWHJ1WE5ZNFZuUDJyd"
}

please help me to resolve this issue.

Thanks,

@Mangeshr94 Mangeshr94 changed the title rror in inserting CreativeAssets Error in inserting CreativeAssets Dec 21, 2023
@Mangeshr94
Copy link
Author

public class uploadAssetClass {
@AuraEnabled
public static Object uploadAsset(String userProfileId,String advertiserId,blob assetData,String assetName,String assetType,String mimeType){

    Object result = null;
    
    String accessToken = Auth2.getAccessTokenMain();
    
    // Create asset identifier
    Map<String, Object> assetIdentifier = new Map<String, Object>();
    assetIdentifier.put('name', assetName);
    assetIdentifier.put('type', assetType);
    System.debug('assetName: ' + assetName);
    System.debug('assetType: ' + assetType);
    
    //Convert blob data to string
    String base64AssetData = EncodingUtil.base64Encode(assetData);
    
    // Create metadata with asset identifier
    Map<String, Object> metadata = new Map<String, Object>();
    metadata.put('assetData', base64AssetData);
    metadata.put('assetIdentifier', assetIdentifier);
    System.debug('assetIdentifier: ' + assetIdentifier);
    System.debug('assetData: ' + assetData);
    System.debug('metadata: ' + metadata);
    
    // Example: Making a callout (this might not compile directly, adjust based on your Salesforce setup)
    HttpRequest request = new HttpRequest();
    request.setMethod('POST');
    request.setEndpoint('endpoint url');
    String requestBodyJson = JSON.serialize(metadata);  
    
    // Set request body
    request.setBody(requestBodyJson);
    system.debug('requestBodyJson==>'+requestBodyJson);
    
    // Set request headers
    request.setHeader('Accept', 'application/json');
    request.setHeader('Content-Type','image/'+'PNG');
    request.setHeader('Content-Type', mimeType);
    system.debug('mimeType==>'+mimeType);
    request.setHeader('Authorization', 'Bearer ' + accessToken);
    
    // Set other required headers
    
    // Make the API callout
    Http http = new Http();
    HTTPResponse httpResponse = http.send(request);
    system.debug('httpResponse==>'+httpResponse);
    
    // Process the response
    if (httpResponse.getStatusCode() == 200) {
        result = 'Success'; // Replace this with your response parsing logic
    } else {
        result = 'Error'; // Replace this with your error handling logic
        httpResponse.getStatusCode();
        System.debug('Error in insert CreativeAsset: ' + httpResponse.getBody());
    }
    
    return result;
}

}

@Mangeshr94
Copy link
Author

this is the apex class which I am using

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant