1

I am trying to insert the record into the data extension. I am successfully fetching access token by sending client ID and Client Secret. However, when I try to call the API to insert the record into the DE, I am receiving

400 Bad Request Error.

Below is the code I am using

     HttpRequest req = new HttpRequest();  
     JSONGenerator gen = JSON.createGenerator(true);
     req.setTimeout(120000);
     req.setMethod('POST');             
     req.setEndpoint('https://www.exacttargetapis.com/data/v1/async/dataextensions/NikhilTest_0:keys/rows');
     req.setHeader('Content-Type', 'application/json');
     req.setHeader('Host', 'https://www.exacttargetapis.com');
     req.setHeader('Authorization', 'Bearer' + ' ' + token);
     gen.writeStartObject();
     gen.writeFieldName('items');
     gen.writeStartArray();
     gen.writeStartObject();
     gen.writeStringField('FirstName','Nikhil');
     gen.writeStringField('LastName','Khandare');
     gen.writeStringField('Id','12345');
     gen.writeEndObject();
     gen.writeEndArray();
     gen.writeEndObject();        
     String requestBody = gen.getAsString();
     System.debug('Request:' + requestBody );
     req.setBody(requestBody); 
     System.debug(requestBody );
     Http http = new Http(); 
     HTTPResponse res = new  HTTPResponse(); 
     res = http.send(req); 
     System.debug('Response:' + res);

In the above code, NikhilTest_0 is the external key of DE and FirstName, LastName and ID are the fields of DE.

Below is the body of JSON request I am sending.

{
  "items" : [ {
    "FirstName" : "Nikhil",
    "LastName" : "Khandare",
    "Id" : "12345"
  } ]
}

Please let me know what is causing the error I mentioned.

2 Answers 2

2

@nikhil

change your url to:

'https://www.exacttargetapis.com/data/v1/async/dataextensions/key:NikhilTest_0/rows'

0

I think your endpoint seems wrong. As per the documentation here, the endpoint is

Host : https://www.exacttargetapis.com Post : /data/v1/async/dataextensions/{key}:key/rows

Remove the extra 's' from the word "keys" in your endpoint and try again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .