1

I want to upload a file, I get the below error message

{"errors":["undefined method tempfile'for\"@/files/media/keywords.csv\":String"]}

Here is my code

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,
'https://app.simpli.fi/api/organizations/57979/campaigns/2156268/keywords');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
        
        $post = array(
            'keyword[csv]' => '@' .realpath('./files/media/keywords.csv'),
            'keyword[append]' => 'true'
        );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        
        $headers = array();
        $headers[] = 'X-App-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
        $headers[] = 'X-User-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        
        $result = curl_exec($ch);
        echo "<pre>";
        print_r($result);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close($ch);
        die;
Aryan
  • 3,338
  • 4
  • 18
  • 43
  • I'm unable to reproduce. When I run your code, all I get is an empty string as the result. – El_Vanja Nov 18 '20 at 10:49
  • To reproduce create a csv file with any word in first cell only for test. Give the path to file in the curl query. And to execute you would need App key and user key – Antony Shaji Nov 18 '20 at 11:56

0 Answers0