JSON request to Edge

Hi All,

I am trying to replicate company JSON request to my php curl command but getting the issue .

Company Creation Request on Apigee:{
   "name": "{unique-company-name-that-won't-change}",     "displayName": "{company name displayed in the UI}",
    "attributes": [
        {
            "name": "ADMIN_EMAIL",
            "value": "{company owner email address}"
        },
        {
            "name": "MINT_BILLING_TYPE",
            "value": "{one of PREPAID | POSTPAID}"
        },
        {
            "name": "MINT_DEVELOPER_LEGAL_NAME",
            "value": "{legal name of company for reports}"
        },
        {
            "name": "MINT_TAX_EXEMPT_AUTH_NO",
            "value": "{government tax exemption number, if applicable}"
        },
        {
            "name": "MINT_DEVELOPER_PHONE",
            "value": "{company phone number}"
        },
        {
            "name": "MINT_DEVELOPER_ADDRESS",
            "value": "{\"address1\":\"123 Main St.\",\"city\":\"Anytown\",\"country\":\"US\",\"isPrimary\":true}"
        },
        {
            "name" : "{custom_attribute1_name}",
            "value" : "{value1}"
        } 
            ]
} 



And this is my php code:


$customdata=array( "name" =>"Test_Company4", "displayName" =>"Test Company4",
"attributes" =>array(
"ADMIN_EMAIL" =>"test@gmail.com"));

and i am getting the error

{ "message" : "Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at 
[Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@52ba3b0a; line: 1, column: 54]
(through reference chain: com.apigee.company.Company[\"attributes\"])", "contexts" : [ ] }
Solved Solved
0 5 644
1 ACCEPTED SOLUTION

I think you want this PHP code:

$customdata=array( 
    "name" => "Test_Company4", 
    "displayName" => "Test Company4",
    "attributes" => array(
         array("name" => "ADMIN_EMAIL", "value" => "test@gmail.com"),
         array("name" => "MINT_BILLING_TYPE", "value" => "POSTPAID"),
         ...
    )
  );

The error you are seeing is from Apigee Edge. Apigee Edge is complaining that it cannot de-serialize the thing it wants to deserialize, from the JSON you have passed in.

By changing your PHP code, you will tell PHP to construct the JSON that Apigee Edge expects.

View solution in original post

5 REPLIES 5

I think you want this PHP code:

$customdata=array( 
    "name" => "Test_Company4", 
    "displayName" => "Test Company4",
    "attributes" => array(
         array("name" => "ADMIN_EMAIL", "value" => "test@gmail.com"),
         array("name" => "MINT_BILLING_TYPE", "value" => "POSTPAID"),
         ...
    )
  );

The error you are seeing is from Apigee Edge. Apigee Edge is complaining that it cannot de-serialize the thing it wants to deserialize, from the JSON you have passed in.

By changing your PHP code, you will tell PHP to construct the JSON that Apigee Edge expects.

Hi Dino ,

Thanks for the response i tried the above code but still my request is not working following is my code



$data_string = json_encode($customdata); $headers = array('Content-Type: application/json'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_USERPWD, "$user:$passwd"); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

JSON Format:

{"name":"Test_Company6",
"displayName":"Test Company6",
"attributes":[{"ADMIN_EMAIL":"test@gmail.com"},
{"MINT_BILLING_TYPE":"POSTPAID"},
{"MINT_DEVELOPER_LEGAL_NAME":"ABC"},
{"MINT_TAX_EXEMPT_AUTH_NO":"54321678"},
{"MINT_DEVELOPER_PHONE":"0434243424794"},
{"MINT_DEVELOPER_ADDRESS":"ABC"}]}

i think now format is ok but my request not going to Edge and i am getting the error on devportal

{ "code" : "mint.unhandledException", "message" : "Unanticipated exception. Please contact your Support administrator with code : 98818e44-8f33-4d19-83df-ceb079419c33", "contexts" : [ ] }

The format is not correct. Your format is not what you need. you need this:

{
  "name": "Test_Company6",
  "displayName": "Test Company6",
  "attributes": [{
    "name" : "ADMIN_EMAIL", "value": "test@gmail.com"
  }, {
    "name" : "MINT_BILLING_TYPE", "value": "POSTPAID"
  }, {
    "name" : "MINT_DEVELOPER_LEGAL_NAME", "value" : "ABC"
  }, {
   ....
  }]
}

Fix your format.

This is what I told you originally. Seriously.

Fix it.

Hi Dino,

its working thank you .

i am also calling the Management API of create Company APP and follow the same rule as you already told me but my company app is not creating on Edge

http://apigee/v1/organizations/org_name/companies/Test_Company6/apps

this is the my output :

{"attributes":
[{
"name":"attribute_name1","value":"23415678"},
{"name":"attribute_name2","value":"2"}
],"apiProducts":["Production","Test Product"],"name":"Comapny_Test_App","callbackUrl":"www.google.com"}

and this is same as apigee referred.

apigee code :

{
  "attributes" : [ 
  {
   "name" : "{attribute_name1}",
   "value" : "{value1}"
  },
  {
   "name" : "{attribute_name2}",
   "value" : "{value2}"
  }
 ],
 "apiProducts": [ "{ApiProduct1}", "{ApiProduct2}", ... ],  
 "name" : "{App_name}",
 "callbackUrl" : "{url}"
}

and following is my code

$apiProductArray=array("Production","Test Product");




$customdata_data=array(
"attributes" => array(
         array("name"=>"attribute_name1","value"=>"23415678"),
         array("name"=>"attribute_name2" ,"value"=>"2")


    ),


"apiProducts" =>$apiProductArray,
"name" =>"Comapny_Test_App",
"callbackUrl"=>"www.google.com"


);

i am not getting where is the issue because i read all the code which i think as it is above reference .

ok, your original question has been answered. Is that right?

Please ask new questions with the "Ask a Quesiton" button.

4707-ask-a-question.png