External Api call and request

  • Hello,
    We are about to start a new project and this project is about posting and getting from an external api and also posting from and external api to to this project. We have chosen wordpress as our CMS and as a developer im having a problem posting to an external api.
    Before venturing into this project i decide to test posting to an external api, i used code snippet wordpress plugin and php to program and post it but i received a 404 error that its not allowed.
    Then i went through the developers handbook and also tried it using the developers handbook and failed.

    What i need now is how to post, get, put and delete with an external api, where and how to insert the code.

    And also please check the code I’ve been trying out and inform me of my errors and correct it.

    <?php
    $url = ‘https://api.apyhub.com/data/convert/currency’;

    $header = array(
    ‘Content-Type’ => ‘application/json’,
    ‘apy-token’ => ‘APT03xPn2ZVq7rFriUtRoamaY917CPd60WtMW03’,
    );

    $body = array{
    ‘source’ => ‘eur’,
    ‘target’ => ‘inr’,
    };

    $args = array(
    ‘header’ => $header,
    ‘body’ => $body,
    );

    $response = wp_remote_post( $url, $args );

    echo ‘$response’;

    I did this in a code snippet save and copy the short code to a page expecting to see the result there, but saw nothing.

    Thank you.

    WP.com: Unknown
    Jetpack: Yes
    Correct account: Yes

    The blog I need help with is: (visible only to moderators and staff)

  • Hello there,

    Many thanks for reaching out.

    Are you able to confirm the URL of the website that you need assistance with please?

  • yes, I’ve tried it on postman and it worked and note, the apy tokken isn’t correct as i changed it before posting this question.

  • Hello there,

    Ok, so that looks like an API end point…

    Is the site you’re working on hubaya.com?

  • No, its a new project and we have the domain name and about to get the hosting. But i have been trying it out on a subdomain on hubaya.com

  • Ok, thanks for clarifying! The reason we asked about the domain was that these forums are oriented at helping with sites that are hosted here on WordPress.com; when the site uses the WordPress software from WordPress.org and is with a different host then we aren’t really able to offer the same help; as it is this details what help we can offer for plugins and custom code:
    https://wordpress.com/support/plugins/get-help-with-plugins-and-themes/

    If you did happen to be looking for the WordPress.org community forums, they’re at the link below:
    https://wordpress.org/support/forums/

    They may well be a better point of contact for this type of query!

  • I think maybe we should discuss it privately and if what we want is assured, we will host this project on wordpress.

  • Hey there,

    Sure thing, we’ll be reaching out via email shortly.

  • The topic ‘External Api call and request’ is closed to new replies.