german-bortoli / laravel-ckan-api

API Client for Ckan - Laravel 5
MIT License
6 stars 7 forks source link

404 error #1

Closed Naveedali1234 closed 6 years ago

Naveedali1234 commented 6 years ago

Hello everyone,

first of all thank you so much for this pretty easy package.

I am uploading csv file to ckan using this package but i am getting the below error:

Client error: POST http://my-domain/api/action/resource_create resulted in a 404 NOT FOUND response: {"help": "http://my-domain/api/3/action/help_show?name=resource_create", "success": false, "error": {"message": "Not (truncated...)

below is my code which i used to upload the csv file:

` $keyword = $request->input('keywords');

    $description = $request->input('description');

    $file = $request->file('file');

    $file->move('storage/uploads/',$file->getClientOriginalName());

    $data = [
    'upload' => fopen(storage_path('app/public/uploads/'.$file->getClientOriginalName()), 'r'),
    'package_id' => 'ckan-api-test-338',
    'name' => $keyword,
    'format' => 'CSV',
    'description' => $description,
    ];
    \CkanApi::resource()->create($data);`

my file is uploading to the server but when i am uploading it to ckan then i am getting the above error.

your help would really be appreciated.

thank you

german-bortoli commented 6 years ago

Hello, thank you so much for reporting this issue, please do me a favor and try with the configuration

CKAN_API_VERSION=2

If it does not work, report and going to check the issue.

Regards

Naveedali1234 commented 6 years ago

I have already used that and put that in .env file.

On Fri, Jul 27, 2018, 17:28 German Bortoli notifications@github.com wrote:

Hello, thank you so much for reporting this issue, please do me a favor and try with the configuration

CKAN_API_VERSION=2

If it does not work, report and going to check the issue.

Regards

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Germanaz0/laravel-ckan-api/issues/1#issuecomment-408404463, or mute the thread https://github.com/notifications/unsubscribe-auth/ARG8xXqID_hNpcpv4Irz0hCI6E9vlD2eks5uKwdmgaJpZM4VjYUg .

Naveedali1234 commented 6 years ago

if this is a package issue then i would really appreciate it if you can inform me about it. I am using this package specifically in my project and your cooperation would be really appreciated.

Regards

german-bortoli commented 6 years ago

@Naveedali1234 hello, let me confirm, going to work on that.

german-bortoli commented 6 years ago

Yes I have been tested it, it seems to work properly, the api version is the number 3, you can remove it from .env file.

What was happening, your ckan-api-test-123 does not exists, that's why it throws an 404 error, is not because the ckan api, is because the package id does not exists (ckan problem).

What I did was following your example:

    $data = [
       'upload' => fopen(storage_path('app/public/test.png'), 'r'),
       'package_id' => 'package-test',
       'name' => 'key 123',
       'format' => 'png',
       'description' => 'Lorem ipsum description',
    ];
    return CkanApi::resource()->create($data);

And you can see (before it get deleted from the ckan example)

https://demo.ckan.org/es/dataset/package-test

So you have to create your package and get the id before upload the content.

Naveedali1234 commented 6 years ago

so it means i should have create a package manually from the ckan dashboard and then i will upload a resource into that package, right?

german-bortoli commented 6 years ago

No, you can create the package trhough the API, the workflow should be this.

myPackage = create package .... resource = create my resource with myPackage.id

german-bortoli commented 6 years ago

Going to close this issue, I just tested this and this is the output https://demo.ckan.org/dataset/ckan-api-test-2

The code is described below:

<?php

use Illuminate\Http\Request;

use CkanApi;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::get("/", function(Request $request) {

  $packageId = "ckan-api-test-2";

  // First we need to create a package (dataset)
  $package =  CkanApi::dataset()->create([
    'name' => $packageId,
    'title' => $packageId,
    'private' => 'False',
  ]);

  // Then we can attach resources to it.
  $data = [
    'upload' => fopen(storage_path('app/public/test.png'), 'r'),
    'package_id' => $packageId,
    'name' => 'key 123',
    'format' => 'image/png',
    'description' => 'Lorem ipsum description',
  ];

  $resource = CkanApi::resource()->create($data);

  return ['package' => $package, 'resource' => $resource];
});