Hello DaniWeb Community,

I am a newbie in PHP, but I tried to create a plugin for my CRM platform using API to get informations, but I get some errors: Notice: Undefined index. Click here for an image with the errors..

Here are the lines where I got the errors:

` 
// API doRequest - Custom Attributes Information
    $customAttributes = UCRMAPIAccess::doRequest(sprintf('custom-attributes?attributeType=client')) ?: [];
    foreach($customAttributes as $customAttr) {
        $responseCA = UCRMAPIAccess::doRequest(sprintf('custom-attributes?attributeType=client'),
            'GET',
            [
                'id' => $cAttributeID,
                'key' => $cAttributeKey,
                'name' => $cAttributeName,
                'attributeType' => $cAttributeType,
                'value' => $cAttrValue,
            ]
        );

        if($responseCA !== null) {
            echo '<ul>';
                echo sprintf('<li>ID:</li> %d', $cAttributeID);
                echo sprintf('<li>key:</li> %s', $responseCA['key']); // line 117
                echo sprintf('<li>name:</li> %s', $responseCA['name']); // line 118
                echo sprintf('<li>value:</li> %s', $responseCA['value']); // line 119
            echo '</ul>';
        } else {
            echo 'There was an error retrieving custom attributes.' . PHP_EOL;
        }
     }
`

And here is where I use $_GET function:

`
// Custom Attributes Information
$cAttributeName = (isset($_GET['name']) ? $_GET['name'] : null);
$cAttributeID = (isset($_GET['id']) ? $_GET['id'] : null);
$cAttributeKey = (isset($_GET['key']) ? $_GET['key'] : null);
$cAttributeType = (isset($_GET['attributeType']) ? $_GET['attributeType'] : null);
`

What I am trying to do aswell, after I get the custom attributes, I want to get them for each client I have:

$cAttributes = (isset($_GET['attributes']) ? $_GET['attributes'] : [
    $cAttrName = (isset($_GET['name']) ? $_GET['name'] : null),
    $cAttrKey = (isset($_GET['key']) ? $_GET['key'] : null),
    $cAttrValue = (isset($_GET['value']) ? $_GET['value'] : null),
    $cAttrClientID = $clientId,
]);

This is the $_GET function for Client Custom Attributes

And this is the API doRequest function for clients, where I had added the attributes, but I don't know if I did it right.

// API doRequest - Client Information & Custom Attributes
    $response = UCRMAPIAccess::doRequest(sprintf('clients/%d', $clientId),
        'GET',
        [
            'fullAddress' => $cFAddress,
            'firstName' => $cFName,
            'lastName' => $cLName,
            'companyTaxId' => $cCompanyTaxID,
            'companyRegistrationNumber' => $cCompanyRegistrationNumber,
            'city' => $cCity,
            'street1' => $cStreet1,
            'street2' => $cStreet2,
            'organizationName' => $cOrganizationName,
            'invoiceStreet1' => $cInvoiceStreet1,
            'invoiceStreet2' => $cInvoiceStreet2,
            'invoiceCity' => $cInvoiceCity,
            'invoiceZipCode' => $cInvoiceZipCode,
            'attributes' => [
            'name' => $cAttrName,
            'value' => $cAttrValue,
            'key' => $cAttrKey,
            'id' => $cAttributeID,
        ],
    ]
);

Which lines in the code above correspond to lines 118-120 of public.php?

Also, I'm including the image here for reference.

6926d234978766542f544ed1e31e465c.png

You should use the same construct you are using in the other code blocks. isset($responseCA['key']) ? $responseCA['key'] : ''

Hey this is variable Undefined probalm

you first defined variable in global
tray this type :- first start php code then defined variable
<?php
$key = '';
$name = '';
$value = '';
?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.