0

I am using the clinch-pad rest api to create the contact using this document Document rest api I i am trying bellow snippet code to create contact on clinchpad but its getting error We're sorry, but something went wrong.. so can any one tell me how do i go to achieve this.

$url = 'https://www.clinchpad.com/api/v1/contacts';  
 //$appId = 'YOUR_APP_ID';  
 $restKey = 'MY_API_KEY';  
 $headers = array(  
   "Content-Type: application/json",  
   //"X-Parse-Application-Id: " . $appId,  
 "X-Parse-REST-API-Key: " . $restKey  
 //"-u api-key:". $restKey  
 );  
 $objectData = '{
        "_id": "521f2wwww6eccce8b4310e000076",
        "name": "wwwwwwwwFoo Guy",
        "designation": null,
        "email": "[email protected]",
        "phone": "5553331234",
        "address": null,
        "fields":  [
            {
              "_id": "531ed3a49a21f6e90b00000e",
              "name": "custom contact field",
              "value": "Annual"
            }
        ],
        "organization": {
            "_id": "sdfsdf5455sdfdf545455",
            "name": "Foo Organization",
            "email": "[email protected]",
            "phone": "5553336666",
            "website": "http://www.foocorp.com",
            "address": "Foo City"
        }
    },
  ';  
 $rest = curl_init();  
 curl_setopt($rest,CURLOPT_URL,$url);  
 curl_setopt($rest,CURLOPT_POST,1);  
 curl_setopt($rest,CURLOPT_POSTFIELDS,$objectData);  
 curl_setopt($rest,CURLOPT_HTTPHEADER,$headers);  
 curl_setopt($rest,CURLOPT_SSL_VERIFYPEER, false);  
 curl_setopt($rest,CURLOPT_RETURNTRANSFER, true);  
 $response = curl_exec($rest);  
 echo $response;  
 print_r($response);  
 curl_close($rest);  

1 Answer 1

2

The data you're sending is not the valid JSON. The extra comma in the end is extra.

Is the $restKey in the example valid? I'm getting HTTP Basic: Access denied.

I guess you shouldn't put your private data (keys, codes, passwords) into the questions here.

Nevertheless I've made few changes and this should be working

$url = 'https://www.clinchpad.com/api/v1/contacts';  
 //$appId = 'YOUR_APP_ID';  
 $restKey = 'MY_API_KEY';  
 $headers = array(  
   "Content-Type: application/json",  
   // "X-Parse-Application-Id: " . $appId,  
//  "X-Parse-REST-API-Key: " . $restKey  
 //"-u api-key:". $restKey  
 );  
 $username = 'api-key';
 $password = $restKey;
 $objectData = '{
    "_id": "521f2wwww6eccce8b4310e000076",
    "name": "wwwwwwwwFoo Guy",
    "designation": null,
    "email": "[email protected]",
    "phone": "5553331234",
    "address": null,
    "fields":  [
        {
          "_id": "531ed3a49a21f6e90b00000e",
          "name": "custom contact field",
          "value": "Annual"
        }
    ],
    "organization": {
        "_id": "sdfsdf5455sdfdf545455",
        "name": "Foo Organization",
        "email": "[email protected]",
        "phone": "5553336666",
        "website": "http://www.foocorp.com",
        "address": "Foo City"
    }
    }';  
 $rest = curl_init();  
 curl_setopt($rest,CURLOPT_URL,$url);  
 curl_setopt($rest,CURLOPT_POST,1);  
 curl_setopt($rest,CURLOPT_POSTFIELDS,$objectData);  
 curl_setopt($rest,CURLOPT_HTTPHEADER,$headers);  
 curl_setopt($rest, CURLOPT_USERPWD, $username . ":" . $password);  
 curl_setopt($rest,CURLOPT_SSL_VERIFYPEER, false);  
 curl_setopt($rest,CURLOPT_RETURNTRANSFER, true);  
 $response = curl_exec($rest);  
 echo $response;  
 print_r($response);  
 curl_close($rest);  

Main changes besides removing the comma are:

$username = 'api-key';
$password = $apiKey;
curl_setopt($rest, CURLOPT_USERPWD, $username . ":" . $password); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.