Re: What is the format of tokens and leads(input json format) used in request campaign rest api? I am getting error code 609 with message Invalid value specified for attribute 'null' .

Anonymous
Not applicable

What is the format of tokens and leads(input json format) used in request campaign rest api? I am getting error code 609 with message Invalid value specified for attribute 'null'.

Please provide some example for the integration purpose.

Tags (1)
10 REPLIES 10
Grégoire_Miche2
Level 10

Hi Jatin,

Paste your code, it will be easier to help you.

-Greg

Anonymous
Not applicable

Hi Greg,

It is the same sample java code as given in request campaign rest api page.Here is the snippet for the input format.

public static void main(String[] args){

  RequestCampaign requestCampaign = new RequestCampaign();

  requestCampaign.id = 1079;

  requestCampaign.leadIds = new int[]{40};

  JsonObject myToken = new JsonObject()

  .add("name", "{{my.number}}")

  .add("value", "123456");

  requestCampaign.tokens = new JsonObject[]{myToken};

  System.out.println(requestCampaign.buildRequest());

  String result = requestCampaign.postData();

  System.out.println(result);

  }

The input json is printed in this format - {"input":{"leads":[40],"tokens":[{"name":"{{my.number}}","value":"123456"}]}}

Please reply. your help will be highly appreciated.

-Jatin

SanfordWhiteman
Level 10 - Community Moderator

The "leads" prop is an array of object { id:<int> id }. You are passing an array of integers.

Anonymous
Not applicable

Hi Sanford,

Thanks for your reply. Actually i am using same code as mentioned in  Request Campaign » Marketo Developers  and in this it is mentioned that we have to pass only id. So , can you guide me how to use this in correct way with some example as i am new to this.

Regards

Jatin

SanfordWhiteman
Level 10 - Community Moderator

Actually i am using same code as mentioned in Request Campaign » Marketo Developers

Not really.  You left out this critical part:

  JsonArray leads = new JsonArray();

  int i;

  for (i = 0; i < leadIds.length; i++) {

   leads.add(leadIds[i]);

  }

Please look at the whole code sample.  It's not perfectly intuitive but you're missing parts.

it is mentioned that we have to pass only id.

No, it's not.

Anonymous
Not applicable

Hi Sanford,

can you please share a working snippet and how to use multiple id's with request campaign api.

SanfordWhiteman
Level 10 - Community Moderator

Each lead identifier is a small JSON object, not just an int:

"leads" : [

{

      "id" : 12234

},

{

      "id" : 12235

}

]

So you need to wrap each lead ID in an instance of JSONObject.

Anonymous
Not applicable

I am following you but didn't getting the necessary changes that you are suggesting. Currently to get the output, i am using this.

public JsonObject[] leadIds;

JsonObject myLeads = new JsonObject().add("id", "40");

  JsonObject myLeads1 = new JsonObject().add("id", "41");

  requestCampaign.leadIds = new JsonObject[]{myLeads,myLeads1};

It is giving me correct output, but can you give something more optimized in accordance with the code.

SanfordWhiteman
Level 10 - Community Moderator

It is giving me correct output, but can you give something more optimized in accordance with the code.

As long as you're using Java's builder-based approach, it's always going to seem clunky compared to JS or PHP.  There are some libs you can use to allow for all-at-once JSON::stringify, like Gson.​ I can't vouch for any of these.

Anonymous
Not applicable

Is this the correct way to use it.

requestCampaign.leadIds = new JsonObject().add("id",41);