Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json: cannot unmarshal object into Go value of type []json.RawMessage #1

Open
narkan opened this issue May 6, 2020 · 1 comment
Open

Comments

@narkan
Copy link

narkan commented May 6, 2020

I can't work out how to format the payload. I've tried this:

    include( plugin_dir_path( __FILE__ ) . 'StackPath.php' );
    $stackpath = new StackPath\StackPath( "my-default-stack-38343c", SP_CLIENT_IDZZ, SP_CLIENT_SECRETZZ );


    $response2 = $stackpath->post( "cdn/v1/stacks/my-default-stack-38343c/purge", [
        "json" => [ "items" => [
            "purgeAllDynamic" => true,
            "invalidateOnly" => false,
            "recursive"=>true,
            "url" =>"https://thecommunitychurch.online"
        ] ]
    ] );

But I get the response: "json: cannot unmarshal object into Go value of type []json.RawMessage"

If I remove the json outer wrapper:

    $response2 = $stackpath->post( "cdn/v1/stacks/my-default-stack-38343c/purge", [
        "items" => [
            "purgeAllDynamic" => true,
            "invalidateOnly" => false,
            "recursive"=>true,
            "url" =>"https://thecommunitychurch.online"
        ]
    ] );

the response is "Items must be provided"

If I send it without the "items" wrapper I get the same: "Items must be provided"

    $response2 = $stackpath->post( "cdn/v1/stacks/my-default-stack-38343c/purge", [
            "purgeAllDynamic" => true,
            "invalidateOnly" => false,
            "recursive"=>true,
            "url" =>"https://thecommunitychurch.online"
        
    ] );

Any help would be appreciated ;)

@Striker007
Copy link

items is an array of associative arrays (additional square brackets)

insted of
["json" => ["items" => ["url" => "..."]]];
we need
["json" => ["items" => [["url" => "..."]]]];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants