Unable to PATCH custom field using GuzzleHttp


(Ankush Thakur) #1

I’m trying to write custom fields back to a contact using PHP’s GuzzleHttp library. Although I’m able to send GET requests, etc., I feel I’m doing something wrong with this patch request as it returns me a 400 error {"message":"Input could not be converted to a valid request"}.

I’ll be very happy if someone can look at this code and suggest what’s wrong. By the way, I was able to send this PATCH request using command-line curl, so I think it’s something related to the usage of GuzzleHttp here.

$url = 'https://api.infusionsoft.com/crm/rest/v1/contacts/' . $order->contact->id . '?access_token=' . $infs_token;

$response = $client->request('PATCH', $url, array(
    'json' => array(
        "custom_fields" => array(
            'content' => $infs_points,
            'id' => env('INFS_POINTS_FIELD_ID')
        )
    )
));

Thanks in advance!


(John Borelli) #2

Have you tried a forward slash before the question mark (at the end of the uri) line /?access_token=’ etc?


(Ankush Thakur) #3

I haven’t, but I think the problem might be that the expected input contains an array that contains an object that contains the data. What I have right now is maybe an array that contains the data. Do you think that might be causing the problem?


(Ankush Thakur) #4

Okay, I made some progress. I used the following code now:

$obj = new \StdClass();
$obj->content= $infs_points;
$obj->id = env('INFS_POINTS_FIELD_ID');

$response = $client->request('PATCH', $url, array(
    'json' => array(
        "custom_fields" => array(
            $obj
        )
    )
));

But this time, I got {"message":"BILLING Region is invalid, SHIPPING Region is invalid"}. Please help! :slight_smile: