Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Problems pushing content to the API #57

Closed
benlk opened this issue Sep 25, 2018 · 8 comments
Closed

Problems pushing content to the API #57

benlk opened this issue Sep 25, 2018 · 8 comments
Labels
Milestone

Comments

@benlk
Copy link
Contributor

benlk commented Sep 25, 2018

Reported by @eteare:

I have been struggling to publish to the Story API from the plugin. I can get stories from the Story API no prob (one story, or an auto publish of a collection), but no PUT or POST from the site I am testing on. We are looking at Kibana to find these requests.

I’ve gone round a few times, checking all the configs and Ben, can you double check one thing for us? Can you check that for POST and PUT requests that the URL is /story and not /query? That’s the one guess we have right now on why, perhaps, no stories are getting to the API.

@benlk benlk added this to the 1.7.2 milestone Sep 25, 2018
@benlk benlk added the bug label Sep 25, 2018
@benlk
Copy link
Contributor Author

benlk commented Sep 25, 2018

When pushing content to the API, the URL is /story and it is making a POST request:

$url = add_query_arg( array(
'orgId' => $org_id,
'apiKey' => get_option( 'ds_npr_api_key' )
), get_option( 'ds_npr_api_push_url' ) . '/story' );
nprstory_error_log( 'Sending nprml = ' . $nprml );
$result = wp_remote_post( $url, array( 'body' => $nprml ) );

Erin says that NPR is taking another look to see if they can determine what the problem is.

This was referenced Sep 25, 2018
@benlk
Copy link
Contributor Author

benlk commented Sep 26, 2018

I'm not even seeing the "org ID not set" error that should be showing in my server log, because I'm attempting to push to the sandbox without an Org ID.

} else {
$error_text = 'OrgID was not set when tried to push post_ID ' . $post_ID . ' to the NPR Story API.';
error_log ( $error_text ); // debug use
}

@benlk
Copy link
Contributor Author

benlk commented Sep 26, 2018

It's because this URL parameter is no longer set:

if ( isset( $_POST['ds_npr_update_push'] ) ) {
// No need to validate the ds_npr_update_push contents; we're checking only for its existence
// permissions check is handled by nprstory_api_push
add_action( 'save_post', 'nprstory_api_push', 10, 2 );
}

That URL parameter was set before #47, and is not set afterwards. The pull request removed the submit_button( 'Push to NPR', 'large', 'ds_npr_update_push', false, $attrs ); button, which set that URL parameter, and replaced it with a checkbox that added a different parameter to the URL.

benlk added a commit that referenced this issue Sep 26, 2018
This fixes the issue described in #57, where the URL parameter ds_npr_update_push was removed along with the 'Push to NPR' submit button, but the URL parameter triggering the nprstory_api_push function was not changed.
@benlk
Copy link
Contributor Author

benlk commented Sep 26, 2018

With an org ID set:

Fatal error: Uncaught Error: Cannot use string offset as an array in /Users/blk/sites/nprapi/wp-content/plugins/nprapi-wordpress/push_story.php:463
Stack trace:
0 /Users/blk/sites/nprapi/wp-content/plugins/nprapi-wordpress/settings.php(238): nprstory_get_permission_groups()
1 /Users/blk/sites/nprapi/wp-admin/includes/template.php(1388): nprstory_push_story_permissions_callback(Array)
2 /Users/blk/sites/nprapi/wp-admin/includes/template.php(1347): do_settings_fields('ds_npr_api', 'ds_npr_api_sett...')
3 /Users/blk/sites/nprapi/wp-content/plugins/nprapi-wordpress/settings_ui.php(14): do_settings_sections('ds_npr_api')
4 /Users/blk/sites/nprapi/wp-includes/class-wp-hook.php(286): nprstory_api_options_page('')
5 /Users/blk/sites/nprapi/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array)
6 /Users/blk/sites/nprapi/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
7 /Users/blk/sites/nprapi/wp-admin/admin.php(224): do_action('settings_page_d...')
8 /Users/blk/sites/nprapi/wp-admin/options-general.php(10): require_once('/Users/blk/site...')
9 /Users/blk/.composer/vendor/laravel/valet/server.php(147): require('/Users/blk/site...')
10 {main}

thrown in /Users/blk/sites/nprapi/wp-content/plugins/nprapi-wordpress/push_story.php on line 463

@benlk
Copy link
Contributor Author

benlk commented Sep 26, 2018

That's fixed by 63c25f0

@eteare
Copy link
Contributor

eteare commented Sep 27, 2018

Ben, I pulled a repo with this branch and successfully posted to the API. Success!

@benlk
Copy link
Contributor Author

benlk commented Sep 27, 2018

👍

@benlk
Copy link
Contributor Author

benlk commented Sep 27, 2018

#60 has merged, so moving this to the "Done" category.

@benlk benlk closed this as completed Sep 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants